summaryrefslogtreecommitdiffstats
path: root/source3/passdb/pdb_smbpasswd.c
diff options
context:
space:
mode:
authorJim McDonough <jmcd@samba.org>2005-10-20 20:40:47 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 11:05:08 -0500
commit1113cad9c0c81e9ecec3a0f4317c950943cfc62a (patch)
treefdafa600529a6bcc43cf283007630d8cd51b1151 /source3/passdb/pdb_smbpasswd.c
parent6fc9098dcc1a1ef232b96f5d4c562bf340db8988 (diff)
downloadsamba-1113cad9c0c81e9ecec3a0f4317c950943cfc62a.tar.gz
samba-1113cad9c0c81e9ecec3a0f4317c950943cfc62a.tar.xz
samba-1113cad9c0c81e9ecec3a0f4317c950943cfc62a.zip
r11236: Implement user rename for smbpasswd and ldap backends. Some cleanup on
tdb as well to make naming consistent. (This used to be commit ee91eb9a39cc5e3edd9e97eb040e7557930e4e62)
Diffstat (limited to 'source3/passdb/pdb_smbpasswd.c')
-rw-r--r--source3/passdb/pdb_smbpasswd.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/source3/passdb/pdb_smbpasswd.c b/source3/passdb/pdb_smbpasswd.c
index 6eb4305409..5fca706a83 100644
--- a/source3/passdb/pdb_smbpasswd.c
+++ b/source3/passdb/pdb_smbpasswd.c
@@ -1477,6 +1477,62 @@ static NTSTATUS smbpasswd_delete_sam_account (struct pdb_methods *my_methods, SA
return NT_STATUS_UNSUCCESSFUL;
}
+static NTSTATUS smbpasswd_rename_sam_account (struct pdb_methods *my_methods,
+ SAM_ACCOUNT *old_acct,
+ const char *newname)
+{
+ struct smbpasswd_privates *smbpasswd_state = (struct smbpasswd_privates*)my_methods->private_data;
+ pstring rename_script;
+ SAM_ACCOUNT *new_acct = NULL;
+ BOOL interim_account = False;
+ NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
+
+ if (!*(lp_renameuser_script()))
+ goto done;
+
+ if (!pdb_copy_sam_account(old_acct, &new_acct) ||
+ !pdb_set_username(new_acct, newname, PDB_CHANGED))
+ goto done;
+
+ ret = smbpasswd_add_sam_account(my_methods, new_acct);
+ if (!NT_STATUS_IS_OK(ret))
+ goto done;
+
+ interim_account = True;
+
+ /* rename the posix user */
+ pstrcpy(rename_script, lp_renameuser_script());
+
+ if (*rename_script) {
+ int rename_ret;
+
+ pstring_sub(rename_script, "%unew", newname);
+ pstring_sub(rename_script, "%uold",
+ pdb_get_username(old_acct));
+ rename_ret = smbrun(rename_script, NULL);
+
+ DEBUG(rename_ret ? 0 : 3,("Running the command `%s' gave %d\n", rename_script, rename_ret));
+
+ if (rename_ret)
+ goto done;
+ } else {
+ goto done;
+ }
+
+ smbpasswd_delete_sam_account(my_methods, old_acct);
+ interim_account = False;
+
+done:
+ /* cleanup */
+ if (interim_account)
+ smbpasswd_delete_sam_account(my_methods, new_acct);
+
+ if (new_acct)
+ pdb_free_sam(&new_acct);
+
+ return (ret);
+}
+
static void free_private_data(void **vp)
{
struct smbpasswd_privates **privates = (struct smbpasswd_privates**)vp;
@@ -1506,6 +1562,7 @@ static NTSTATUS pdb_init_smbpasswd(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_m
(*pdb_method)->add_sam_account = smbpasswd_add_sam_account;
(*pdb_method)->update_sam_account = smbpasswd_update_sam_account;
(*pdb_method)->delete_sam_account = smbpasswd_delete_sam_account;
+ (*pdb_method)->rename_sam_account = smbpasswd_rename_sam_account;
/* Setup private data and free function */