Change the passdb interface to use allocated strings.
[ira/wip.git] / source3 / utils / pdbedit.c
index ce241934a1187e01bdb90e6ff70315746703f878..ae600f6a6a7f2b5bc2b819c4b8e635ca9b5d272f 100644 (file)
@@ -32,6 +32,7 @@
 #include "includes.h"
 
 extern pstring global_myname;
+extern BOOL AllowDebugChange;
 
 /*
  * Next two lines needed for SunOS and don't
@@ -82,21 +83,24 @@ static int print_sam_info (SAM_ACCOUNT *sam_pwent, BOOL verbosity, BOOL smbpwdst
        
        if (verbosity) {
                printf ("username:       %s\n",  pdb_get_username(sam_pwent));
-               if ((uid = pdb_get_uid(sam_pwent)) && (gid = pdb_get_gid(sam_pwent))) {
-                       printf ("user ID/Group:  %d/%d\n", (unsigned int)uid,
-                               (unsigned int)gid);
+               if (IS_SAM_UNIX_USER(sam_pwent)) {
+                       uid = pdb_get_uid(sam_pwent);
+                       gid = pdb_get_gid(sam_pwent);
+                       printf ("user ID/Group:  %d/%d\n", uid, gid);
                }
-               printf ("user RID/GRID:  %u/%u\n", (unsigned int)sam_pwent->user_rid,
-                       (unsigned int)sam_pwent->group_rid);
+               printf ("user RID/GRID:  %u/%u\n", (unsigned int)pdb_get_user_rid(sam_pwent),
+                       (unsigned int)pdb_get_group_rid(sam_pwent));
                printf ("Full Name:      %s\n", pdb_get_fullname(sam_pwent));
                printf ("Home Directory: %s\n", pdb_get_homedir(sam_pwent));
                printf ("HomeDir Drive:  %s\n", pdb_get_dirdrive(sam_pwent));
                printf ("Logon Script:   %s\n", pdb_get_logon_script(sam_pwent));
                printf ("Profile Path:   %s\n", pdb_get_profile_path(sam_pwent));
        } else if (smbpwdstyle) {
-               if ((uid = pdb_get_uid(sam_pwent))) {
+               if (IS_SAM_UNIX_USER(sam_pwent)) {
                        char lm_passwd[33];
                        char nt_passwd[33];
+
+                       uid = pdb_get_uid(sam_pwent);
                        pdb_sethexpwd(lm_passwd, 
                                      pdb_get_lanman_passwd(sam_pwent), 
                                      pdb_get_acct_ctrl(sam_pwent));
@@ -106,7 +110,7 @@ static int print_sam_info (SAM_ACCOUNT *sam_pwent, BOOL verbosity, BOOL smbpwdst
                        
                        printf("%s:%d:%s:%s:%s:LCT-%08X:\n",
                               pdb_get_username(sam_pwent),
-                              (unsigned int)uid,
+                              uid,
                               lm_passwd,
                               nt_passwd,
                               pdb_encode_acct_ctrl(pdb_get_acct_ctrl(sam_pwent),NEW_PW_FORMAT_SPACE_PADDED_LEN),
@@ -115,8 +119,9 @@ static int print_sam_info (SAM_ACCOUNT *sam_pwent, BOOL verbosity, BOOL smbpwdst
                        fprintf(stderr, "Can't output in smbpasswd format, no uid on this record.\n");
                }
        } else {
-               if ((uid = pdb_get_uid(sam_pwent))) {           
-                       printf ("%s:%d:%s\n", pdb_get_username(sam_pwent), uid, pdb_get_fullname(sam_pwent));
+               if (IS_SAM_UNIX_USER(sam_pwent)) {
+                       printf ("%s:%d:%s\n", pdb_get_username(sam_pwent), pdb_get_uid(sam_pwent), 
+                               pdb_get_fullname(sam_pwent));
                } else {        
                        printf ("%s:(null):%s\n", pdb_get_username(sam_pwent), pdb_get_fullname(sam_pwent));
                }
@@ -200,13 +205,13 @@ static int set_user_info (char *username, char *fullname, char *homedir, char *d
        if (fullname)
                pdb_set_fullname(sam_pwent, fullname);
        if (homedir)
-               pdb_set_homedir(sam_pwent, homedir);
+               pdb_set_homedir(sam_pwent, homedir, True);
        if (drive)
-               pdb_set_dir_drive(sam_pwent,drive);
+               pdb_set_dir_drive(sam_pwent,drive, True);
        if (script)
-               pdb_set_logon_script(sam_pwent, script);
+               pdb_set_logon_script(sam_pwent, script, True);
        if (profile)
-               pdb_set_profile_path (sam_pwent, profile);
+               pdb_set_profile_path (sam_pwent, profile, True);
        
        if (pdb_update_sam_account (sam_pwent, True))
                print_user_info (username, True, False);
@@ -251,13 +256,13 @@ static int new_user (char *username, char *fullname, char *homedir, char *drive,
        if (fullname)
                pdb_set_fullname(sam_pwent, fullname);
        if (homedir)
-               pdb_set_homedir (sam_pwent, homedir);
+               pdb_set_homedir (sam_pwent, homedir, True);
        if (drive)
-               pdb_set_dir_drive (sam_pwent, drive);
+               pdb_set_dir_drive (sam_pwent, drive, True);
        if (script)
-               pdb_set_logon_script(sam_pwent, script);
+               pdb_set_logon_script(sam_pwent, script, True);
        if (profile)
-               pdb_set_profile_path (sam_pwent, profile);
+               pdb_set_profile_path (sam_pwent, profile, True);
        
        pdb_set_acct_ctrl (sam_pwent, ACB_NORMAL);
        
@@ -438,7 +443,7 @@ account without a valid local system user.\n", user_name);
                        return False;
                }
 
-               if (!pdb_init_sam_pw(&sam_pwent, pwd)) {
+               if (!NT_STATUS_IS_OK(pdb_init_sam_pw(&sam_pwent, pwd))) {
                        fprintf(stderr, "Failed initialise SAM_ACCOUNT for user %s.\n", user_name);
                        return False;
                }
@@ -564,6 +569,9 @@ int main (int argc, char **argv)
                exit(1);
        }
        
+       DEBUGLEVEL = 1;
+       AllowDebugChange = False;
+
        if (!lp_load(dyn_CONFIGFILE,True,False,False)) {
                fprintf(stderr, "Can't load %s - run testparm to debug it\n", 
                        dyn_CONFIGFILE);