summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2009-02-13 10:56:34 +0100
committerVolker Lendecke <vl@samba.org>2009-02-13 12:15:03 +0100
commit0844cca1d5e4579b54af7d03509f3f97fac43bdc (patch)
tree48e92ab9ebeb54a485394849e3bcc2b0aca7734a
parente7f7ed8bf6281ef01aca53ea44acdd4af4c51aa7 (diff)
downloadsamba-0844cca1d5e4579b54af7d03509f3f97fac43bdc.tar.gz
samba-0844cca1d5e4579b54af7d03509f3f97fac43bdc.tar.xz
samba-0844cca1d5e4579b54af7d03509f3f97fac43bdc.zip
Replace get_myname() with the talloc version from v3-3-test
-rw-r--r--lib/util/util.c26
-rw-r--r--lib/util/util.h4
-rw-r--r--source3/client/smbspool.c2
-rw-r--r--source3/include/proto.h2
-rw-r--r--source3/lib/util.c31
-rw-r--r--source3/nmbd/nmbd_processlogon.c2
-rw-r--r--source3/rpc_client/cli_pipe.c2
-rw-r--r--source3/torture/torture.c2
-rw-r--r--source4/client/smbspool.c4
-rw-r--r--source4/param/loadparm.c4
10 files changed, 23 insertions, 56 deletions
diff --git a/lib/util/util.c b/lib/util/util.c
index 40ac7f79e69..988d8f9fa02 100644
--- a/lib/util/util.c
+++ b/lib/util/util.c
@@ -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);
}
/**
diff --git a/lib/util/util.h b/lib/util/util.h
index dced557acbe..7873f0e769f 100644
--- a/lib/util/util.h
+++ b/lib/util/util.h
@@ -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.
diff --git a/source3/client/smbspool.c b/source3/client/smbspool.c
index 7943cf58282..a276353a87f 100644
--- a/source3/client/smbspool.c
+++ b/source3/client/smbspool.c
@@ -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;
}
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 7ad063ef476..34104727e99 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -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);
diff --git a/source3/lib/util.c b/source3/lib/util.c
index 68d33224361..6079e710633 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -1209,35 +1209,6 @@ void add_to_large_array(TALLOC_CTX *mem_ctx, size_t element_size,
}
/****************************************************************************
- 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;
}
diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c
index a4ef528133b..59a2ca405ea 100644
--- a/source3/nmbd/nmbd_processlogon.c
+++ b/source3/nmbd/nmbd_processlogon.c
@@ -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"));
diff --git a/source3/rpc_client/cli_pipe.c b/source3/rpc_client/cli_pipe.c
index 2841ff08f61..24dbcb01931 100644
--- a/source3/rpc_client/cli_pipe.c
+++ b/source3/rpc_client/cli_pipe.c
@@ -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)) {
diff --git a/source3/torture/torture.c b/source3/torture/torture.c
index 9cf41d88c7c..db89b05603a 100644
--- a/source3/torture/torture.c
+++ b/source3/torture/torture.c
@@ -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;
diff --git a/source4/client/smbspool.c b/source4/client/smbspool.c
index df867d5fefc..cfba5992d3c 100644
--- a/source4/client/smbspool.c
+++ b/source4/client/smbspool.c
@@ -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;
diff --git a/source4/param/loadparm.c b/source4/param/loadparm.c
index 0cd92c16f1e..6789aa1ac29 100644
--- a/source4/param/loadparm.c
+++ b/source4/param/loadparm.c
@@ -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");