}
/**
- 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);
}
/**
_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.
/*
* 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;
}
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);
*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.
****************************************************************************/
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;
}
("get_mydnsdomname failed.\n"));
return;
}
- hostname = talloc_get_myname(talloc_tos());
+ hostname = get_myname(talloc_tos());
if (!hostname) {
DEBUG(2,
("get_myname failed.\n"));
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)) {
*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;
* 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;
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");