s3-lib: Do not create 'MACHINE$@' usernames
authorAndreas Schneider <asn@samba.org>
Thu, 15 Sep 2016 10:54:42 +0000 (12:54 +0200)
committerStefan Metzmacher <metze@samba.org>
Sun, 25 Sep 2016 07:05:27 +0000 (09:05 +0200)
If there is no realm set we should not add it to the machine account.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/lib/util_cmdline.c

index 80c3ecdb4622e744aff18316a978cdf3b5ef2f95..d2381f03732fa1d3d72392f31948c29a7ac71d51 100644 (file)
@@ -207,6 +207,9 @@ bool set_cmdline_auth_info_machine_account_creds(struct user_auth_info *auth_inf
 {
        char *pass = NULL;
        char *account = NULL;
+       const char *realm = lp_realm();
+       int rc;
+
 
        if (!get_cmdline_auth_info_use_machine_account(auth_info)) {
                return false;
@@ -217,8 +220,21 @@ bool set_cmdline_auth_info_machine_account_creds(struct user_auth_info *auth_inf
                return false;
        }
 
-       if (asprintf(&account, "%s$@%s", lp_netbios_name(), lp_realm()) < 0) {
-               return false;
+       if (realm != NULL && realm[0] != '\0') {
+               rc = asprintf(&account,
+                             "%s$@%s",
+                             lp_netbios_name(),
+                             realm);
+               if (rc < 0) {
+                       return false;
+               }
+       } else {
+               rc = asprintf(&account,
+                             "%s$",
+                             lp_netbios_name());
+               if (rc < 0) {
+                       return false;
+               }
        }
 
        pass = secrets_fetch_machine_password(lp_workgroup(), NULL, NULL);