diff options
Diffstat (limited to 'source3/libnet')
-rw-r--r-- | source3/libnet/libnet_dssync.c | 8 | ||||
-rw-r--r-- | source3/libnet/libnet_dssync_keytab.c | 6 | ||||
-rw-r--r-- | source3/libnet/libnet_dssync_passdb.c | 16 | ||||
-rw-r--r-- | source3/libnet/libnet_join.c | 90 | ||||
-rw-r--r-- | source3/libnet/libnet_join.h | 25 | ||||
-rw-r--r-- | source3/libnet/libnet_keytab.c | 2 | ||||
-rw-r--r-- | source3/libnet/libnet_samsync.c | 7 | ||||
-rw-r--r-- | source3/libnet/libnet_samsync_ldif.c | 37 | ||||
-rw-r--r-- | source3/libnet/libnet_samsync_passdb.c | 12 |
9 files changed, 142 insertions, 61 deletions
diff --git a/source3/libnet/libnet_dssync.c b/source3/libnet/libnet_dssync.c index 47ceff1509..c768226e8b 100644 --- a/source3/libnet/libnet_dssync.c +++ b/source3/libnet/libnet_dssync.c @@ -54,7 +54,7 @@ NTSTATUS libnet_dssync_init_context(TALLOC_CTX *mem_ctx, { struct dssync_context *ctx; - ctx = TALLOC_ZERO_P(mem_ctx, struct dssync_context); + ctx = talloc_zero(mem_ctx, struct dssync_context); NT_STATUS_HAVE_NO_MEMORY(ctx); talloc_set_destructor(ctx, libnet_dssync_free_context); @@ -339,7 +339,7 @@ static NTSTATUS libnet_dssync_build_request(TALLOC_CTX *mem_ctx, level = 5; } - nc = TALLOC_ZERO_P(mem_ctx, struct drsuapi_DsReplicaObjectIdentifier); + nc = talloc_zero(mem_ctx, struct drsuapi_DsReplicaObjectIdentifier); if (!nc) { status = NT_STATUS_NO_MEMORY; goto fail; @@ -351,7 +351,7 @@ static NTSTATUS libnet_dssync_build_request(TALLOC_CTX *mem_ctx, if (!ctx->single_object_replication && !ctx->force_full_replication && utdv) { - cursors = TALLOC_ZERO_P(mem_ctx, + cursors = talloc_zero(mem_ctx, struct drsuapi_DsReplicaCursorCtrEx); if (!cursors) { status = NT_STATUS_NO_MEMORY; @@ -442,7 +442,7 @@ static NTSTATUS libnet_dssync_getncchanges(TALLOC_CTX *mem_ctx, struct dcerpc_binding_handle *b = ctx->cli->binding_handle; if (!ctx->single_object_replication) { - new_utdv = TALLOC_ZERO_P(mem_ctx, struct replUpToDateVectorBlob); + new_utdv = talloc_zero(mem_ctx, struct replUpToDateVectorBlob); if (!new_utdv) { status = NT_STATUS_NO_MEMORY; goto out; diff --git a/source3/libnet/libnet_dssync_keytab.c b/source3/libnet/libnet_dssync_keytab.c index 65085cd96e..763f8baf4d 100644 --- a/source3/libnet/libnet_dssync_keytab.c +++ b/source3/libnet/libnet_dssync_keytab.c @@ -200,7 +200,7 @@ static NTSTATUS parse_supplemental_credentials(TALLOC_CTX *mem_ctx, goto done; } - pkb = TALLOC_ZERO_P(mem_ctx, struct package_PrimaryKerberosBlob); + pkb = talloc_zero(mem_ctx, struct package_PrimaryKerberosBlob); if (!pkb) { status = NT_STATUS_NO_MEMORY; goto done; @@ -276,7 +276,7 @@ static NTSTATUS parse_object(TALLOC_CTX *mem_ctx, if (attr->attid == DRSUAPI_ATTID_servicePrincipalName) { uint32_t count; num_spns = attr->value_ctr.num_values; - spn = TALLOC_ARRAY(mem_ctx, char *, num_spns); + spn = talloc_array(mem_ctx, char *, num_spns); for (count = 0; count < num_spns; count++) { blob = attr->value_ctr.values[count].blob; pull_string_talloc(spn, NULL, 0, @@ -387,7 +387,7 @@ static NTSTATUS parse_object(TALLOC_CTX *mem_ctx, entry = libnet_keytab_search(ctx, principal, 0, ENCTYPE_NULL, mem_ctx); if (entry) { - name = (char *)TALLOC_MEMDUP(mem_ctx, + name = (char *)talloc_memdup(mem_ctx, entry->password.data, entry->password.length); if (!name) { diff --git a/source3/libnet/libnet_dssync_passdb.c b/source3/libnet/libnet_dssync_passdb.c index ab347567f1..b8675d3d98 100644 --- a/source3/libnet/libnet_dssync_passdb.c +++ b/source3/libnet/libnet_dssync_passdb.c @@ -20,10 +20,10 @@ #include "includes.h" #include "system/passwd.h" #include "libnet/libnet_dssync.h" -#include "libnet/libnet_samsync.h" #include "../libcli/security/security.h" #include "../libds/common/flags.h" #include "../librpc/gen_ndr/ndr_drsuapi.h" +#include "util_tdb.h" #include "dbwrap.h" #include "../libds/common/flag_mapping.h" #include "passdb.h" @@ -106,7 +106,7 @@ static struct dssync_passdb_obj *dssync_search_obj_by_guid(struct dssync_passdb TDB_DATA key; TDB_DATA data; - key = make_tdb_data((const uint8_t *)(void *)guid, + key = make_tdb_data((const uint8_t *)(const void *)guid, sizeof(*guid)); ret = db->fetch(db, talloc_tos(), key, &data); @@ -1531,11 +1531,11 @@ static NTSTATUS handle_alias_object(struct dssync_passdb *pctx, map.sid_name_use = SID_NAME_ALIAS; } - fstrcpy(map.nt_name, name); + strlcpy(map.nt_name, name, sizeof(map.nt_name)); if (description) { - fstrcpy(map.comment, comment); + strlcpy(map.comment, comment, sizeof(map.comment)); } else { - fstrcpy(map.comment, ""); + strlcpy(map.comment, "", sizeof(map.comment)); } if (insert) @@ -1636,11 +1636,11 @@ static NTSTATUS handle_group_object(struct dssync_passdb *pctx, map.gid = grp->gr_gid; map.sid = group_sid; map.sid_name_use = SID_NAME_DOM_GRP; - fstrcpy(map.nt_name, name); + strlcpy(map.nt_name, name, sizeof(map.nt_name)); if (description) { - fstrcpy(map.comment, comment); + strlcpy(map.comment, comment, sizeof(map.comment)); } else { - fstrcpy(map.comment, ""); + strlcpy(map.comment, "", sizeof(map.comment)); } if (insert) diff --git a/source3/libnet/libnet_join.c b/source3/libnet/libnet_join.c index 1e866c3dd1..16c068c66e 100644 --- a/source3/libnet/libnet_join.c +++ b/source3/libnet/libnet_join.c @@ -38,6 +38,7 @@ #include "krb5_env.h" #include "../libcli/security/security.h" #include "passdb.h" +#include "libsmb/libsmb.h" /**************************************************************** ****************************************************************/ @@ -1074,7 +1075,7 @@ static NTSTATUS libnet_join_joindomain_rpc(TALLOC_CTX *mem_ctx, &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)) { /* retry with level 24 */ @@ -1291,7 +1292,7 @@ static NTSTATUS libnet_join_unjoindomain_rpc(TALLOC_CTX *mem_ctx, struct samr_Ids user_rids; struct samr_Ids name_types; union samr_UserInfo *info = NULL; - struct dcerpc_binding_handle *b; + struct dcerpc_binding_handle *b = NULL; ZERO_STRUCT(sam_pol); ZERO_STRUCT(domain_pol); @@ -1432,7 +1433,7 @@ static NTSTATUS libnet_join_unjoindomain_rpc(TALLOC_CTX *mem_ctx, dcerpc_samr_Close(b, mem_ctx, &user_pol, &result); done: - if (pipe_hnd) { + if (pipe_hnd && b) { if (is_valid_policy_hnd(&domain_pol)) { dcerpc_samr_Close(b, mem_ctx, &domain_pol, &result); } @@ -1454,40 +1455,61 @@ done: static WERROR do_join_modify_vals_config(struct libnet_JoinCtx *r) { - WERROR werr; + WERROR werr = WERR_OK; + sbcErr err; struct smbconf_ctx *ctx; - werr = smbconf_init_reg(r, &ctx, NULL); - if (!W_ERROR_IS_OK(werr)) { + err = smbconf_init_reg(r, &ctx, NULL); + if (!SBC_ERROR_IS_OK(err)) { + werr = WERR_NO_SUCH_SERVICE; goto done; } if (!(r->in.join_flags & WKSSVC_JOIN_FLAGS_JOIN_TYPE)) { - werr = smbconf_set_global_parameter(ctx, "security", "user"); - W_ERROR_NOT_OK_GOTO_DONE(werr); + err = smbconf_set_global_parameter(ctx, "security", "user"); + if (!SBC_ERROR_IS_OK(err)) { + werr = WERR_NO_SUCH_SERVICE; + goto done; + } - werr = smbconf_set_global_parameter(ctx, "workgroup", - r->in.domain_name); + err = smbconf_set_global_parameter(ctx, "workgroup", + r->in.domain_name); + if (!SBC_ERROR_IS_OK(err)) { + werr = WERR_NO_SUCH_SERVICE; + goto done; + } smbconf_delete_global_parameter(ctx, "realm"); goto done; } - werr = smbconf_set_global_parameter(ctx, "security", "domain"); - W_ERROR_NOT_OK_GOTO_DONE(werr); + err = smbconf_set_global_parameter(ctx, "security", "domain"); + if (!SBC_ERROR_IS_OK(err)) { + werr = WERR_NO_SUCH_SERVICE; + goto done; + } - werr = smbconf_set_global_parameter(ctx, "workgroup", - r->out.netbios_domain_name); - W_ERROR_NOT_OK_GOTO_DONE(werr); + err = smbconf_set_global_parameter(ctx, "workgroup", + r->out.netbios_domain_name); + if (!SBC_ERROR_IS_OK(err)) { + werr = WERR_NO_SUCH_SERVICE; + goto done; + } if (r->out.domain_is_ad) { - werr = smbconf_set_global_parameter(ctx, "security", "ads"); - W_ERROR_NOT_OK_GOTO_DONE(werr); + err = smbconf_set_global_parameter(ctx, "security", "ads"); + if (!SBC_ERROR_IS_OK(err)) { + werr = WERR_NO_SUCH_SERVICE; + goto done; + } - werr = smbconf_set_global_parameter(ctx, "realm", - r->out.dns_domain_name); - W_ERROR_NOT_OK_GOTO_DONE(werr); + err = smbconf_set_global_parameter(ctx, "realm", + r->out.dns_domain_name); + if (!SBC_ERROR_IS_OK(err)) { + werr = WERR_NO_SUCH_SERVICE; + goto done; + } } done: @@ -1501,20 +1523,28 @@ static WERROR do_join_modify_vals_config(struct libnet_JoinCtx *r) static WERROR do_unjoin_modify_vals_config(struct libnet_UnjoinCtx *r) { WERROR werr = WERR_OK; + sbcErr err; struct smbconf_ctx *ctx; - werr = smbconf_init_reg(r, &ctx, NULL); - if (!W_ERROR_IS_OK(werr)) { + err = smbconf_init_reg(r, &ctx, NULL); + if (!SBC_ERROR_IS_OK(err)) { + werr = WERR_NO_SUCH_SERVICE; goto done; } if (r->in.unjoin_flags & WKSSVC_JOIN_FLAGS_JOIN_TYPE) { - werr = smbconf_set_global_parameter(ctx, "security", "user"); - W_ERROR_NOT_OK_GOTO_DONE(werr); + err = smbconf_set_global_parameter(ctx, "security", "user"); + if (!SBC_ERROR_IS_OK(err)) { + werr = WERR_NO_SUCH_SERVICE; + goto done; + } - werr = smbconf_delete_global_parameter(ctx, "workgroup"); - W_ERROR_NOT_OK_GOTO_DONE(werr); + err = smbconf_delete_global_parameter(ctx, "workgroup"); + if (!SBC_ERROR_IS_OK(err)) { + werr = WERR_NO_SUCH_SERVICE; + goto done; + } smbconf_delete_global_parameter(ctx, "realm"); } @@ -1741,7 +1771,7 @@ static int libnet_destroy_JoinCtx(struct libnet_JoinCtx *r) } krb5_cc_env = getenv(KRB5_ENV_CCNAME); - if (krb5_cc_env && StrCaseCmp(krb5_cc_env, "MEMORY:libnetjoin")) { + if (krb5_cc_env && strcasecmp_m(krb5_cc_env, "MEMORY:libnetjoin")) { unsetenv(KRB5_ENV_CCNAME); } @@ -1760,7 +1790,7 @@ static int libnet_destroy_UnjoinCtx(struct libnet_UnjoinCtx *r) } krb5_cc_env = getenv(KRB5_ENV_CCNAME); - if (krb5_cc_env && StrCaseCmp(krb5_cc_env, "MEMORY:libnetjoin")) { + if (krb5_cc_env && strcasecmp_m(krb5_cc_env, "MEMORY:libnetjoin")) { unsetenv(KRB5_ENV_CCNAME); } @@ -1783,7 +1813,7 @@ WERROR libnet_init_JoinCtx(TALLOC_CTX *mem_ctx, talloc_set_destructor(ctx, libnet_destroy_JoinCtx); - ctx->in.machine_name = talloc_strdup(mem_ctx, global_myname()); + ctx->in.machine_name = talloc_strdup(mem_ctx, lp_netbios_name()); W_ERROR_HAVE_NO_MEMORY(ctx->in.machine_name); krb5_cc_env = getenv(KRB5_ENV_CCNAME); @@ -1816,7 +1846,7 @@ WERROR libnet_init_UnjoinCtx(TALLOC_CTX *mem_ctx, talloc_set_destructor(ctx, libnet_destroy_UnjoinCtx); - ctx->in.machine_name = talloc_strdup(mem_ctx, global_myname()); + ctx->in.machine_name = talloc_strdup(mem_ctx, lp_netbios_name()); W_ERROR_HAVE_NO_MEMORY(ctx->in.machine_name); krb5_cc_env = getenv(KRB5_ENV_CCNAME); diff --git a/source3/libnet/libnet_join.h b/source3/libnet/libnet_join.h index 5659828a5c..dccf03b715 100644 --- a/source3/libnet/libnet_join.h +++ b/source3/libnet/libnet_join.h @@ -1,3 +1,26 @@ +/* + * Unix SMB/CIFS implementation. + * libnet Join Support + * Copyright (C) Gerald (Jerry) Carter 2006 + * 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 _LIBNET_LIBNET_JOIN_H_ +#define _LIBNET_LIBNET_JOIN_H_ + /* The following definitions come from libnet/libnet_join.c */ NTSTATUS libnet_join_ok(const char *netbios_domain_name, @@ -11,3 +34,5 @@ WERROR libnet_Join(TALLOC_CTX *mem_ctx, struct libnet_JoinCtx *r); WERROR libnet_Unjoin(TALLOC_CTX *mem_ctx, struct libnet_UnjoinCtx *r); + +#endif /* _LIBNET_LIBNET_JOIN_H_ */ diff --git a/source3/libnet/libnet_keytab.c b/source3/libnet/libnet_keytab.c index f395c975e5..6349c2291f 100644 --- a/source3/libnet/libnet_keytab.c +++ b/source3/libnet/libnet_keytab.c @@ -66,7 +66,7 @@ krb5_error_code libnet_keytab_init(TALLOC_CTX *mem_ctx, struct libnet_keytab_context *r; - r = TALLOC_ZERO_P(mem_ctx, struct libnet_keytab_context); + r = talloc_zero(mem_ctx, struct libnet_keytab_context); if (!r) { return ENOMEM; } diff --git a/source3/libnet/libnet_samsync.c b/source3/libnet/libnet_samsync.c index 1141bed730..75fc329e0a 100644 --- a/source3/libnet/libnet_samsync.c +++ b/source3/libnet/libnet_samsync.c @@ -23,7 +23,6 @@ #include "includes.h" #include "libnet/libnet_samsync.h" -#include "../lib/crypto/crypto.h" #include "../libcli/samsync/samsync.h" #include "../libcli/auth/libcli_auth.h" #include "rpc_client/rpc_client.h" @@ -71,7 +70,7 @@ NTSTATUS libnet_samsync_init_context(TALLOC_CTX *mem_ctx, *ctx_p = NULL; - ctx = TALLOC_ZERO_P(mem_ctx, struct samsync_context); + ctx = talloc_zero(mem_ctx, struct samsync_context); NT_STATUS_HAVE_NO_MEMORY(ctx); if (domain_sid) { @@ -204,7 +203,7 @@ static NTSTATUS libnet_samsync_delta(TALLOC_CTX *mem_ctx, NTSTATUS result, status; NTSTATUS callback_status; const char *logon_server = ctx->cli->desthost; - const char *computername = global_myname(); + const char *computername = lp_netbios_name(); struct netr_Authenticator credential; struct netr_Authenticator return_authenticator; uint16_t restart_state = 0; @@ -405,7 +404,7 @@ NTSTATUS pull_netr_AcctLockStr(TALLOC_CTX *mem_ctx, *str_p = NULL; - str = TALLOC_ZERO_P(mem_ctx, struct netr_AcctLockStr); + str = talloc_zero(mem_ctx, struct netr_AcctLockStr); if (!str) { return NT_STATUS_NO_MEMORY; } diff --git a/source3/libnet/libnet_samsync_ldif.c b/source3/libnet/libnet_samsync_ldif.c index 4154a07fda..f535e28e33 100644 --- a/source3/libnet/libnet_samsync_ldif.c +++ b/source3/libnet/libnet_samsync_ldif.c @@ -68,6 +68,33 @@ struct samsync_ldif_context { int num_alloced; }; +/* + Returns the substring from src between the first occurrence of + the char "front" and the first occurence of the char "back". + Mallocs the return string which must be freed. Not for use + with wide character strings. +*/ +static char *sstring_sub(const char *src, char front, char back) +{ + char *temp1, *temp2, *temp3; + ptrdiff_t len; + + temp1 = strchr(src, front); + if (temp1 == NULL) return NULL; + temp2 = strchr(src, back); + if (temp2 == NULL) return NULL; + len = temp2 - temp1; + if (len <= 0) return NULL; + temp3 = (char*)SMB_MALLOC(len); + if (temp3 == NULL) { + DEBUG(1,("Malloc failure in sstring_sub\n")); + return NULL; + } + memcpy(temp3, temp1+1, len-1); + temp3[len-1] = '\0'; + return temp3; +} + /**************************************************************** ****************************************************************/ @@ -919,7 +946,7 @@ static NTSTATUS ldif_init_context(TALLOC_CTX *mem_ctx, return NT_STATUS_OK; } - r = TALLOC_ZERO_P(mem_ctx, struct samsync_ldif_context); + r = talloc_zero(mem_ctx, struct samsync_ldif_context); NT_STATUS_HAVE_NO_MEMORY(r); /* Get the ldap suffix */ @@ -966,8 +993,8 @@ static NTSTATUS ldif_init_context(TALLOC_CTX *mem_ctx, } /* Allocate initial memory for groupmap and accountmap arrays */ - r->groupmap = TALLOC_ZERO_ARRAY(mem_ctx, GROUPMAP, 8); - r->accountmap = TALLOC_ZERO_ARRAY(mem_ctx, ACCOUNTMAP, 8); + r->groupmap = talloc_zero_array(mem_ctx, GROUPMAP, 8); + r->accountmap = talloc_zero_array(mem_ctx, ACCOUNTMAP, 8); if (r->groupmap == NULL || r->accountmap == NULL) { DEBUG(1,("GROUPMAP talloc failed\n")); status = NT_STATUS_NO_MEMORY; @@ -1173,12 +1200,12 @@ static NTSTATUS ldif_realloc_maps(TALLOC_CTX *mem_ctx, uint32_t num_entries) { /* Re-allocate memory for groupmap and accountmap arrays */ - l->groupmap = TALLOC_REALLOC_ARRAY(mem_ctx, + l->groupmap = talloc_realloc(mem_ctx, l->groupmap, GROUPMAP, num_entries + l->num_alloced); - l->accountmap = TALLOC_REALLOC_ARRAY(mem_ctx, + l->accountmap = talloc_realloc(mem_ctx, l->accountmap, ACCOUNTMAP, num_entries + l->num_alloced); diff --git a/source3/libnet/libnet_samsync_passdb.c b/source3/libnet/libnet_samsync_passdb.c index b579723f6f..0cf2ed3323 100644 --- a/source3/libnet/libnet_samsync_passdb.c +++ b/source3/libnet/libnet_samsync_passdb.c @@ -428,11 +428,11 @@ static NTSTATUS fetch_group_info(TALLOC_CTX *mem_ctx, map.gid = grp->gr_gid; map.sid = group_sid; map.sid_name_use = SID_NAME_DOM_GRP; - fstrcpy(map.nt_name, name); + strlcpy(map.nt_name, name, sizeof(map.nt_name)); if (r->description.string) { - fstrcpy(map.comment, comment); + strlcpy(map.comment, comment, sizeof(map.comment)); } else { - fstrcpy(map.comment, ""); + strlcpy(map.comment, "", sizeof(map.comment)); } if (insert) @@ -476,7 +476,7 @@ static NTSTATUS fetch_group_mem_info(TALLOC_CTX *mem_ctx, d_printf("Group members of %s: ", grp->gr_name); if (r->num_rids) { - if ((nt_members = TALLOC_ZERO_ARRAY(mem_ctx, char *, r->num_rids)) == NULL) { + if ((nt_members = talloc_zero_array(mem_ctx, char *, r->num_rids)) == NULL) { DEBUG(0, ("talloc failed\n")); return NT_STATUS_NO_MEMORY; } @@ -617,8 +617,8 @@ static NTSTATUS fetch_alias_info(TALLOC_CTX *mem_ctx, else map.sid_name_use = SID_NAME_ALIAS; - fstrcpy(map.nt_name, name); - fstrcpy(map.comment, comment); + strlcpy(map.nt_name, name, sizeof(map.nt_name)); + strlcpy(map.comment, comment, sizeof(map.comment)); if (insert) pdb_add_group_mapping_entry(&map); |