diff options
author | Andrew Bartlett <abartlet@samba.org> | 2011-06-24 16:26:23 +1000 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2011-06-24 16:26:23 +1000 |
commit | 6da26870e0ae5acd6ff49a30ec2f6886b44d095e (patch) | |
tree | 850c71039563c16a5d563c47e7ba2ab645baf198 /source3/lib/netapi | |
parent | 6925a799d04c6fa59dd2ddef1f5510f9bb7d17d1 (diff) | |
parent | 2610c05b5b95cc7036b3d6dfb894c6cfbdb68483 (diff) | |
download | samba-6da26870e0ae5acd6ff49a30ec2f6886b44d095e.tar.gz samba-6da26870e0ae5acd6ff49a30ec2f6886b44d095e.tar.xz samba-6da26870e0ae5acd6ff49a30ec2f6886b44d095e.zip |
Merge 2610c05b5b95cc7036b3d6dfb894c6cfbdb68483 as Samba-4.0alpha16
Diffstat (limited to 'source3/lib/netapi')
-rw-r--r-- | source3/lib/netapi/cm.c | 5 | ||||
-rw-r--r-- | source3/lib/netapi/group.c | 8 | ||||
-rw-r--r-- | source3/lib/netapi/libnetapi.h | 19 | ||||
-rw-r--r-- | source3/lib/netapi/localgroup.c | 6 | ||||
-rw-r--r-- | source3/lib/netapi/netapi.c | 51 | ||||
-rw-r--r-- | source3/lib/netapi/netapi.h | 9 | ||||
-rw-r--r-- | source3/lib/netapi/netapi_private.h | 2 | ||||
-rw-r--r-- | source3/lib/netapi/samr.c | 2 | ||||
-rw-r--r-- | source3/lib/netapi/serverinfo.c | 26 | ||||
-rw-r--r-- | source3/lib/netapi/share.c | 4 | ||||
-rw-r--r-- | source3/lib/netapi/user.c | 14 |
11 files changed, 100 insertions, 46 deletions
diff --git a/source3/lib/netapi/cm.c b/source3/lib/netapi/cm.c index 290194ba2d..47ccf8bb7a 100644 --- a/source3/lib/netapi/cm.c +++ b/source3/lib/netapi/cm.c @@ -22,6 +22,7 @@ #include "lib/netapi/netapi.h" #include "lib/netapi/netapi_private.h" +#include "libsmb/libsmb.h" #include "rpc_client/cli_pipe.h" /******************************************************************** @@ -121,7 +122,7 @@ static WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx, return WERR_CAN_NOT_COMPLETE; } - p = TALLOC_ZERO_P(ctx, struct client_ipc_connection); + p = talloc_zero(ctx, struct client_ipc_connection); if (p == NULL) { return WERR_NOMEM; } @@ -187,7 +188,7 @@ static NTSTATUS pipe_cm_connect(TALLOC_CTX *mem_ctx, struct client_pipe_connection *p; NTSTATUS status; - p = TALLOC_ZERO_ARRAY(mem_ctx, struct client_pipe_connection, 1); + p = talloc_zero_array(mem_ctx, struct client_pipe_connection, 1); if (!p) { return NT_STATUS_NO_MEMORY; } diff --git a/source3/lib/netapi/group.c b/source3/lib/netapi/group.c index 4295d9f7bb..710ec3790f 100644 --- a/source3/lib/netapi/group.c +++ b/source3/lib/netapi/group.c @@ -1157,7 +1157,7 @@ static WERROR convert_samr_disp_groups_to_GROUP_INFO_0_buffer(TALLOC_CTX *mem_ct struct GROUP_INFO_0 *g0; int i; - g0 = TALLOC_ZERO_ARRAY(mem_ctx, struct GROUP_INFO_0, groups->count); + g0 = talloc_zero_array(mem_ctx, struct GROUP_INFO_0, groups->count); W_ERROR_HAVE_NO_MEMORY(g0); for (i=0; i<groups->count; i++) { @@ -1183,7 +1183,7 @@ static WERROR convert_samr_disp_groups_to_GROUP_INFO_1_buffer(TALLOC_CTX *mem_ct struct GROUP_INFO_1 *g1; int i; - g1 = TALLOC_ZERO_ARRAY(mem_ctx, struct GROUP_INFO_1, groups->count); + g1 = talloc_zero_array(mem_ctx, struct GROUP_INFO_1, groups->count); W_ERROR_HAVE_NO_MEMORY(g1); for (i=0; i<groups->count; i++) { @@ -1211,7 +1211,7 @@ static WERROR convert_samr_disp_groups_to_GROUP_INFO_2_buffer(TALLOC_CTX *mem_ct struct GROUP_INFO_2 *g2; int i; - g2 = TALLOC_ZERO_ARRAY(mem_ctx, struct GROUP_INFO_2, groups->count); + g2 = talloc_zero_array(mem_ctx, struct GROUP_INFO_2, groups->count); W_ERROR_HAVE_NO_MEMORY(g2); for (i=0; i<groups->count; i++) { @@ -1242,7 +1242,7 @@ static WERROR convert_samr_disp_groups_to_GROUP_INFO_3_buffer(TALLOC_CTX *mem_ct struct GROUP_INFO_3 *g3; int i; - g3 = TALLOC_ZERO_ARRAY(mem_ctx, struct GROUP_INFO_3, groups->count); + g3 = talloc_zero_array(mem_ctx, struct GROUP_INFO_3, groups->count); W_ERROR_HAVE_NO_MEMORY(g3); for (i=0; i<groups->count; i++) { diff --git a/source3/lib/netapi/libnetapi.h b/source3/lib/netapi/libnetapi.h index 2711558dbc..e832deaccc 100644 --- a/source3/lib/netapi/libnetapi.h +++ b/source3/lib/netapi/libnetapi.h @@ -1,3 +1,22 @@ +/* + * Unix SMB/CIFS implementation. + * NetApi Support + * Copyright (C) Guenther Deschner 2007-2008 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + */ + #ifndef __LIBNETAPI_LIBNETAPI__ #define __LIBNETAPI_LIBNETAPI__ NET_API_STATUS NetJoinDomain(const char * server /* [in] [unique] */, diff --git a/source3/lib/netapi/localgroup.c b/source3/lib/netapi/localgroup.c index 51f4e1d745..816afc230f 100644 --- a/source3/lib/netapi/localgroup.c +++ b/source3/lib/netapi/localgroup.c @@ -610,7 +610,7 @@ static WERROR map_buffer_to_alias_info(TALLOC_CTX *mem_ctx, struct LOCALGROUP_INFO_1002 *info1002; union samr_AliasInfo *info = NULL; - info = TALLOC_ZERO_P(mem_ctx, union samr_AliasInfo); + info = talloc_zero(mem_ctx, union samr_AliasInfo); W_ERROR_HAVE_NO_MEMORY(info); switch (level) { @@ -1115,7 +1115,7 @@ static WERROR NetLocalGroupModifyMembers_r(struct libnetapi_ctx *ctx, ZERO_STRUCT(domain_handle); ZERO_STRUCT(alias_handle); - member_sids = TALLOC_ZERO_ARRAY(ctx, struct dom_sid, + member_sids = talloc_zero_array(ctx, struct dom_sid, r->in.total_entries); W_ERROR_HAVE_NO_MEMORY(member_sids); @@ -1344,7 +1344,7 @@ static WERROR NetLocalGroupModifyMembers_r(struct libnetapi_ctx *ctx, werr = WERR_OK; done: - if (is_valid_policy_hnd(&alias_handle)) { + if (b && is_valid_policy_hnd(&alias_handle)) { dcerpc_samr_Close(b, talloc_tos(), &alias_handle, &result); } diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index cd590273ce..14259864ae 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -24,7 +24,6 @@ #include "krb5_env.h" struct libnetapi_ctx *stat_ctx = NULL; -TALLOC_CTX *frame = NULL; static bool libnetapi_initialized = false; /**************************************************************** @@ -38,7 +37,7 @@ static NET_API_STATUS libnetapi_init_private_context(struct libnetapi_ctx *ctx) return W_ERROR_V(WERR_INVALID_PARAM); } - priv = TALLOC_ZERO_P(ctx, struct libnetapi_private_ctx); + priv = talloc_zero(ctx, struct libnetapi_private_ctx); if (!priv) { return W_ERROR_V(WERR_NOMEM); } @@ -57,6 +56,8 @@ were not expecting it. NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context) { + NET_API_STATUS ret; + TALLOC_CTX *frame; if (stat_ctx && libnetapi_initialized) { *context = stat_ctx; return NET_API_STATUS_SUCCESS; @@ -76,7 +77,7 @@ NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context) lp_set_cmdline("log level", "0"); setup_logging("libnetapi", DEBUG_STDERR); - if (!lp_load(get_dyn_CONFIGFILE(), true, false, false, false)) { + if (!lp_load(get_dyn_CONFIGFILE(), true, false, false, true)) { TALLOC_FREE(frame); fprintf(stderr, "error loading %s\n", get_dyn_CONFIGFILE() ); return W_ERROR_V(WERR_GENERAL_FAILURE); @@ -88,7 +89,9 @@ NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context) BlockSignals(True, SIGPIPE); - return libnetapi_net_init(context); + ret = libnetapi_net_init(context); + TALLOC_FREE(frame); + return ret; } /**************************************************************** @@ -105,7 +108,7 @@ NET_API_STATUS libnetapi_net_init(struct libnetapi_ctx **context) struct libnetapi_ctx *ctx = NULL; char *krb5_cc_env = NULL; - frame = talloc_stackframe(); + TALLOC_CTX *frame = talloc_stackframe(); ctx = talloc_zero(frame, struct libnetapi_ctx); if (!ctx) { @@ -117,14 +120,14 @@ NET_API_STATUS libnetapi_net_init(struct libnetapi_ctx **context) krb5_cc_env = getenv(KRB5_ENV_CCNAME); if (!krb5_cc_env || (strlen(krb5_cc_env) == 0)) { - ctx->krb5_cc_env = talloc_strdup(frame, "MEMORY:libnetapi"); + ctx->krb5_cc_env = talloc_strdup(ctx, "MEMORY:libnetapi"); setenv(KRB5_ENV_CCNAME, ctx->krb5_cc_env, 1); } if (getenv("USER")) { - ctx->username = talloc_strdup(frame, getenv("USER")); + ctx->username = talloc_strdup(ctx, getenv("USER")); } else { - ctx->username = talloc_strdup(frame, ""); + ctx->username = talloc_strdup(ctx, ""); } if (!ctx->username) { TALLOC_FREE(frame); @@ -140,8 +143,10 @@ NET_API_STATUS libnetapi_net_init(struct libnetapi_ctx **context) libnetapi_initialized = true; + talloc_steal(NULL, ctx); *context = stat_ctx = ctx; - + + TALLOC_FREE(frame); return NET_API_STATUS_SUCCESS; } @@ -187,8 +192,10 @@ NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx) secrets_shutdown(); + if (ctx == stat_ctx) { + stat_ctx = NULL; + } TALLOC_FREE(ctx); - TALLOC_FREE(frame); gfree_debugsyms(); @@ -202,10 +209,14 @@ NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx) NET_API_STATUS libnetapi_set_debuglevel(struct libnetapi_ctx *ctx, const char *debuglevel) { + TALLOC_CTX *frame = talloc_stackframe(); ctx->debuglevel = talloc_strdup(ctx, debuglevel); + if (!lp_set_cmdline("log level", debuglevel)) { + TALLOC_FREE(frame); return W_ERROR_V(WERR_GENERAL_FAILURE); } + TALLOC_FREE(frame); return NET_API_STATUS_SUCCESS; } @@ -272,15 +283,22 @@ NET_API_STATUS libnetapi_set_use_ccache(struct libnetapi_ctx *ctx) } /**************************************************************** +Return a libnetapi error as a string, caller must free with NetApiBufferFree ****************************************************************/ -const char *libnetapi_errstr(NET_API_STATUS status) +char *libnetapi_errstr(NET_API_STATUS status) { + TALLOC_CTX *frame = talloc_stackframe(); + char *ret; if (status & 0xc0000000) { - return get_friendly_nt_error_msg(NT_STATUS(status)); + ret = talloc_strdup(NULL, + get_friendly_nt_error_msg(NT_STATUS(status))); + } else { + ret = talloc_strdup(NULL, + get_friendly_werror_msg(W_ERROR(status))); } - - return get_friendly_werror_msg(W_ERROR(status)); + TALLOC_FREE(frame); + return ret; } /**************************************************************** @@ -304,9 +322,10 @@ NET_API_STATUS libnetapi_set_error_string(struct libnetapi_ctx *ctx, } /**************************************************************** +Return a libnetapi_errstr(), caller must free with NetApiBufferFree ****************************************************************/ -const char *libnetapi_get_error_string(struct libnetapi_ctx *ctx, +char *libnetapi_get_error_string(struct libnetapi_ctx *ctx, NET_API_STATUS status_in) { NET_API_STATUS status; @@ -320,7 +339,7 @@ const char *libnetapi_get_error_string(struct libnetapi_ctx *ctx, } if (tmp_ctx->error_string) { - return tmp_ctx->error_string; + return talloc_strdup(NULL, tmp_ctx->error_string); } return libnetapi_errstr(status_in); diff --git a/source3/lib/netapi/netapi.h b/source3/lib/netapi/netapi.h index 9e1549df0e..620d8cf591 100644 --- a/source3/lib/netapi/netapi.h +++ b/source3/lib/netapi/netapi.h @@ -1411,15 +1411,18 @@ NET_API_STATUS libnetapi_set_use_kerberos(struct libnetapi_ctx *ctx); NET_API_STATUS libnetapi_set_use_ccache(struct libnetapi_ctx *ctx); /**************************************************************** +Return a specific libnetapi error as a string, caller must free with NetApiBufferFree ****************************************************************/ -const char *libnetapi_errstr(NET_API_STATUS status); +char *libnetapi_errstr(NET_API_STATUS status); /**************************************************************** +Return the last libnetapi error as a string, caller must free with NetApiBufferFree +ctx is optional ****************************************************************/ -const char *libnetapi_get_error_string(struct libnetapi_ctx *ctx, - NET_API_STATUS status); +char *libnetapi_get_error_string(struct libnetapi_ctx *ctx, + NET_API_STATUS status); /**************************************************************** NetApiBufferAllocate diff --git a/source3/lib/netapi/netapi_private.h b/source3/lib/netapi/netapi_private.h index 7559c61564..349287b9e9 100644 --- a/source3/lib/netapi/netapi_private.h +++ b/source3/lib/netapi/netapi_private.h @@ -29,6 +29,8 @@ } \ return fn ## _r(ctx, r); +struct dcerpc_binding_handle; + struct libnetapi_private_ctx { struct { const char *domain_name; diff --git a/source3/lib/netapi/samr.c b/source3/lib/netapi/samr.c index 544698004a..1c3a94ee9c 100644 --- a/source3/lib/netapi/samr.c +++ b/source3/lib/netapi/samr.c @@ -240,7 +240,7 @@ WERROR libnetapi_samr_open_builtin_domain(struct libnetapi_ctx *mem_ctx, status = dcerpc_samr_OpenDomain(b, mem_ctx, connect_handle, builtin_mask, - CONST_DISCARD(struct dom_sid *, &global_sid_Builtin), + discard_const_p(struct dom_sid, &global_sid_Builtin), builtin_handle, &result); if (!NT_STATUS_IS_OK(status)) { diff --git a/source3/lib/netapi/serverinfo.c b/source3/lib/netapi/serverinfo.c index 22c7df69d1..4b11339f94 100644 --- a/source3/lib/netapi/serverinfo.c +++ b/source3/lib/netapi/serverinfo.c @@ -36,9 +36,9 @@ static WERROR NetServerGetInfo_l_101(struct libnetapi_ctx *ctx, struct SERVER_INFO_101 i; i.sv101_platform_id = PLATFORM_ID_NT; - i.sv101_name = global_myname(); - i.sv101_version_major = lp_major_announce_version(); - i.sv101_version_minor = lp_minor_announce_version(); + i.sv101_name = lp_netbios_name(); + i.sv101_version_major = SAMBA_MAJOR_NBT_ANNOUNCE_VERSION; + i.sv101_version_minor = SAMBA_MINOR_NBT_ANNOUNCE_VERSION; i.sv101_type = lp_default_server_announce(); i.sv101_comment = lp_serverstring(); @@ -540,7 +540,8 @@ WERROR NetServerGetInfo_r(struct libnetapi_ctx *ctx, static WERROR NetServerSetInfo_l_1005(struct libnetapi_ctx *ctx, struct NetServerSetInfo *r) { - WERROR werr; + WERROR werr = WERR_OK; + sbcErr err; struct smbconf_ctx *conf_ctx; struct srvsvc_NetSrvInfo1005 *info1005; @@ -563,13 +564,24 @@ static WERROR NetServerSetInfo_l_1005(struct libnetapi_ctx *ctx, return WERR_NOT_SUPPORTED; } - werr = smbconf_init_reg(ctx, &conf_ctx, NULL); - if (!W_ERROR_IS_OK(werr)) { + err = smbconf_init_reg(ctx, &conf_ctx, NULL); + if (!SBC_ERROR_IS_OK(err)) { + libnetapi_set_error_string(ctx, + "Could not initialize backend: %s", + sbcErrorString(err)); + werr = WERR_NO_SUCH_SERVICE; goto done; } - werr = smbconf_set_global_parameter(conf_ctx, "server string", + err = smbconf_set_global_parameter(conf_ctx, "server string", info1005->comment); + if (!SBC_ERROR_IS_OK(err)) { + libnetapi_set_error_string(ctx, + "Could not set global parameter: %s", + sbcErrorString(err)); + werr = WERR_NO_SUCH_SERVICE; + goto done; + } done: smbconf_shutdown(conf_ctx); diff --git a/source3/lib/netapi/share.c b/source3/lib/netapi/share.c index c4ed1549ce..d12fa1cf0c 100644 --- a/source3/lib/netapi/share.c +++ b/source3/lib/netapi/share.c @@ -141,7 +141,7 @@ static NTSTATUS map_SHARE_INFO_buffer_to_srvsvc_share_info(TALLOC_CTX *mem_ctx, case 2: i2 = (struct SHARE_INFO_2 *)buffer; - s2 = TALLOC_P(mem_ctx, struct srvsvc_NetShareInfo2); + s2 = talloc(mem_ctx, struct srvsvc_NetShareInfo2); NT_STATUS_HAVE_NO_MEMORY(s2); s2->name = i2->shi2_netname; @@ -159,7 +159,7 @@ static NTSTATUS map_SHARE_INFO_buffer_to_srvsvc_share_info(TALLOC_CTX *mem_ctx, case 1004: i1004 = (struct SHARE_INFO_1004 *)buffer; - s1004 = TALLOC_P(mem_ctx, struct srvsvc_NetShareInfo1004); + s1004 = talloc(mem_ctx, struct srvsvc_NetShareInfo1004); NT_STATUS_HAVE_NO_MEMORY(s1004); s1004->comment = i1004->shi1004_remark; diff --git a/source3/lib/netapi/user.c b/source3/lib/netapi/user.c index 63be7ac751..3003a39397 100644 --- a/source3/lib/netapi/user.c +++ b/source3/lib/netapi/user.c @@ -322,7 +322,7 @@ static NTSTATUS set_user_info_USER_INFO_X(TALLOC_CTX *ctx, 25, &user_info, &result); - if (NT_STATUS_EQUAL(status, NT_STATUS(DCERPC_FAULT_INVALID_TAG))) { + if (NT_STATUS_EQUAL(status, NT_STATUS_RPC_ENUM_VALUE_OUT_OF_RANGE)) { user_info.info23.info = info21; @@ -575,7 +575,7 @@ WERROR NetUserDel_r(struct libnetapi_ctx *ctx, status = dcerpc_samr_OpenDomain(b, talloc_tos(), &connect_handle, SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT, - CONST_DISCARD(struct dom_sid *, &global_sid_Builtin), + discard_const_p(struct dom_sid, &global_sid_Builtin), &builtin_handle, &result); if (!NT_STATUS_IS_OK(status)) { @@ -1436,7 +1436,7 @@ static WERROR convert_samr_dispinfo_to_NET_DISPLAY_USER(TALLOC_CTX *mem_ctx, struct NET_DISPLAY_USER *user = NULL; int i; - user = TALLOC_ZERO_ARRAY(mem_ctx, + user = talloc_zero_array(mem_ctx, struct NET_DISPLAY_USER, info->count); W_ERROR_HAVE_NO_MEMORY(user); @@ -1480,7 +1480,7 @@ static WERROR convert_samr_dispinfo_to_NET_DISPLAY_MACHINE(TALLOC_CTX *mem_ctx, struct NET_DISPLAY_MACHINE *machine = NULL; int i; - machine = TALLOC_ZERO_ARRAY(mem_ctx, + machine = talloc_zero_array(mem_ctx, struct NET_DISPLAY_MACHINE, info->count); W_ERROR_HAVE_NO_MEMORY(machine); @@ -1522,7 +1522,7 @@ static WERROR convert_samr_dispinfo_to_NET_DISPLAY_GROUP(TALLOC_CTX *mem_ctx, struct NET_DISPLAY_GROUP *group = NULL; int i; - group = TALLOC_ZERO_ARRAY(mem_ctx, + group = talloc_zero_array(mem_ctx, struct NET_DISPLAY_GROUP, info->count); W_ERROR_HAVE_NO_MEMORY(group); @@ -3137,7 +3137,6 @@ WERROR NetUserSetGroups_r(struct libnetapi_ctx *ctx, size_t num_del_rids = 0; uint32_t *member_rids = NULL; - size_t num_member_rids = 0; struct GROUP_USERS_INFO_0 *i0 = NULL; struct GROUP_USERS_INFO_1 *i1 = NULL; @@ -3263,7 +3262,6 @@ WERROR NetUserSetGroups_r(struct libnetapi_ctx *ctx, } member_rids = group_rids.ids; - num_member_rids = group_rids.count; status = dcerpc_samr_GetGroupsForUser(b, talloc_tos(), &user_handle, @@ -3574,7 +3572,7 @@ WERROR NetUserGetLocalGroups_r(struct libnetapi_ctx *ctx, } sid_array.num_sids = rid_array->count + 1; - sid_array.sids = TALLOC_ARRAY(ctx, struct lsa_SidPtr, sid_array.num_sids); + sid_array.sids = talloc_array(ctx, struct lsa_SidPtr, sid_array.num_sids); if (!sid_array.sids) { werr = WERR_NOMEM; goto done; |