r23779: Change from v2 or later to v3 or later.
[amitay/samba.git] / source3 / utils / smbpasswd.c
index d66001e441b2d583d40b148e63c222b3ae3728a2..1c8b503b4d68522a6f35c93647e58c2463ffa030 100644 (file)
@@ -5,7 +5,7 @@
  * 
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
+ * Free Software Foundation; either version 3 of the License, or (at your
  * option) any later version.
  * 
  * This program is distributed in the hope that it will be useful, but WITHOUT
@@ -64,6 +64,7 @@ static void usage(void)
        printf("  -i                   interdomain trust account\n");
        printf("  -m                   machine trust account\n");
        printf("  -n                   set no password\n");
+       printf("  -W                   use stdin ldap admin password\n");
        printf("  -w PASSWORD          ldap admin password\n");
        printf("  -x                   delete user\n");
        printf("  -R ORDER             name resolve order\n");
@@ -189,7 +190,7 @@ static int process_options(int argc, char **argv, int local_flags)
 
        if (!lp_load(configfile,True,False,False,True)) {
                fprintf(stderr, "Can't load %s - run testparm to debug it\n", 
-                       dyn_CONFIGFILE);
+                       configfile);
                exit(1);
        }
 
@@ -304,7 +305,7 @@ static int process_root(int local_flags)
        }
 
        /* Ensure passdb startup(). */
-       if(!initialize_password_db(False)) {
+       if(!initialize_password_db(False, NULL)) {
                DEBUG(0, ("Failed to open passdb!\n"));
                exit(1);
        }
@@ -402,12 +403,19 @@ static int process_root(int local_flags)
                        
                        if(local_flags & LOCAL_ENABLE_USER) {
                                struct samu *sampass = NULL;
-                               BOOL ret;
                                
                                sampass = samu_new( NULL );
-                               ret = pdb_getsampwnam(sampass, user_name);
-                               if((ret) &&
-                                  (pdb_get_lanman_passwd(sampass) == NULL)) {
+                               if (!sampass) {
+                                       fprintf(stderr, "talloc fail for struct samu.\n");
+                                       exit(1);
+                               }
+                               if (!pdb_getsampwnam(sampass, user_name)) {
+                                       fprintf(stderr, "Failed to find user %s in passdb backend.\n",
+                                               user_name );
+                                       exit(1);
+                               }
+
+                               if(pdb_get_nt_passwd(sampass) == NULL) {
                                        local_flags |= LOCAL_SET_PASSWORD;
                                }
                                TALLOC_FREE(sampass);
@@ -436,16 +444,26 @@ static int process_root(int local_flags)
                printf("Password changed for user %s on %s.\n", user_name, remote_machine );
        } else if(!(local_flags & (LOCAL_ADD_USER|LOCAL_DISABLE_USER|LOCAL_ENABLE_USER|LOCAL_DELETE_USER|LOCAL_SET_NO_PASSWORD|LOCAL_SET_PASSWORD))) {
                struct samu *sampass = NULL;
-               BOOL ret;
                
                sampass = samu_new( NULL );
-               ret = pdb_getsampwnam(sampass, user_name);
+               if (!sampass) {
+                       fprintf(stderr, "talloc fail for struct samu.\n");
+                       exit(1);
+               }
+
+               if (!pdb_getsampwnam(sampass, user_name)) {
+                       fprintf(stderr, "Failed to find user %s in passdb backend.\n",
+                               user_name );
+                       exit(1);
+               }
 
                printf("Password changed for user %s.", user_name );
-               if( (ret != False) && (pdb_get_acct_ctrl(sampass)&ACB_DISABLED) )
+               if(pdb_get_acct_ctrl(sampass)&ACB_DISABLED) {
                        printf(" User has disabled flag set.");
-               if((ret != False) && (pdb_get_acct_ctrl(sampass) & ACB_PWNOTREQ) )
+               }
+               if(pdb_get_acct_ctrl(sampass) & ACB_PWNOTREQ) {
                        printf(" User has no password flag set.");
+               }
                printf("\n");
                TALLOC_FREE(sampass);
        }