use lp_realm() to find the default realm for 'net ads password'
authorAndrew Tridgell <tridge@samba.org>
Tue, 10 Jun 2003 04:15:55 +0000 (04:15 +0000)
committerAndrew Tridgell <tridge@samba.org>
Tue, 10 Jun 2003 04:15:55 +0000 (04:15 +0000)
source/utils/net_ads.c

index 5051f1818810ec998d2a92b1e07e9b8a3166f350..9a824e2662f312789a58e77a4356cabb24d17a01 100644 (file)
@@ -899,20 +899,34 @@ static int net_ads_password(int argc, const char **argv)
     const char *auth_password = opt_password;
     char *realm = NULL;
     char *new_password = NULL;
-    char *c;
-    char *prompt;
+    char *c, *prompt;
+    const char *user;
     ADS_STATUS ret;
 
+    if (opt_user_name == NULL || opt_password == NULL) {
+           d_printf("You must supply an administrator username/password\n");
+           return -1;
+    }
+
     
-    if ((argc != 1) || (opt_user_name == NULL) || 
-       (opt_password == NULL) || (strchr(opt_user_name, '@') == NULL) ||
-       (strchr(argv[0], '@') == NULL)) {
-       return net_ads_usage(argc, argv);
+    if (argc != 1) {
+           d_printf("ERROR: You must say which username to change password for\n");
+           return -1;
+    }
+
+    user = argv[0];
+    if (!strchr(user, '@')) {
+           asprintf(&c, "%s@%s", argv[0], lp_realm());
+           user = c;
     }
 
     use_in_memory_ccache();    
     c = strchr(auth_principal, '@');
-    realm = ++c;
+    if (c) {
+           realm = ++c;
+    } else {
+           realm = lp_realm();
+    }
 
     /* use the realm so we can eventually change passwords for users 
     in realms other than default */
@@ -927,12 +941,12 @@ static int net_ads_password(int argc, const char **argv)
            return -1;
     }
 
-    asprintf(&prompt, "Enter new password for %s:", argv[0]);
+    asprintf(&prompt, "Enter new password for %s:", user);
 
     new_password = getpass(prompt);
 
     ret = kerberos_set_password(ads->auth.kdc_server, auth_principal, 
-                               auth_password, argv[0], new_password, ads->auth.time_offset);
+                               auth_password, user, new_password, ads->auth.time_offset);
     if (!ADS_ERR_OK(ret)) {
        d_printf("Password change failed :-( ...\n");
        ads_destroy(&ads);
@@ -940,7 +954,7 @@ static int net_ads_password(int argc, const char **argv)
        return -1;
     }
 
-    d_printf("Password change for %s completed.\n", argv[0]);
+    d_printf("Password change for %s completed.\n", user);
     ads_destroy(&ads);
     free(prompt);