char *alloc_sub_specified(const char *input_string, const char *username, const char *domain, uid_t uid, gid_t gid) { char *a_string, *ret_string; char *b, *p, *s; a_string = SMB_STRDUP(input_string); if (a_string == NULL) { DEBUG(0, ("alloc_sub_specified: Out of memory!\n")); return NULL; } for (b = s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) { b = a_string; switch (*(p+1)) { case 'U' : a_string = realloc_string_sub(a_string, "%U", username); break; case 'u' : a_string = realloc_string_sub(a_string, "%u", username); break; case 'G' : if (gid != -1) { a_string = realloc_string_sub(a_string, "%G", gidtoname(gid)); } else { a_string = realloc_string_sub(a_string, "%G", "NO_GROUP"); } break; case 'g' : if (gid != -1) { a_string = realloc_string_sub(a_string, "%g", gidtoname(gid)); } else { a_string = realloc_string_sub(a_string, "%g", "NO_GROUP"); } break; case 'D' : a_string = realloc_string_sub(a_string, "%D", domain); break; case 'N' : a_string = realloc_string_sub(a_string, "%N", automount_server(username)); break; default: break; } p++; if (a_string == NULL) { return NULL; } } ret_string = alloc_sub_basic(username, a_string); SAFE_FREE(a_string); return ret_string; }
char *talloc_sub_basic(TALLOC_CTX *mem_ctx, const char *smb_name, const char *str) { char *a, *t; a = alloc_sub_basic(smb_name, str); if (!a) return NULL; t = talloc_strdup(mem_ctx, a); SAFE_FREE(a); return t; }
void standard_sub_basic(const char *smb_name, char *str, size_t len) { char *s; if ( (s = alloc_sub_basic( smb_name, str )) != NULL ) { strncpy( str, s, len ); } SAFE_FREE( s ); }
char *alloc_sub_advanced(int snum, const char *user, const char *connectpath, gid_t gid, const char *smb_name, const char *str) { char *a_string, *ret_string; char *b, *p, *s, *t, *h; a_string = strdup(str); if (a_string == NULL) { DEBUG(0, ("alloc_sub_specified: Out of memory!\n")); return NULL; } for (b = s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) { b = t = a_string; switch (*(p+1)) { case 'N' : t = realloc_string_sub(t, "%N", automount_server(user)); break; case 'H': if ((h = get_user_home_dir(user))) t = realloc_string_sub(t, "%H", h); break; case 'P': t = realloc_string_sub(t, "%P", connectpath); break; case 'S': t = realloc_string_sub(t, "%S", lp_servicename(snum)); break; case 'g': t = realloc_string_sub(t, "%g", gidtoname(gid)); break; case 'u': t = realloc_string_sub(t, "%u", user); break; /* Patch from [email protected] Left the %N (NIS * server name) in standard_sub_basic as it is * a feature for logon servers, hence uses the * username. The %p (NIS server path) code is * here as it is used instead of the default * "path =" string in [homes] and so needs the * service name, not the username. */ case 'p': t = realloc_string_sub(t, "%p", automount_path(lp_servicename(snum))); break; default: break; } p++; if (t == NULL) { SAFE_FREE(a_string); return NULL; } a_string = t; } ret_string = alloc_sub_basic(smb_name, a_string); SAFE_FREE(a_string); return ret_string; }