Replace get_myname() with the talloc version from v3-3-test
authorVolker Lendecke <vl@samba.org>
Fri, 13 Feb 2009 09:56:34 +0000 (10:56 +0100)
committerVolker Lendecke <vl@samba.org>
Fri, 13 Feb 2009 11:15:03 +0000 (12:15 +0100)
lib/util/util.c
lib/util/util.h
source3/client/smbspool.c
source3/include/proto.h
source3/lib/util.c
source3/nmbd/nmbd_processlogon.c
source3/rpc_client/cli_pipe.c
source3/torture/torture.c
source4/client/smbspool.c
source4/param/loadparm.c

index 40ac7f79e69578a43cf24fb3a275172c8663f12c..988d8f9fa02a479d05fc81a72af3905c3c35e12b 100644 (file)
@@ -192,34 +192,30 @@ _PUBLIC_ void msleep(unsigned int t)
 }
 
 /**
- Get my own name, return in malloc'ed storage.
+ Get my own name, return in talloc'ed storage.
 **/
 
-_PUBLIC_ char *get_myname(void)
+_PUBLIC_ char *get_myname(TALLOC_CTX *ctx)
 {
-       char *hostname;
        char *p;
-
-       hostname = (char *)malloc(MAXHOSTNAMELEN+1);
-       *hostname = 0;
+       char hostname[HOST_NAME_MAX];
 
        /* get my host name */
-       if (gethostname(hostname, MAXHOSTNAMELEN+1) == -1) {
+       if (gethostname(hostname, sizeof(hostname)) == -1) {
                DEBUG(0,("gethostname failed\n"));
-               free(hostname);
                return NULL;
-       } 
+       }
 
        /* Ensure null termination. */
-       hostname[MAXHOSTNAMELEN] = '\0';
+       hostname[sizeof(hostname)-1] = '\0';
 
        /* split off any parts after an initial . */
-       p = strchr(hostname, '.');
-
-       if (p != NULL)
+       p = strchr_m(hostname, '.');
+       if (p) {
                *p = 0;
-       
-       return hostname;
+       }
+
+       return talloc_strdup(ctx, hostname);
 }
 
 /**
index dced557acbe32594d282d1a87248d4ae2598a6e5..7873f0e769f34c407e834636d80caff38362755d 100644 (file)
@@ -536,9 +536,9 @@ _PUBLIC_ int set_blocking(int fd, bool set);
 _PUBLIC_ void msleep(unsigned int t);
 
 /**
- Get my own name, return in malloc'ed storage.
+ Get my own name, return in talloc'ed storage.
 **/
-_PUBLIC_ char* get_myname(void);
+_PUBLIC_ char* get_myname(TALLOC_CTX *mem_ctx);
 
 /**
  Return true if a string could be a pure IP address.
index 7943cf582822fc5f9fdb01900938eb014d2062bd..a276353a87f39a28cc532e5c04d68c52ef17b3fc 100644 (file)
@@ -485,7 +485,7 @@ smb_connect(const char *workgroup,  /* I - Workgroup */
        /*
          * Get the names and addresses of the client and server...
          */
-       myname = talloc_get_myname(talloc_tos());
+       myname = get_myname(talloc_tos());
        if (!myname) {
                return NULL;
        }
index 7ad063ef4766bc38373509c2cdd49bd7e78800d0..34104727e99f1cba2c3a7ede4b4c8fe901981e93 100644 (file)
@@ -1154,7 +1154,7 @@ void *Realloc(void *p, size_t size, bool free_old_on_error);
 void add_to_large_array(TALLOC_CTX *mem_ctx, size_t element_size,
                        void *element, void *_array, uint32 *num_elements,
                        ssize_t *array_size);
-char *talloc_get_myname(TALLOC_CTX *ctx);
+char *get_myname(TALLOC_CTX *ctx);
 char *get_mydnsdomname(TALLOC_CTX *ctx);
 int interpret_protocol(const char *str,int def);
 char *automount_lookup(TALLOC_CTX *ctx, const char *user_name);
index 68d332243610d5308c4c314a66c1350797383ebb..6079e710633bdce131bf1c1c58fda13aa203958e 100644 (file)
@@ -1208,35 +1208,6 @@ void add_to_large_array(TALLOC_CTX *mem_ctx, size_t element_size,
        *array_size = -1;
 }
 
