From: Gerald Carter Date: Tue, 21 Feb 2006 14:34:11 +0000 (+0000) Subject: r13590: * replace all pdb_init_sam[_talloc]() calls with samu_new() X-Git-Tag: samba-4.0.0alpha6~801^2~9074 X-Git-Url: http://git.samba.org/?a=commitdiff_plain;h=cd559192633d78a9f06e239c6a448955f6ea0842;p=samba.git r13590: * replace all pdb_init_sam[_talloc]() calls with samu_new() * replace all pdb_{init,fill}_sam_pw() calls with samu_set_unix() (This used to be commit 6f1afa4acc93a07d0ee9940822d7715acaae634f) --- diff --git a/source3/auth/auth_rhosts.c b/source3/auth/auth_rhosts.c index 7068fa2e888..23e276bc84e 100644 --- a/source3/auth/auth_rhosts.c +++ b/source3/auth/auth_rhosts.c @@ -31,7 +31,7 @@ static NTSTATUS auth_get_sam_account(const char *user, struct samu **account) { BOOL pdb_ret; - NTSTATUS nt_status; + NTSTATUS nt_status = NT_STATUS_NO_SUCH_USER; if ( !(*account = samu_new( NULL )) ) { return NT_STATUS_NO_MEMORY; @@ -41,17 +41,18 @@ static NTSTATUS auth_get_sam_account(const char *user, struct samu **account) pdb_ret = pdb_getsampwnam(*account, user); unbecome_root(); - if (!pdb_ret) { - - struct passwd *pass = Get_Pwnam(user); - if (!pass) - return NT_STATUS_NO_SUCH_USER; + if (!pdb_ret) + { + struct passwd *pass; - if (!NT_STATUS_IS_OK(nt_status = pdb_fill_sam_pw(*account, pass))) { - return nt_status; + if ( !(pass = Get_Pwnam( user )) ) { + return NT_STATUS_NO_SUCH_USER; } + + nt_status = samu_set_unix( *account, pass ); } - return NT_STATUS_OK; + + return nt_status; } /**************************************************************************** diff --git a/source3/auth/auth_sam.c b/source3/auth/auth_sam.c index 6f8ca387d24..f06eb83ba1a 100644 --- a/source3/auth/auth_sam.c +++ b/source3/auth/auth_sam.c @@ -250,8 +250,9 @@ static NTSTATUS check_sam_security(const struct auth_context *auth_context, /* Can't use the talloc version here, because the returned struct gets kept on the server_info */ - if (!NT_STATUS_IS_OK(nt_status = pdb_init_sam(&sampass))) { - return nt_status; + + if ( !(sampass = samu_new( NULL )) ) { + return NT_STATUS_NO_MEMORY; } /* get the account information */ diff --git a/source3/auth/auth_unix.c b/source3/auth/auth_unix.c index 1d29389716b..efe5203b233 100644 --- a/source3/auth/auth_unix.c +++ b/source3/auth/auth_unix.c @@ -30,10 +30,12 @@ **/ static BOOL update_smbpassword_file(const char *user, const char *password) { - struct samu *sampass = NULL; + struct samu *sampass; BOOL ret; - pdb_init_sam(&sampass); + if ( !(sampass = samu_new( NULL )) ) { + return False; + } become_root(); ret = pdb_getsampwnam(sampass, user); diff --git a/source3/auth/auth_util.c b/source3/auth/auth_util.c index 7e6ab021b47..bc929fc81df 100644 --- a/source3/auth/auth_util.c +++ b/source3/auth/auth_util.c @@ -172,7 +172,7 @@ NTSTATUS make_user_info_map(auth_usersupplied_info **user_info, and let the "passdb backend" handle unknown users. */ if ( !is_trusted_domain(domain) && !strequal(domain, get_global_sam_name()) ) - domain = get_default_sam_name(); + domain = my_sam_name(); /* we know that it is a trusted domain (and we are allowing them) or it is our domain */ @@ -492,7 +492,7 @@ NT_USER_TOKEN *get_root_nt_token( void ) if ( token ) return token; - if ( !(pw = getpwnam( "root" )) ) { + if ( !(pw = sys_getpwnam( "root" )) ) { DEBUG(0,("get_root_nt_token: getpwnam\"root\") failed!\n")); return NULL; } @@ -951,8 +951,7 @@ NTSTATUS create_token_from_username(TALLOC_CTX *mem_ctx, const char *username, struct samu *sam_acct = NULL; - result = pdb_init_sam_talloc(tmp_ctx, &sam_acct); - if (!NT_STATUS_IS_OK(result)) { + if ( !(sam_acct = samu_new( tmp_ctx )) ) { goto done; } @@ -1100,9 +1099,12 @@ NTSTATUS make_server_info_pac(auth_serversupplied_info **server_info, fstring dom_name; auth_serversupplied_info *result; - status = pdb_init_sam_pw(&sampass, pwd); - - if (!NT_STATUS_IS_OK(status)) { + if ( !(sampass = samu_new( NULL )) ) { + return NT_STATUS_NO_MEMORY; + } + + status = samu_set_unix( sampass, pwd ); + if ( !NT_STATUS_IS_OK(status) ) { return status; } @@ -1157,8 +1159,11 @@ NTSTATUS make_server_info_pw(auth_serversupplied_info **server_info, gid_t *gids; auth_serversupplied_info *result; - status = pdb_init_sam_pw(&sampass, pwd); - + if ( !(sampass = samu_new( NULL )) ) { + return NT_STATUS_NO_MEMORY; + } + + status = samu_set_unix( sampass, pwd ); if (!NT_STATUS_IS_OK(status)) { return status; } @@ -1211,10 +1216,8 @@ static NTSTATUS make_new_server_info_guest(auth_serversupplied_info **server_inf BOOL ret; static const char zeros[16]; - status = pdb_init_sam(&sampass); - - if (!NT_STATUS_IS_OK(status)) { - return status; + if ( !(sampass = samu_new( NULL )) ) { + return NT_STATUS_NO_MEMORY; } sid_copy(&guest_sid, get_global_sam_sid()); @@ -1311,7 +1314,7 @@ static NTSTATUS fill_sam_account(TALLOC_CTX *mem_ctx, const char *username, char **found_username, uid_t *uid, gid_t *gid, - struct samu **sam_account) + struct samu *account) { NTSTATUS nt_status; fstring dom_user, lower_username; @@ -1345,11 +1348,12 @@ static NTSTATUS fill_sam_account(TALLOC_CTX *mem_ctx, *found_username = talloc_strdup( mem_ctx, real_username ); - DEBUG(5,("fill_sam_account: located username was [%s]\n", - *found_username)); + DEBUG(5,("fill_sam_account: located username was [%s]\n", *found_username)); - nt_status = pdb_init_sam_pw(sam_account, passwd); + nt_status = samu_set_unix( account, passwd ); + TALLOC_FREE(passwd); + return nt_status; } @@ -1452,7 +1456,6 @@ NTSTATUS make_server_info_info3(TALLOC_CTX *mem_ctx, char *found_username; const char *nt_domain; const char *nt_username; - struct samu *sam_account = NULL; DOM_SID user_sid; DOM_SID group_sid; @@ -1504,30 +1507,30 @@ NTSTATUS make_server_info_info3(TALLOC_CTX *mem_ctx, that is how the current code is designed. Making the change here is the least disruptive place. -- jerry */ + if ( !(sam_account = samu_new( NULL )) ) { + return NT_STATUS_NO_MEMORY; + } + nt_status = fill_sam_account(mem_ctx, nt_domain, sent_nt_username, - &found_username, &uid, &gid, - &sam_account); + &found_username, &uid, &gid, sam_account); if (NT_STATUS_EQUAL(nt_status, NT_STATUS_NO_SUCH_USER)) { DEBUG(3,("User %s does not exist, trying to add it\n", internal_username)); smb_create_user( nt_domain, sent_nt_username, NULL); - nt_status = fill_sam_account( mem_ctx, nt_domain, - sent_nt_username, - &found_username, &uid, &gid, - &sam_account ); + nt_status = fill_sam_account( mem_ctx, nt_domain, sent_nt_username, + &found_username, &uid, &gid, sam_account ); } /* if we still don't have a valid unix account check for 'map to gues = bad uid' */ if (!NT_STATUS_IS_OK(nt_status)) { + TALLOC_FREE( sam_account ); if ( lp_map_to_guest() == MAP_TO_GUEST_ON_BAD_UID ) { make_server_info_guest(server_info); return NT_STATUS_OK; } - - DEBUG(0, ("make_server_info_info3: pdb_init_sam failed!\n")); return nt_status; } diff --git a/source3/pam_smbpass/pam_smb_acct.c b/source3/pam_smbpass/pam_smb_acct.c index 8d5882bc931..cf53e04d7e7 100644 --- a/source3/pam_smbpass/pam_smb_acct.c +++ b/source3/pam_smbpass/pam_smb_acct.c @@ -79,10 +79,13 @@ int pam_sm_acct_mgmt( pam_handle_t *pamh, int flags, } /* Get the user's record. */ - pdb_init_sam(&sampass); - pdb_getsampwnam(sampass, name ); - if (!sampass) { + if ( (sampass = samu_new( NULL )) != NULL ) { + pdb_getsampwnam(sampass, name ); + } + + /* check for lookup failure */ + if ( !sampass || !strlen(pdb_get_username(sampass)) ) { CatchSignal(SIGPIPE, SIGNAL_CAST oldsig_handler); return PAM_USER_UNKNOWN; } diff --git a/source3/pam_smbpass/pam_smb_auth.c b/source3/pam_smbpass/pam_smb_auth.c index 3de752cd30e..f7980e2bb23 100644 --- a/source3/pam_smbpass/pam_smb_auth.c +++ b/source3/pam_smbpass/pam_smb_auth.c @@ -107,7 +107,7 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags, AUTH_RETURN; } - pdb_init_sam(&sampass); + sampass = samu_new( NULL ); found = pdb_getsampwnam( sampass, name ); diff --git a/source3/pam_smbpass/pam_smb_passwd.c b/source3/pam_smbpass/pam_smb_passwd.c index f0a94bd49cb..8eca1d6aa97 100644 --- a/source3/pam_smbpass/pam_smb_passwd.c +++ b/source3/pam_smbpass/pam_smb_passwd.c @@ -102,8 +102,6 @@ int pam_sm_chauthtok(pam_handle_t *pamh, int flags, char *pass_old; char *pass_new; - NTSTATUS nt_status; - /* Samba initialization. */ setup_logging( "pam_smbpass", False ); in_client = True; @@ -137,9 +135,9 @@ int pam_sm_chauthtok(pam_handle_t *pamh, int flags, } /* obtain user record */ - if (!NT_STATUS_IS_OK(nt_status = pdb_init_sam(&sampass))) { + if ( !(sampass = samu_new( NULL )) ) { CatchSignal(SIGPIPE, SIGNAL_CAST oldsig_handler); - return nt_status_to_pam(nt_status); + return nt_status_to_pam(NT_STATUS_NO_MEMORY); } if (!pdb_getsampwnam(sampass,user)) { diff --git a/source3/passdb/passdb.c b/source3/passdb/passdb.c index 1632d222d46..358d99b0ca7 100644 --- a/source3/passdb/passdb.c +++ b/source3/passdb/passdb.c @@ -3,7 +3,7 @@ Password and authentication handling Copyright (C) Jeremy Allison 1996-2001 Copyright (C) Luke Kenneth Casson Leighton 1996-1998 - Copyright (C) Gerald (Jerry) Carter 2000-2001 + Copyright (C) Gerald (Jerry) Carter 2000-2006 Copyright (C) Andrew Bartlett 2001-2002 Copyright (C) Simo Sorce 2003 Copyright (C) Volker Lendecke 2006 @@ -36,7 +36,7 @@ standalone box will map to WKS\user. ******************************************************************/ -const char *get_default_sam_name(void) +const char *my_sam_name(void) { /* standalone servers can only use the local netbios name */ if ( lp_server_role() == ROLE_STANDALONE ) @@ -51,7 +51,7 @@ const char *get_default_sam_name(void) Fill the struct samu with default values. ***********************************************************/ -void pdb_fill_default_sam(struct samu *user) +static void samu_init( struct samu *user ) { /* no initial methods */ user->methods = NULL; @@ -62,8 +62,8 @@ void pdb_fill_default_sam(struct samu *user) user->logon_time = (time_t)0; user->pass_last_set_time = (time_t)0; user->pass_can_change_time = (time_t)0; - user->logoff_time = - user->kickoff_time = + user->logoff_time = get_time_t_max(); + user->kickoff_time = get_time_t_max(); user->pass_must_change_time = get_time_t_max(); user->fields_present = 0x00ffffff; user->logon_divs = 168; /* hours per week */ @@ -115,16 +115,6 @@ static int samu_destroy(void *p) return 0; } -/********************************************************************** -***********************************************************************/ - -BOOL samu_init( struct samu *user ) -{ - pdb_fill_default_sam( user ); - - return True; -} - /********************************************************************** generate a new struct samuser ***********************************************************************/ @@ -138,41 +128,13 @@ struct samu* samu_new( TALLOC_CTX *ctx ) return NULL; } - if ( !samu_init( user ) ) { - DEBUG(0,("samuser_new: initialization failed!\n")); - TALLOC_FREE( user ); - return NULL; - } + samu_init( user ); talloc_set_destructor( user, samu_destroy ); return user; } -/********************************************************************** - Allocates memory and initialises a struct sam_passwd on supplied mem_ctx. -***********************************************************************/ - -NTSTATUS pdb_init_sam_talloc(TALLOC_CTX *mem_ctx, struct samu **user) -{ - if ( !*user ) - return NT_STATUS_UNSUCCESSFUL; - - *user = samu_new( mem_ctx ); - return *user ? NT_STATUS_OK : NT_STATUS_NO_MEMORY; -} - - -/************************************************************* - Allocates memory and initialises a struct sam_passwd. - ************************************************************/ - -NTSTATUS pdb_init_sam(struct samu **user) -{ - *user = samu_new( NULL ); - return *user ? NT_STATUS_OK : NT_STATUS_NO_MEMORY; -} - /************************************************************************** * This function will take care of all the steps needed to correctly * allocate and set the user SID, please do use this function to create new @@ -252,21 +214,17 @@ static NTSTATUS pdb_set_sam_sids(struct samu *account_data, const struct passwd Initialises a struct sam_passwd with sane values. ************************************************************/ -NTSTATUS pdb_fill_sam_pw(struct samu *sam_account, const struct passwd *pwd) +NTSTATUS samu_set_unix(struct samu *sam_account, const struct passwd *pwd) { NTSTATUS ret; - if (!pwd) { - return NT_STATUS_UNSUCCESSFUL; + if ( !pwd ) { + return NT_STATUS_NO_SUCH_USER; } - pdb_fill_default_sam(sam_account); - pdb_set_username(sam_account, pwd->pw_name, PDB_SET); pdb_set_fullname(sam_account, pwd->pw_gecos, PDB_SET); - pdb_set_unix_homedir(sam_account, pwd->pw_dir, PDB_SET); - pdb_set_domain (sam_account, get_global_sam_name(), PDB_DEFAULT); /* When we get a proper uid -> SID and SID -> uid allocation @@ -280,7 +238,8 @@ NTSTATUS pdb_fill_sam_pw(struct samu *sam_account, const struct passwd *pwd) */ ret = pdb_set_sam_sids(sam_account, pwd); - if (!NT_STATUS_IS_OK(ret)) return ret; + if (!NT_STATUS_IS_OK(ret)) + return ret; /* check if this is a user account or a machine account */ if (pwd->pw_name[strlen(pwd->pw_name)-1] != '$') @@ -325,38 +284,9 @@ NTSTATUS pdb_fill_sam_pw(struct samu *sam_account, const struct passwd *pwd) return NT_STATUS_OK; } - -/************************************************************* - Initialises a struct sam_passwd with sane values. - ************************************************************/ - -NTSTATUS pdb_init_sam_pw(struct samu **new_sam_acct, const struct passwd *pwd) -{ - NTSTATUS nt_status; - - if (!pwd) { - new_sam_acct = NULL; - return NT_STATUS_INVALID_PARAMETER; - } - - if (!NT_STATUS_IS_OK(nt_status = pdb_init_sam(new_sam_acct))) { - new_sam_acct = NULL; - return nt_status; - } - - if (!NT_STATUS_IS_OK(nt_status = pdb_fill_sam_pw(*new_sam_acct, pwd))) { - TALLOC_FREE(new_sam_acct); - new_sam_acct = NULL; - return nt_status; - } - - return NT_STATUS_OK; -} - - /************************************************************* Initialises a struct samu ready to add a new account, based - on the UNIX user. Pass in a RID if you have one + on the UNIX user. ************************************************************/ NTSTATUS pdb_init_sam_new(struct samu **new_sam_acct, const char *username) @@ -374,17 +304,21 @@ NTSTATUS pdb_init_sam_new(struct samu **new_sam_acct, const char *username) return NT_STATUS_NO_MEMORY; } - pwd = Get_Pwnam_alloc(mem_ctx, username); - - if (pwd == NULL) { + if ( !(pwd = Get_Pwnam_alloc(mem_ctx, username)) ) { DEBUG(10, ("Could not find user %s\n", username)); result = NT_STATUS_NO_SUCH_USER; goto done; } - result = pdb_init_sam_pw(new_sam_acct, pwd); + if ( !(*new_sam_acct = samu_new( NULL )) ) { + result = NT_STATUS_NO_MEMORY; + goto done; + } + + result = samu_set_unix( *new_sam_acct, pwd ); + if (!NT_STATUS_IS_OK(result)) { - DEBUG(10, ("pdb_init_sam_pw failed: %s\n", nt_errstr(result))); + DEBUG(10, ("samu_set_unix failed: %s\n", nt_errstr(result))); goto done; } @@ -792,7 +726,7 @@ BOOL lookup_global_sam_name(const char *user, int flags, uint32_t *rid, struct samu *sam_account = NULL; DOM_SID user_sid; - if (!NT_STATUS_IS_OK(pdb_init_sam(&sam_account))) { + if ( !(sam_account = samu_new( NULL )) ) { return False; } @@ -862,7 +796,10 @@ NTSTATUS local_password_change(const char *user_name, int local_flags, *msg_str = '\0'; /* Get the smb passwd entry for this user */ - pdb_init_sam(&sam_pass); + + if ( !(sam_pass = samu_new( NULL )) ) { + return NT_STATUS_NO_MEMORY; + } become_root(); if(!pdb_getsampwnam(sam_pass, user_name)) { @@ -880,8 +817,7 @@ NTSTATUS local_password_change(const char *user_name, int local_flags, result = pdb_init_sam_new(&sam_pass, user_name); DEBUGLEVEL = tmp_debug; - if (NT_STATUS_EQUAL(result, - NT_STATUS_INVALID_PRIMARY_GROUP)) { + if (NT_STATUS_EQUAL(result, NT_STATUS_INVALID_PRIMARY_GROUP)) { return result; } @@ -1912,7 +1848,7 @@ BOOL pdb_copy_sam_account(const struct samu *src, struct samu **dst) uint8 *buf; int len; - if ((*dst == NULL) && (!NT_STATUS_IS_OK(pdb_init_sam(dst)))) + if ( !*dst && !(*dst = samu_new(NULL)) ) return False; len = init_buffer_from_sam_v2(&buf, src, False); diff --git a/source3/passdb/pdb_interface.c b/source3/passdb/pdb_interface.c index 7f85c4d7c41..294cd513487 100644 --- a/source3/passdb/pdb_interface.c +++ b/source3/passdb/pdb_interface.c @@ -285,7 +285,7 @@ BOOL pdb_getsampwnam(struct samu *sam_acct, const char *username) BOOL guest_user_info( struct samu *user ) { struct passwd *pwd; - NTSTATUS ntstatus; + NTSTATUS result; const char *guestname = lp_guestaccount(); if ( !(pwd = getpwnam_alloc( NULL, guestname ) ) ) { @@ -294,11 +294,11 @@ BOOL guest_user_info( struct samu *user ) return False; } - /* fill in from the users information */ - - ntstatus = pdb_fill_sam_pw( user, pwd ); - - return NT_STATUS_IS_OK(ntstatus); + result = samu_set_unix(user, pwd); + + TALLOC_FREE( pwd ); + + return NT_STATUS_IS_OK( result ); } @@ -816,7 +816,6 @@ static NTSTATUS pdb_default_add_groupmem(struct pdb_methods *methods, struct passwd *pwd; const char *group_name; uid_t uid; - NTSTATUS status; sid_compose(&group_sid, get_global_sam_sid(), group_rid); sid_compose(&member_sid, get_global_sam_sid(), member_rid); @@ -832,8 +831,8 @@ static NTSTATUS pdb_default_add_groupmem(struct pdb_methods *methods, return NT_STATUS_NO_MEMORY; } - if (!NT_STATUS_IS_OK(status = pdb_init_sam(&account))) { - return status; + if ( !(account = samu_new( NULL )) ) { + return NT_STATUS_NO_MEMORY; } if (!pdb_getsampwsid(account, &member_sid) || @@ -884,7 +883,6 @@ static NTSTATUS pdb_default_del_groupmem(struct pdb_methods *methods, struct passwd *pwd; const char *group_name; uid_t uid; - NTSTATUS status; sid_compose(&group_sid, get_global_sam_sid(), group_rid); sid_compose(&member_sid, get_global_sam_sid(), member_rid); @@ -900,8 +898,8 @@ static NTSTATUS pdb_default_del_groupmem(struct pdb_methods *methods, return NT_STATUS_NO_MEMORY; } - if (!NT_STATUS_IS_OK(status = pdb_init_sam(&account))) { - return status; + if ( !(account = samu_new( NULL )) ) { + return NT_STATUS_NO_MEMORY; } if (!pdb_getsampwsid(account, &member_sid) || @@ -1288,12 +1286,11 @@ static BOOL pdb_default_uid_to_rid(struct pdb_methods *methods, uid_t uid, return False; } - if ( !NT_STATUS_IS_OK(pdb_init_sam(&sampw)) ) { - DEBUG(0,("pdb_default_uid_to_rid: failed to allocate " - "struct samu object\n")); + if ( !(sampw = samu_new( NULL )) ) { + DEBUG(0,("pdb_default_uid_to_rid: samu_new() failed!\n")); return False; } - + become_root(); ret = NT_STATUS_IS_OK( methods->getsampwnam(methods, sampw, unix_pw->pw_name )); @@ -1565,7 +1562,8 @@ static BOOL lookup_global_sam_rid(TALLOC_CTX *mem_ctx, uint32 rid, sid_append_rid(&sid, rid); /* see if the passdb can help us with the name of the user */ - if (!NT_STATUS_IS_OK(pdb_init_sam(&sam_account))) { + + if ( !(sam_account = samu_new( NULL )) ) { return False; } @@ -1813,12 +1811,10 @@ static BOOL next_entry_users(struct pdb_search *s, { struct user_search *state = s->private_data; struct samu *user = NULL; - NTSTATUS status; next: - status = pdb_init_sam(&user); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(0, ("Could not pdb_init_sam\n")); + if ( !(user = samu_new( NULL )) ) { + DEBUG(0, ("next_entry_users: samu_new() failed!\n")); return False; } diff --git a/source3/passdb/pdb_smbpasswd.c b/source3/passdb/pdb_smbpasswd.c index ebd5de22582..f354d0c444d 100644 --- a/source3/passdb/pdb_smbpasswd.c +++ b/source3/passdb/pdb_smbpasswd.c @@ -1190,7 +1190,7 @@ static BOOL build_sam_account(struct smbpasswd_privates *smbpasswd_state, { struct passwd *pwfile; - if (sam_pass==NULL) { + if ( !sam_pass ) { DEBUG(5,("build_sam_account: struct samu is NULL\n")); return False; } @@ -1203,7 +1203,7 @@ static BOOL build_sam_account(struct smbpasswd_privates *smbpasswd_state, return False; } - if (!NT_STATUS_IS_OK(pdb_fill_sam_pw(sam_pass, pwfile))) + if ( !NT_STATUS_IS_OK( samu_set_unix(sam_pass, pwfile)) ) return False; TALLOC_FREE(pwfile); @@ -1269,13 +1269,11 @@ static NTSTATUS smbpasswd_getsampwent(struct pdb_methods *my_methods, struct sam struct smbpasswd_privates *smbpasswd_state = (struct smbpasswd_privates*)my_methods->private_data; struct smb_passwd *pw_buf=NULL; BOOL done = False; + DEBUG(5,("pdb_getsampwent\n")); - if (user==NULL) { + if ( !user ) { DEBUG(5,("pdb_getsampwent (smbpasswd): user is NULL\n")); -#if 0 - smb_panic("NULL pointer passed to getsampwent (smbpasswd)\n"); -#endif return nt_status; } @@ -1338,9 +1336,6 @@ static NTSTATUS smbpasswd_getsampwnam(struct pdb_methods *my_methods, if (!sam_acct) { DEBUG(10,("getsampwnam (smbpasswd): struct samu is NULL\n")); -#if 0 - smb_panic("NULL pointer passed to pdb_getsampwnam\n"); -#endif return nt_status; } @@ -1398,9 +1393,6 @@ static NTSTATUS smbpasswd_getsampwsid(struct pdb_methods *my_methods, struct sam if (!sam_acct) { DEBUG(10,("getsampwrid: (smbpasswd) struct samu is NULL\n")); -#if 0 - smb_panic("NULL pointer passed to pdb_getsampwrid\n"); -#endif return nt_status; } diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 0a05e1f2a51..e994760fabc 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -101,7 +101,11 @@ static BOOL tdbsam_convert(int32 from) } /* unpack the buffer from the former format */ - pdb_init_sam( &user ); + if ( !(user = samu_new( NULL )) ) { + DEBUG(0,("tdbsam_convert: samu_new() failed!\n")); + SAFE_FREE( data.dptr ); + return False; + } DEBUG(10,("tdbsam_convert: Try unpacking a record with (key:%s) (version:%d)\n", key.dptr, from)); switch (from) { case 0: diff --git a/source3/rpc_server/srv_netlog_nt.c b/source3/rpc_server/srv_netlog_nt.c index ea0685f41b2..a71d97ada78 100644 --- a/source3/rpc_server/srv_netlog_nt.c +++ b/source3/rpc_server/srv_netlog_nt.c @@ -229,8 +229,9 @@ static BOOL get_md4pw(char *md4pw, char *mach_acct) } #endif /* 0 */ - if(!NT_STATUS_IS_OK(pdb_init_sam(&sampass))) + if ( !(sampass = samu_new( NULL )) ) { return False; + } /* JRA. This is ok as it is only used for generating the challenge. */ become_root(); @@ -517,10 +518,14 @@ NTSTATUS _net_srv_pwset(pipes_struct *p, NET_Q_SRV_PWSET *q_u, NET_R_SRV_PWSET * secrets_store_schannel_session_info(p->pipe_state_mem_ctx, remote_machine, p->dc); - pdb_init_sam(&sampass); - ret=pdb_getsampwnam(sampass, p->dc->mach_acct); + if ( (sampass = samu_new( NULL )) != NULL ) { + ret = pdb_getsampwnam(sampass, p->dc->mach_acct); + } unbecome_root(); + if ( !sampass ) + return NT_STATUS_NO_MEMORY; + /* Ensure the account exists and is a machine account. */ acct_ctrl = pdb_get_acct_ctrl(sampass); diff --git a/source3/rpc_server/srv_samr_nt.c b/source3/rpc_server/srv_samr_nt.c index f9a28f1272f..5c2950b4917 100644 --- a/source3/rpc_server/srv_samr_nt.c +++ b/source3/rpc_server/srv_samr_nt.c @@ -1693,10 +1693,9 @@ NTSTATUS _samr_open_user(pipes_struct *p, SAMR_Q_OPEN_USER *q_u, SAMR_R_OPEN_USE if ( !NT_STATUS_IS_OK(nt_status) ) return nt_status; - nt_status = pdb_init_sam_talloc(p->mem_ctx, &sampass); - - if (!NT_STATUS_IS_OK(nt_status)) - return nt_status; + if ( !(sampass = samu_new( p->mem_ctx )) ) { + return NT_STATUS_NO_MEMORY; + } /* append the user's RID to it */ @@ -1749,19 +1748,16 @@ static NTSTATUS get_user_info_7(TALLOC_CTX *mem_ctx, SAM_USER_INFO_7 *id7, DOM_S { struct samu *smbpass=NULL; BOOL ret; - NTSTATUS nt_status; - nt_status = pdb_init_sam_talloc(mem_ctx, &smbpass); - - if (!NT_STATUS_IS_OK(nt_status)) { - return nt_status; + if ( !(smbpass = samu_new( mem_ctx )) ) { + return NT_STATUS_NO_MEMORY; } - + become_root(); ret = pdb_getsampwsid(smbpass, user_sid); unbecome_root(); - if (ret==False) { + if ( !ret ) { DEBUG(4,("User %s not found\n", sid_string_static(user_sid))); return NT_STATUS_NO_SUCH_USER; } @@ -1783,12 +1779,9 @@ static NTSTATUS get_user_info_9(TALLOC_CTX *mem_ctx, SAM_USER_INFO_9 * id9, DOM_ { struct samu *smbpass=NULL; BOOL ret; - NTSTATUS nt_status; - - nt_status = pdb_init_sam_talloc(mem_ctx, &smbpass); - if (!NT_STATUS_IS_OK(nt_status)) { - return nt_status; + if ( !(smbpass = samu_new( mem_ctx )) ) { + return NT_STATUS_NO_MEMORY; } become_root(); @@ -1818,12 +1811,9 @@ static NTSTATUS get_user_info_16(TALLOC_CTX *mem_ctx, SAM_USER_INFO_16 *id16, DO { struct samu *smbpass=NULL; BOOL ret; - NTSTATUS nt_status; - nt_status = pdb_init_sam_talloc(mem_ctx, &smbpass); - - if (!NT_STATUS_IS_OK(nt_status)) { - return nt_status; + if ( !(smbpass = samu_new( mem_ctx )) ) { + return NT_STATUS_NO_MEMORY; } become_root(); @@ -1855,7 +1845,6 @@ static NTSTATUS get_user_info_18(pipes_struct *p, TALLOC_CTX *mem_ctx, SAM_USER_ { struct samu *smbpass=NULL; BOOL ret; - NTSTATUS nt_status; if (p->auth.auth_type != PIPE_AUTH_TYPE_NTLMSSP || p->auth.auth_type != PIPE_AUTH_TYPE_SPNEGO_NTLMSSP) { return NT_STATUS_ACCESS_DENIED; @@ -1869,10 +1858,8 @@ static NTSTATUS get_user_info_18(pipes_struct *p, TALLOC_CTX *mem_ctx, SAM_USER_ * Do *NOT* do become_root()/unbecome_root() here ! JRA. */ - nt_status = pdb_init_sam_talloc(mem_ctx, &smbpass); - - if (!NT_STATUS_IS_OK(nt_status)) { - return nt_status; + if ( !(smbpass = samu_new( mem_ctx )) ) { + return NT_STATUS_NO_MEMORY; } ret = pdb_getsampwsid(smbpass, user_sid); @@ -1907,7 +1894,9 @@ static NTSTATUS get_user_info_20(TALLOC_CTX *mem_ctx, SAM_USER_INFO_20 *id20, DO struct samu *sampass=NULL; BOOL ret; - pdb_init_sam_talloc(mem_ctx, &sampass); + if ( !(sampass = samu_new( mem_ctx )) ) { + return NT_STATUS_NO_MEMORY; + } become_root(); ret = pdb_getsampwsid(sampass, user_sid); @@ -1941,9 +1930,8 @@ static NTSTATUS get_user_info_21(TALLOC_CTX *mem_ctx, SAM_USER_INFO_21 *id21, BOOL ret; NTSTATUS nt_status; - nt_status = pdb_init_sam_talloc(mem_ctx, &sampass); - if (!NT_STATUS_IS_OK(nt_status)) { - return nt_status; + if ( !(sampass = samu_new( mem_ctx )) ) { + return NT_STATUS_NO_MEMORY; } become_root(); @@ -2113,8 +2101,10 @@ NTSTATUS _samr_query_usergroups(pipes_struct *p, SAMR_Q_QUERY_USERGROUPS *q_u, S if (!sid_check_is_in_our_domain(&sid)) return NT_STATUS_OBJECT_TYPE_MISMATCH; - pdb_init_sam_talloc(p->mem_ctx, &sam_pass); - + if ( !(sam_pass = samu_new( p->mem_ctx )) ) { + return NT_STATUS_NO_MEMORY; + } + become_root(); ret = pdb_getsampwsid(sam_pass, &sid); unbecome_root(); @@ -3290,7 +3280,9 @@ NTSTATUS _samr_set_userinfo(pipes_struct *p, SAMR_Q_SET_USERINFO *q_u, SAMR_R_SE return NT_STATUS_INVALID_INFO_CLASS; } - pdb_init_sam(&pwd); + if ( !(pwd = samu_new( NULL )) ) { + return NT_STATUS_NO_MEMORY; + } become_root(); ret = pdb_getsampwsid(pwd, &sid); @@ -3438,8 +3430,10 @@ NTSTATUS _samr_set_userinfo2(pipes_struct *p, SAMR_Q_SET_USERINFO2 *q_u, SAMR_R_ switch_value=ctr->switch_value; - pdb_init_sam(&pwd); - + if ( !(pwd = samu_new( NULL )) ) { + return NT_STATUS_NO_MEMORY; + } + become_root(); ret = pdb_getsampwsid(pwd, &sid); unbecome_root(); @@ -3916,7 +3910,10 @@ NTSTATUS _samr_delete_dom_user(pipes_struct *p, SAMR_Q_DELETE_DOM_USER *q_u, SAM return NT_STATUS_CANNOT_DELETE; /* check if the user exists before trying to delete */ - pdb_init_sam(&sam_pass); + if ( !(sam_pass = samu_new( NULL )) ) { + return NT_STATUS_NO_MEMORY; + } + if(!pdb_getsampwsid(sam_pass, &user_sid)) { DEBUG(5,("_samr_delete_dom_user:User %s doesn't exist.\n", sid_string_static(&user_sid))); diff --git a/source3/smbd/chgpasswd.c b/source3/smbd/chgpasswd.c index f8ae7233c64..8df824a323e 100644 --- a/source3/smbd/chgpasswd.c +++ b/source3/smbd/chgpasswd.c @@ -768,7 +768,9 @@ static NTSTATUS check_oem_password(const char *user, *hnd = NULL; - pdb_init_sam(&sampass); + if ( !(sampass = samu_new( NULL )) ) { + return NT_STATUS_NO_MEMORY; + } become_root(); ret = pdb_getsampwnam(sampass, user); diff --git a/source3/smbd/lanman.c b/source3/smbd/lanman.c index 03f7f8e5c86..ca6cc57cc3e 100644 --- a/source3/smbd/lanman.c +++ b/source3/smbd/lanman.c @@ -1981,8 +1981,8 @@ static BOOL api_NetUserGetGroups(connection_struct *conn,uint16 vuid, char *para goto done; } - if (!NT_STATUS_IS_OK(pdb_init_sam_talloc(mem_ctx, &sampw))) { - DEBUG(10, ("pdb_init_sam_talloc failed\n")); + if ( !(sampw = samu_new(mem_ctx)) ) { + DEBUG(0, ("samu_new() failed!\n")); goto done; } diff --git a/source3/utils/net_rpc_samsync.c b/source3/utils/net_rpc_samsync.c index d3b9a9a8a89..05ff28ad65b 100644 --- a/source3/utils/net_rpc_samsync.c +++ b/source3/utils/net_rpc_samsync.c @@ -508,8 +508,9 @@ static NTSTATUS fetch_account_info(uint32 rid, SAM_ACCOUNT_INFO *delta) fstrcpy(account, unistr2_static(&delta->uni_acct_name)); d_printf("Creating account: %s\n", account); - if (!NT_STATUS_IS_OK(nt_ret = pdb_init_sam(&sam_account))) - return nt_ret; + if ( !(sam_account = samu_new( NULL )) ) { + return NT_STATUS_NO_MEMORY; + } if (!(passwd = Get_Pwnam(account))) { /* Create appropriate user */ @@ -690,13 +691,12 @@ static NTSTATUS fetch_group_mem_info(uint32 rid, SAM_GROUP_MEM_INFO *delta) nt_members = TALLOC_ZERO_ARRAY(t, char *, delta->num_members); for (i=0; inum_members; i++) { - NTSTATUS nt_status; struct samu *member = NULL; DOM_SID member_sid; - if (!NT_STATUS_IS_OK(nt_status = pdb_init_sam_talloc(t, &member))) { + if ( !(member = samu_new(t)) ) { talloc_destroy(t); - return nt_status; + return NT_STATUS_NO_MEMORY; } sid_copy(&member_sid, get_global_sam_sid()); diff --git a/source3/utils/net_sam.c b/source3/utils/net_sam.c index ae0aef59600..ea0544abf3a 100644 --- a/source3/utils/net_sam.c +++ b/source3/utils/net_sam.c @@ -54,7 +54,7 @@ static int net_sam_userset(int argc, const char **argv, const char *field, return -1; } - if (!NT_STATUS_IS_OK(pdb_init_sam(&sam_acct))) { + if ( !(sam_acct = samu_new( NULL )) ) { d_fprintf(stderr, "Internal error\n"); return -1; } @@ -151,7 +151,7 @@ static int net_sam_set_userflag(int argc, const char **argv, const char *field, return -1; } - if (!NT_STATUS_IS_OK(pdb_init_sam(&sam_acct))) { + if ( !(sam_acct = samu_new( NULL )) ) { d_fprintf(stderr, "Internal error\n"); return -1; } @@ -254,7 +254,7 @@ static int net_sam_set_time(int argc, const char **argv, const char *field, } - if (!NT_STATUS_IS_OK(pdb_init_sam(&sam_acct))) { + if ( !(sam_acct = samu_new( NULL )) ) { d_fprintf(stderr, "Internal error\n"); return -1; } diff --git a/source3/utils/pdbedit.c b/source3/utils/pdbedit.c index d517783e853..f1e4fb65428 100644 --- a/source3/utils/pdbedit.c +++ b/source3/utils/pdbedit.c @@ -175,7 +175,7 @@ static int print_user_info (struct pdb_methods *in, const char *username, BOOL v struct samu *sam_pwent=NULL; BOOL ret; - if (!NT_STATUS_IS_OK(pdb_init_sam (&sam_pwent))) { + if ( !(sam_pwent = samu_new( NULL )) ) { return -1; } @@ -207,16 +207,22 @@ static int print_users_list (struct pdb_methods *in, BOOL verbosity, BOOL smbpwd } check = True; - if (!(NT_STATUS_IS_OK(pdb_init_sam(&sam_pwent)))) return 1; + if ( !(sam_pwent = samu_new( NULL )) ) { + return 1; + } while (check && NT_STATUS_IS_OK(in->getsampwent (in, sam_pwent))) { if (verbosity) printf ("---------------\n"); print_sam_info (sam_pwent, verbosity, smbpwdstyle); TALLOC_FREE(sam_pwent); - check = NT_STATUS_IS_OK(pdb_init_sam(&sam_pwent)); + + if ( !(sam_pwent = samu_new( NULL )) ) { + check = False; + } } - if (check) TALLOC_FREE(sam_pwent); + if (check) + TALLOC_FREE(sam_pwent); in->endsampwent(in); return 0; @@ -236,7 +242,9 @@ static int fix_users_list (struct pdb_methods *in) } check = True; - if (!(NT_STATUS_IS_OK(pdb_init_sam(&sam_pwent)))) return 1; + if ( !(sam_pwent = samu_new( NULL )) ) { + return 1; + } while (check && NT_STATUS_IS_OK(in->getsampwent (in, sam_pwent))) { printf("Updating record for user %s\n", pdb_get_username(sam_pwent)); @@ -245,13 +253,16 @@ static int fix_users_list (struct pdb_methods *in) printf("Update of user %s failed!\n", pdb_get_username(sam_pwent)); } TALLOC_FREE(sam_pwent); - check = NT_STATUS_IS_OK(pdb_init_sam(&sam_pwent)); + if ( !(sam_pwent = samu_new( NULL )) ) { + check = False; + } if (!check) { fprintf(stderr, "Failed to initialise new struct samu structure (out of memory?)\n"); } } - if (check) TALLOC_FREE(sam_pwent); + if (check) + TALLOC_FREE(sam_pwent); in->endsampwent(in); return 0; @@ -275,7 +286,9 @@ static int set_user_info (struct pdb_methods *in, const char *username, struct samu *sam_pwent=NULL; BOOL ret; - pdb_init_sam(&sam_pwent); + if ( !(sam_pwent = samu_new( NULL )) ) { + return 1; + } ret = NT_STATUS_IS_OK(in->getsampwnam (in, sam_pwent, username)); if (ret==False) { @@ -506,14 +519,22 @@ static int new_machine (struct pdb_methods *in, const char *machine_in) fstrcat(machineaccount, "$"); if ((pwd = getpwnam_alloc(NULL, machineaccount))) { - if (!NT_STATUS_IS_OK(pdb_init_sam_pw( &sam_pwent, pwd))) { + + if ( !(sam_pwent = samu_new( NULL )) ) { + fprintf(stderr, "Memory allocation error!\n"); + TALLOC_FREE(pwd); + return -1; + } + + if ( !NT_STATUS_IS_OK(samu_set_unix(sam_pwent, pwd)) ) { fprintf(stderr, "Could not init sam from pw\n"); TALLOC_FREE(pwd); return -1; } + TALLOC_FREE(pwd); } else { - if (!NT_STATUS_IS_OK(pdb_init_sam (&sam_pwent))) { + if ( !(sam_pwent = samu_new( NULL )) ) { fprintf(stderr, "Could not init sam from pw\n"); return -1; } @@ -546,7 +567,7 @@ static int delete_user_entry (struct pdb_methods *in, const char *username) { struct samu *samaccount = NULL; - if (!NT_STATUS_IS_OK(pdb_init_sam (&samaccount))) { + if ( !(samaccount = samu_new( NULL )) ) { return -1; } @@ -576,7 +597,7 @@ static int delete_machine_entry (struct pdb_methods *in, const char *machinename if (name[strlen(name)-1] != '$') fstrcat (name, "$"); - if (!NT_STATUS_IS_OK(pdb_init_sam (&samaccount))) { + if ( !(samaccount = samu_new( NULL )) ) { return -1; } diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index 61e97fd692f..d66001e441b 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -404,7 +404,7 @@ static int process_root(int local_flags) struct samu *sampass = NULL; BOOL ret; - pdb_init_sam(&sampass); + sampass = samu_new( NULL ); ret = pdb_getsampwnam(sampass, user_name); if((ret) && (pdb_get_lanman_passwd(sampass) == NULL)) { @@ -438,7 +438,7 @@ static int process_root(int local_flags) struct samu *sampass = NULL; BOOL ret; - pdb_init_sam(&sampass); + sampass = samu_new( NULL ); ret = pdb_getsampwnam(sampass, user_name); printf("Password changed for user %s.", user_name );