netlogon_creds_cli: Simplify netlogon_creds_cli_context_common
authorVolker Lendecke <vl@samba.org>
Mon, 21 Aug 2017 09:34:45 +0000 (11:34 +0200)
committerAndrew Bartlett <abartlet@samba.org>
Sat, 16 Sep 2017 06:36:17 +0000 (08:36 +0200)
printf knows to only print part of a string. No need to talloc_strdup.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
libcli/auth/netlogon_creds_cli.c

index 751c09f4bdd4ebe578e8c09d2844c7bb93a42f40..b85a7e03b601f9f65594b4930402f6ac5904c088 100644 (file)
@@ -113,7 +113,7 @@ static NTSTATUS netlogon_creds_cli_context_common(
        struct netlogon_creds_cli_context *context = NULL;
        TALLOC_CTX *frame = talloc_stackframe();
        char *_key_name = NULL;
-       char *server_netbios_name = NULL;
+       size_t server_netbios_name_len;
        char *p = NULL;
 
        *_context = NULL;
@@ -172,22 +172,19 @@ static NTSTATUS netlogon_creds_cli_context_common(
         * For now we have to deal with
         * "HOSTNAME" vs. "hostname.example.com".
         */
-       server_netbios_name = talloc_strdup(frame, server_computer);
-       if (server_netbios_name == NULL) {
-               TALLOC_FREE(context);
-               TALLOC_FREE(frame);
-               return NT_STATUS_NO_MEMORY;
-       }
 
-       p = strchr(server_netbios_name, '.');
+       p = strchr(server_computer, '.');
        if (p != NULL) {
-               p[0] = '\0';
+               server_netbios_name_len = p-server_computer;
+       } else {
+               server_netbios_name_len = strlen(server_computer);
        }
 
-       _key_name = talloc_asprintf(frame, "CLI[%s/%s]/SRV[%s/%s]",
+       _key_name = talloc_asprintf(frame, "CLI[%s/%s]/SRV[%.*s/%s]",
                                    client_computer,
                                    client_account,
-                                   server_netbios_name,
+                                   (int)server_netbios_name_len,
+                                   server_computer,
                                    server_netbios_domain);
        if (_key_name == NULL) {
                TALLOC_FREE(context);