diff options
author | Andrew Tridgell <tridge@samba.org> | 2009-04-02 10:17:32 +1100 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2009-04-02 10:17:32 +1100 |
commit | 1bc9c3923574d548810733b512716d5758814328 (patch) | |
tree | aa128b82d3232a8c73de316aa5a7b8bd0caa9766 /source3/passdb | |
parent | 2fe17ae61e4f80b7c864bd6777c71557c97c0125 (diff) | |
parent | 36c1a52a57bc96c7586ca1bffbe8ef47c93bca1b (diff) | |
download | samba-1bc9c3923574d548810733b512716d5758814328.tar.gz samba-1bc9c3923574d548810733b512716d5758814328.tar.bz2 samba-1bc9c3923574d548810733b512716d5758814328.zip |
Merge commit 'master/master' into wspp-schema
Diffstat (limited to 'source3/passdb')
-rw-r--r-- | source3/passdb/passdb.c | 59 | ||||
-rw-r--r-- | source3/passdb/pdb_tdb.c | 18 |
2 files changed, 75 insertions, 2 deletions
diff --git a/source3/passdb/passdb.c b/source3/passdb/passdb.c index 95e5deb36f..fd715d201f 100644 --- a/source3/passdb/passdb.c +++ b/source3/passdb/passdb.c @@ -2348,3 +2348,62 @@ struct samr_LogonHours get_logon_hours_from_pdb(TALLOC_CTX *mem_ctx, return hours; } +/**************************************************************** +****************************************************************/ + +NTSTATUS smb_create_user(TALLOC_CTX *mem_ctx, + uint32_t acct_flags, + const char *account, + struct passwd **passwd_p) +{ + struct passwd *passwd; + char *add_script = NULL; + + passwd = Get_Pwnam_alloc(mem_ctx, account); + if (passwd) { + *passwd_p = passwd; + return NT_STATUS_OK; + } + + /* Create appropriate user */ + if (acct_flags & ACB_NORMAL) { + add_script = talloc_strdup(mem_ctx, lp_adduser_script()); + } else if ( (acct_flags & ACB_WSTRUST) || + (acct_flags & ACB_SVRTRUST) || + (acct_flags & ACB_DOMTRUST) ) { + add_script = talloc_strdup(mem_ctx, lp_addmachine_script()); + } else { + DEBUG(1, ("Unknown user type: %s\n", + pdb_encode_acct_ctrl(acct_flags, NEW_PW_FORMAT_SPACE_PADDED_LEN))); + return NT_STATUS_UNSUCCESSFUL; + } + + if (!add_script) { + return NT_STATUS_NO_MEMORY; + } + + if (*add_script) { + int add_ret; + add_script = talloc_all_string_sub(mem_ctx, add_script, + "%u", account); + if (!add_script) { + return NT_STATUS_NO_MEMORY; + } + add_ret = smbrun(add_script, NULL); + DEBUG(add_ret ? 0 : 1,("fetch_account: Running the command `%s' " + "gave %d\n", add_script, add_ret)); + if (add_ret == 0) { + smb_nscd_flush_user_cache(); + } + } + + /* try and find the possible unix account again */ + passwd = Get_Pwnam_alloc(mem_ctx, account); + if (!passwd) { + return NT_STATUS_NO_SUCH_USER; + } + + *passwd_p = passwd; + + return NT_STATUS_OK; +} diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 1060733df4..6c49eb1dc2 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -250,6 +250,11 @@ static bool tdbsam_convert_backup(const char *dbname, struct db_context **pp_db) smb_panic("tdbsam_convert_backup: orig commit failed\n"); } + /* be sure to close the DBs _before_ renaming the file */ + + TALLOC_FREE(orig_db); + TALLOC_FREE(tmp_db); + /* This is safe from other users as we know we're * under a mutex here. */ @@ -262,13 +267,22 @@ static bool tdbsam_convert_backup(const char *dbname, struct db_context **pp_db) } TALLOC_FREE(frame); - TALLOC_FREE(orig_db); + + /* re-open the converted TDB */ + + orig_db = db_open(NULL, dbname, 0, + TDB_DEFAULT, O_CREAT|O_RDWR, 0600); + if (orig_db == NULL) { + DEBUG(0, ("tdbsam_convert_backup: Failed to re-open " + "converted passdb TDB [%s]\n", dbname)); + return false; + } DEBUG(1, ("tdbsam_convert_backup: updated %s file.\n", dbname )); /* Replace the global db pointer. */ - *pp_db = tmp_db; + *pp_db = orig_db; return true; cancel: |