s3-passdb: add smb_create_user().
authorGünther Deschner <gd@samba.org>
Wed, 1 Apr 2009 16:52:13 +0000 (18:52 +0200)
committerGünther Deschner <gd@samba.org>
Wed, 1 Apr 2009 17:12:19 +0000 (19:12 +0200)
Guenther

source3/include/proto.h
source3/passdb/passdb.c

index 2e76764e018532617c5c9b0861d840ce837ffcda..0a2a8de4a93c64ded34e94877e39a2abd57accb0 100644 (file)
@@ -4465,6 +4465,10 @@ bool get_trust_pw_hash(const char *domain, uint8 ret_pwd[16],
                       const char **account_name, uint32 *channel);
 struct samr_LogonHours get_logon_hours_from_pdb(TALLOC_CTX *mem_ctx,
                                                struct samu *pw);
+NTSTATUS smb_create_user(TALLOC_CTX *mem_ctx,
+                        uint32_t acct_flags,
+                        const char *account,
+                        struct passwd **passwd_p);
 
 /* The following definitions come from passdb/pdb_compat.c  */
 
index 95e5deb36f1a63c0d013a08a23743b90a51af5c4..fd715d201f91d7f655a18bac8bc296153cea3199 100644 (file)
@@ -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;
+}