summaryrefslogtreecommitdiff
path: root/source3/passdb
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2006-02-21 14:34:11 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 11:10:16 -0500
commitcd559192633d78a9f06e239c6a448955f6ea0842 (patch)
tree9b91416a493d3f9ca1d8c65666184539ce8919de /source3/passdb
parent87ef96e6be75fb4988fac48b2e21892720c20426 (diff)
downloadsamba-cd559192633d78a9f06e239c6a448955f6ea0842.tar.gz
samba-cd559192633d78a9f06e239c6a448955f6ea0842.tar.bz2
samba-cd559192633d78a9f06e239c6a448955f6ea0842.zip
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)
Diffstat (limited to 'source3/passdb')
-rw-r--r--source3/passdb/passdb.c120
-rw-r--r--source3/passdb/pdb_interface.c38
-rw-r--r--source3/passdb/pdb_smbpasswd.c16
-rw-r--r--source3/passdb/pdb_tdb.c6
4 files changed, 54 insertions, 126 deletions
diff --git a/source3/passdb/passdb.c b/source3/passdb/passdb.c
index 1632d222d4..358d99b0ca 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 */
@@ -116,16 +116,6 @@ static int samu_destroy(void *p)
}
/**********************************************************************
-***********************************************************************/
-
-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 7f85c4d7c4..294cd51348 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 ebd5de2258..f354d0c444 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 0a05e1f2a5..e994760fab 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: