summaryrefslogtreecommitdiff
path: root/source3/passdb
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2003-04-29 09:43:17 +0000
committerAndrew Bartlett <abartlet@samba.org>2003-04-29 09:43:17 +0000
commit281d95e2f35f8276d23d075d6e528d16eda9fadc (patch)
tree9b91d5842a743bf3135e91a3942b76a173e1fd13 /source3/passdb
parente3ae1a2f2398e8fa107673e83f75675629938d75 (diff)
downloadsamba-281d95e2f35f8276d23d075d6e528d16eda9fadc.tar.gz
samba-281d95e2f35f8276d23d075d6e528d16eda9fadc.tar.bz2
samba-281d95e2f35f8276d23d075d6e528d16eda9fadc.zip
Use a common function to create the SAM_ACCOUNT being used to add accounts
to the system. This means that we always run Get_Pwnam(), and can never add FOO when foo exists on the system (the idea is to instead add foo into the passdb, using it's full name, RID etc). Andrew Bartlett (This used to be commit bb79b127e02cefae13c822fd0fd165f1f214b740)
Diffstat (limited to 'source3/passdb')
-rw-r--r--source3/passdb/passdb.c61
1 files changed, 36 insertions, 25 deletions
diff --git a/source3/passdb/passdb.c b/source3/passdb/passdb.c
index 9f91fb57f3..bbccb86d82 100644
--- a/source3/passdb/passdb.c
+++ b/source3/passdb/passdb.c
@@ -301,6 +301,38 @@ NTSTATUS pdb_init_sam_pw(SAM_ACCOUNT **new_sam_acct, const struct passwd *pwd)
}
+/*************************************************************
+ Initialises a SAM_ACCOUNT ready to add a new account, based
+ on the unix user if possible.
+ ************************************************************/
+
+NTSTATUS pdb_init_sam_new(SAM_ACCOUNT **new_sam_acct, const char *username)
+{
+ NTSTATUS nt_status = NT_STATUS_NO_MEMORY;
+
+ struct passwd *pwd;
+
+ pwd = Get_Pwnam(username);
+
+ if (pwd) {
+ if (!NT_STATUS_IS_OK(nt_status = pdb_init_sam_pw(new_sam_acct, pwd))) {
+ *new_sam_acct = NULL;
+ return nt_status;
+ }
+ } else {
+ if (!NT_STATUS_IS_OK(nt_status = pdb_init_sam(new_sam_acct))) {
+ *new_sam_acct = NULL;
+ return nt_status;
+ }
+ if (!pdb_set_username(*new_sam_acct, username, PDB_SET)) {
+ pdb_free_sam(new_sam_acct);
+ return nt_status;
+ }
+ }
+ return NT_STATUS_OK;
+}
+
+
/**
* Free the contets of the SAM_ACCOUNT, but not the structure.
*
@@ -1001,7 +1033,6 @@ BOOL local_password_change(const char *user_name, int local_flags,
char *err_str, size_t err_str_len,
char *msg_str, size_t msg_str_len)
{
- struct passwd *pwd = NULL;
SAM_ACCOUNT *sam_pass=NULL;
uint16 other_acb;
@@ -1013,35 +1044,15 @@ BOOL local_password_change(const char *user_name, int local_flags,
if(!pdb_getsampwnam(sam_pass, user_name)) {
pdb_free_sam(&sam_pass);
- if (local_flags & LOCAL_ADD_USER) {
- pwd = getpwnam_alloc(user_name);
- } else if (local_flags & LOCAL_DELETE_USER) {
+ if ((local_flags & LOCAL_ADD_USER) || (local_flags & LOCAL_DELETE_USER)) {
/* Might not exist in /etc/passwd */
- } else {
- slprintf(err_str, err_str_len-1,"Failed to find entry for user %s.\n", user_name);
- return False;
- }
-
- if (pwd) {
- /* Local user found, so init from this */
- if (!NT_STATUS_IS_OK(pdb_init_sam_pw(&sam_pass, pwd))){
+ if (!NT_STATUS_IS_OK(pdb_init_sam_new(&sam_pass, user_name))) {
slprintf(err_str, err_str_len-1, "Failed initialise SAM_ACCOUNT for user %s.\n", user_name);
- passwd_free(&pwd);
return False;
}
-
- passwd_free(&pwd);
} else {
- if (!NT_STATUS_IS_OK(pdb_init_sam(&sam_pass))){
- slprintf(err_str, err_str_len-1, "Failed initialise SAM_ACCOUNT for user %s.\n", user_name);
- return False;
- }
-
- if (!pdb_set_username(sam_pass, user_name, PDB_CHANGED)) {
- slprintf(err_str, err_str_len - 1, "Failed to set username for user %s.\n", user_name);
- pdb_free_sam(&sam_pass);
- return False;
- }
+ slprintf(err_str, err_str_len-1,"Failed to find entry for user %s.\n", user_name);
+ return False;
}
} else {
/* the entry already existed */