-/****************************************************************************
- Get my own name and IP.
-****************************************************************************/
-
-char *talloc_get_myname(TALLOC_CTX *ctx)
-{
-       char *p;
-       char hostname[HOST_NAME_MAX];
-
-       *hostname = 0;
-
-       /* get my host name */
-       if (gethostname(hostname, sizeof(hostname)) == -1) {
-               DEBUG(0,("gethostname failed\n"));
-               return False;
-       }
-
-       /* Ensure null termination. */
-       hostname[sizeof(hostname)-1] = '\0';
-
-       /* split off any parts after an initial . */
-       p = strchr_m(hostname,'.');
-       if (p) {
-               *p = 0;
-       }
-
-       return talloc_strdup(ctx, hostname);
-}
-
 /****************************************************************************
  Get my own domain name, or "" if we have none.
 ****************************************************************************/
@@ -2237,7 +2208,7 @@ char *myhostname(void)
        if (ret == NULL) {
                /* This is cached forever so
                 * use talloc_autofree_context() ctx. */
-               ret = talloc_get_myname(talloc_autofree_context());
+               ret = get_myname(talloc_autofree_context());
        }
        return ret;
 }
index a4ef528133b8b19293b3010e5d37bb13155f8852..59a2ca405eab7e736c839db495f4946f64628085 100644 (file)
@@ -442,7 +442,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n",
                                                ("get_mydnsdomname failed.\n"));
                                                return;
                                        }
-                                       hostname = talloc_get_myname(talloc_tos());
+                                       hostname = get_myname(talloc_tos());
                                        if (!hostname) {
                                                DEBUG(2,
                                                ("get_myname failed.\n"));
index 2841ff08f61ae62e6a2aa5d4b06e636c0a076052..24dbcb01931e9e0125e5e4b22e9d1119e37cd0b9 100644 (file)
@@ -3417,7 +3417,7 @@ NTSTATUS rpc_pipe_open_ncalrpc(TALLOC_CTX *mem_ctx, const char *socket_path,
        result->transfer_syntax = ndr_transfer_syntax;
        result->dispatch = cli_do_rpc_ndr;
 
-       result->desthost = talloc_get_myname(result);
+       result->desthost = get_myname(result);
        result->srv_name_slash = talloc_asprintf_strupper_m(
                result, "\\\\%s", result->desthost);
        if ((result->desthost == NULL) || (result->srv_name_slash == NULL)) {
index 9cf41d88c7c5214f2433cdd4d197c0596d425c6b..db89b05603aea293f5c6a079b6b28599eed4ec9f 100644 (file)
@@ -5862,7 +5862,7 @@ static void usage(void)
        *p = 0;
        fstrcpy(share, p+1);
 
-       fstrcpy(myname, talloc_get_myname(talloc_tos()));
+       fstrcpy(myname, get_myname(talloc_tos()));
        if (!*myname) {
                fprintf(stderr, "Failed to get my hostname.\n");
                return 1;
index df867d5fefcff7741ff2b2a63ebcc0f99b79f57e..cfba5992d3c847ca41393e643484e9a1f7d48aa4 100644 (file)
@@ -268,12 +268,12 @@ smb_connect(const char *workgroup,                /* I - Workgroup */
   * Get the names and addresses of the client and server...
   */
 
-  myname = get_myname();  
+  myname = get_myname(NULL);
        
   nt_status = smbcli_full_connection(NULL, &c, myname, server, ports, share, 
                                     NULL, username, workgroup, password, NULL);
   
-  free(myname);
+  talloc_free(myname);
   if (!NT_STATUS_IS_OK(nt_status)) {
          fprintf(stderr, "ERROR:  Connection failed with error %s\n", nt_errstr(nt_status));
          return NULL;
index 0cd92c16f1ea2dbc89496a3d8aa4fa32f0b9db82..6789aa1ac29302fae75c5f46b9dd7f6dec2efc2c 100644 (file)
@@ -2286,9 +2286,9 @@ struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
        lp_do_global_parameter(lp_ctx, "socket options", "TCP_NODELAY");
 #endif
        lp_do_global_parameter(lp_ctx, "workgroup", DEFAULT_WORKGROUP);
-       myname = get_myname();
+       myname = get_myname(lp_ctx);
        lp_do_global_parameter(lp_ctx, "netbios name", myname);
-       SAFE_FREE(myname);
+       talloc_free(myname);
        lp_do_global_parameter(lp_ctx, "name resolve order", "wins host bcast");
 
        lp_do_global_parameter(lp_ctx, "fstype", "NTFS");