diff options
Diffstat (limited to 'source3/lib/substitute.c')
-rw-r--r-- | source3/lib/substitute.c | 162 |
1 files changed, 66 insertions, 96 deletions
diff --git a/source3/lib/substitute.c b/source3/lib/substitute.c index dbd382a9424..e878ee8cbfd 100644 --- a/source3/lib/substitute.c +++ b/source3/lib/substitute.c @@ -160,11 +160,9 @@ static char *automount_server(const char *user_name) /**************************************************************************** Do some standard substitutions in a string. - len is the length in bytes of the space allowed in string str. If zero means - don't allow expansions. ****************************************************************************/ -void standard_sub_basic(const char *smb_name, char *str,size_t len) +void standard_sub_basic(const char *smb_name, char *str) { char *p, *s; fstring pidstr; @@ -173,10 +171,7 @@ void standard_sub_basic(const char *smb_name, char *str,size_t len) for (s=str; (p=strchr_m(s, '%'));s=p) { fstring tmp_str; - int l = (int)len - (int)(p-str); - - if (l < 0) - l = 0; + int l = sizeof(pstring) - (int)(p-str); switch (*(p+1)) { case 'U' : @@ -197,43 +192,26 @@ void standard_sub_basic(const char *smb_name, char *str,size_t len) strupper(tmp_str); string_sub(p,"%D", tmp_str,l); break; - case 'I' : - string_sub(p,"%I", client_addr(),l); - break; + case 'I' : string_sub(p,"%I", client_addr(),l); break; case 'L' : - if (*local_machine) + if (*local_machine) { string_sub(p,"%L", local_machine,l); - else + } else { string_sub(p,"%L", global_myname,l); + } break; - case 'M' : - string_sub(p,"%M", client_name(),l); - break; - case 'R' : - string_sub(p,"%R", remote_proto,l); - break; - case 'T' : - string_sub(p,"%T", timestring(False),l); - break; - case 'a' : - string_sub(p,"%a", remote_arch,l); - break; + case 'M' : string_sub(p,"%M", client_name(),l); break; + case 'R' : string_sub(p,"%R", remote_proto,l); break; + case 'T' : string_sub(p,"%T", timestring(False),l); break; + case 'a' : string_sub(p,"%a", remote_arch,l); break; case 'd' : slprintf(pidstr,sizeof(pidstr)-1, "%d",(int)sys_getpid()); string_sub(p,"%d", pidstr,l); break; - case 'h' : - string_sub(p,"%h", myhostname(),l); - break; - case 'm' : - string_sub(p,"%m", remote_machine,l); - break; - case 'v' : - string_sub(p,"%v", VERSION,l); - break; - case '$' : - p += expand_env_var(p,l); - break; /* Expand environment variables */ + case 'h' : string_sub(p,"%h", myhostname(),l); break; + case 'm' : string_sub(p,"%m", remote_machine,l); break; + case 'v' : string_sub(p,"%v", VERSION,l); break; + case '$' : p += expand_env_var(p,l); break; /* Expand environment variables */ case '\0': p++; break; /* don't run off the end of the string */ @@ -248,34 +226,30 @@ void standard_sub_basic(const char *smb_name, char *str,size_t len) Do some standard substitutions in a string. ****************************************************************************/ -static void standard_sub_advanced(int snum, const char *user, - const char *connectpath, gid_t gid, - const char *smb_name, char *str, size_t len) +void standard_sub_advanced(int snum, const char *user, const char *connectpath, gid_t gid, const char *smb_name, char *str) { char *p, *s, *home; for (s=str; (p=strchr_m(s, '%'));s=p) { - int l = (int)len - (int)(p-str); - - if (l < 0) - l = 0; - + int l = sizeof(pstring) - (int)(p-str); + switch (*(p+1)) { - case 'N' : - string_sub(p,"%N", automount_server(user),l); - break; + case 'N' : string_sub(p,"%N", automount_server(user),l); break; case 'H': - if ((home = get_user_home_dir(user))) + if ((home = get_user_home_dir(user))) { string_sub(p,"%H",home, l); - else + } else { p += 2; + } break; case 'P': string_sub(p,"%P", connectpath, l); break; + case 'S': string_sub(p,"%S", lp_servicename(snum), l); break; + case 'g': string_sub(p,"%g", gidtoname(gid), l); break; @@ -302,46 +276,36 @@ static void standard_sub_advanced(int snum, const char *user, } } - standard_sub_basic(smb_name, str, len); + standard_sub_basic(smb_name, str); } -const char *standard_sub_specified(TALLOC_CTX *mem_ctx, const char *input_string, - const char *username, - const char *domain, - uid_t uid, - gid_t gid) +/**************************************************************************** + Do some standard substitutions in a string. +****************************************************************************/ + +void standard_sub_conn(connection_struct *conn, char *str) { - pstring input_pstring; - char *p, *s; + standard_sub_advanced(SNUM(conn), conn->user, conn->connectpath, conn->gid, current_user_info.smb_name, str); +} - pstrcpy(input_pstring, input_string); - - for (s=input_pstring; (p=strchr_m(s, '%')); s=p) { +/**************************************************************************** + Like standard_sub but for a homes share where snum still points to the [homes] + share. No user specific snum created yet so servicename should be the username. +****************************************************************************/ + +void standard_sub_home(int snum, const char *user, char *str) +{ + char *p, *s; - int l = sizeof(pstring) - (int)(p-input_pstring); + for (s=str; (p=strchr_m(s, '%'));s=p) { + int l = sizeof(pstring) - (int)(p-str); switch (*(p+1)) { - case 'U' : - string_sub(p,"%U",username,l); - break; - case 'u' : - string_sub(p,"%u",username,l); - break; - case 'G' : - case 'g' : - if (gid != -1) { - string_sub(p,"%G",gidtoname(gid),l); - string_sub(p,"%g",gidtoname(gid),l); - } else { - string_sub(p,"%G","NO_GROUP",l); - string_sub(p,"%g","NO_GROUP",l); - } - break; - case 'D' : - string_sub(p,"%D", domain,l); + case 'S': + string_sub(p,"%S", user, l); break; - case 'N' : - string_sub(p,"%N", automount_server(username),l); + case 'p': + string_sub(p,"%p", automount_path(user), l); break; case '\0': p++; @@ -352,25 +316,14 @@ const char *standard_sub_specified(TALLOC_CTX *mem_ctx, const char *input_string } } - standard_sub_basic(username, input_pstring, sizeof(pstring)); - return talloc_strdup(mem_ctx, input_pstring); -} - -/**************************************************************************** - Do some standard substitutions in a string. -****************************************************************************/ - -void standard_sub_conn(connection_struct *conn, char *str, size_t len) -{ - standard_sub_advanced(SNUM(conn), conn->user, conn->connectpath, - conn->gid, current_user_info.smb_name, str, len); + standard_sub_advanced(snum, user, "", -1, current_user_info.smb_name, str); } /**************************************************************************** Like standard_sub but by snum. ****************************************************************************/ -void standard_sub_snum(int snum, char *str, size_t len) +void standard_sub_snum(int snum, char *str) { extern struct current_user current_user; static uid_t cached_uid = -1; @@ -383,6 +336,23 @@ void standard_sub_snum(int snum, char *str, size_t len) cached_uid = current_user.uid; } - standard_sub_advanced(snum, cached_user, "", -1, - current_user_info.smb_name, str, len); + standard_sub_advanced(snum, cached_user, "", -1, current_user_info.smb_name, str); +} + +/******************************************************************* + Substitute strings with useful parameters. +********************************************************************/ + +void standard_sub_vuser(char *str, user_struct *vuser) +{ + standard_sub_advanced(-1, vuser->user.unix_name, "", -1, current_user_info.smb_name, str); +} + +/******************************************************************* + Substitute strings with useful parameters. +********************************************************************/ + +void standard_sub_vsnum(char *str, user_struct *vuser, int snum) +{ + standard_sub_advanced(snum, vuser->user.unix_name, "", -1, current_user_info.smb_name, str); } |