static char *local_machine;
+void free_local_machine_name(void)
+{
+ SAFE_FREE(local_machine);
+}
+
bool set_local_machine_name(const char *local_name, bool perm)
{
static bool already_perm = false;
static char *longvar_domainsid( void )
{
DOM_SID sid;
+ fstring tmp;
char *sid_string;
if ( !secrets_fetch_domain_sid( lp_workgroup(), &sid ) ) {
return NULL;
}
- sid_string = SMB_STRDUP( sid_string_static( &sid ) );
+ sid_string = SMB_STRDUP( sid_to_fstring( tmp, &sid ) );
if ( !sid_string ) {
DEBUG(0,("longvar_domainsid: failed to dup SID string!\n"));
/* use the passwd entry as the default */
/* this will be the default if WITH_AUTOMOUNT is not used or fails */
- server_path = talloc_strdup(ctx, get_user_home_dir(user_name));
+ server_path = talloc_strdup(ctx, get_user_home_dir(ctx, user_name));
if (!server_path) {
return "";
}
(home_path_start+1):""));
server_path = talloc_strdup(ctx,
home_path_start+1);
+ if (!server_path) {
+ server_path = "";
+ }
}
} else {
/* NIS key lookup failed: default to
}
#endif
- if (!server_path) {
- server_path = "";
- }
DEBUG(4,("Home server path: %s\n", server_path));
return server_path;
}
return "";
}
srv = talloc_strdup(ctx, automount_value);
+ if (!srv) {
+ return "";
+ }
p = strchr_m(srv, ':');
if (!p) {
return "";
}
#endif
- if (!server_name) {
- server_name = "";
- }
DEBUG(4,("Home server: %s\n", server_name));
return server_name;
}
{
char *b, *p, *s, *r, *a_string;
fstring pidstr, vnnstr;
- struct passwd *pass;
char addr[INET6_ADDRSTRLEN];
const char *local_machine_name = get_local_machine_name();
+ TALLOC_CTX *tmp_ctx = NULL;
/* workaround to prevent a crash while looking at bug #687 */
DEBUG(0, ("alloc_sub_basic: Out of memory!\n"));
return NULL;
}
-
+
+ tmp_ctx = talloc_stackframe();
+
for (b = s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) {
r = NULL;
b = a_string;
-
+
switch (*(p+1)) {
case 'U' :
r = strdup_lower(smb_name);
}
a_string = realloc_string_sub(a_string, "%U", r);
break;
- case 'G' :
+ case 'G' : {
+ struct passwd *pass;
r = SMB_STRDUP(smb_name);
if (r == NULL) {
goto error;
}
- if ((pass = Get_Pwnam(r))!=NULL) {
- a_string = realloc_string_sub(a_string, "%G", gidtoname(pass->pw_gid));
- }
+ pass = Get_Pwnam_alloc(tmp_ctx, r);
+ if (pass != NULL) {
+ a_string = realloc_string_sub(
+ a_string, "%G",
+ gidtoname(pass->pw_gid));
+ }
+ TALLOC_FREE(pass);
break;
+ }
case 'D' :
r = strdup_upper(domain_name);
if (r == NULL) {
}
a_string = realloc_string_sub(a_string, "%D", r);
break;
- case 'I' :
+ case 'I' : {
+ int offset = 0;
+ client_addr(get_client_fd(), addr, sizeof(addr));
+ if (strnequal(addr,"::ffff:",7)) {
+ offset = 7;
+ }
a_string = realloc_string_sub(a_string, "%I",
- client_addr(get_client_fd(),addr, sizeof(addr)));
+ addr + offset);
break;
+ }
case 'i':
a_string = realloc_string_sub( a_string, "%i",
client_socket_addr(get_client_fd(), addr, sizeof(addr)) );
a_string = realloc_string_sub(a_string, "%R", remote_proto);
break;
case 'T' :
- a_string = realloc_string_sub(a_string, "%T", current_timestring(False));
+ a_string = realloc_string_sub(a_string, "%T", current_timestring(tmp_ctx, False));
break;
case 'a' :
a_string = realloc_string_sub(a_string, "%a",
p++;
SAFE_FREE(r);
-
- if ( !a_string ) {
- return NULL;
+
+ if (a_string == NULL) {
+ goto done;
}
}
- return a_string;
+ goto done;
error:
SAFE_FREE(a_string);
- return NULL;
+
+done:
+ TALLOC_FREE(tmp_ctx);
+ return a_string;
}
/****************************************************************************
const char *str)
{
char *a_string, *ret_string;
- char *b, *p, *s, *h;
+ char *b, *p, *s;
a_string = SMB_STRDUP(str);
if (a_string == NULL) {
case 'N' :
a_string = realloc_string_sub(a_string, "%N", automount_server(user));
break;
- case 'H':
- if ((h = get_user_home_dir(user)))
+ case 'H': {
+ char *h;
+ if ((h = get_user_home_dir(talloc_tos(), user)))
a_string = realloc_string_sub(a_string, "%H", h);
+ TALLOC_FREE(h);
break;
+ }
case 'P':
a_string = realloc_string_sub(a_string, "%P", connectpath);
break;