summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/substitute.c43
1 files changed, 29 insertions, 14 deletions
diff --git a/source3/lib/substitute.c b/source3/lib/substitute.c
index e7d620db16..6f6d2a9c16 100644
--- a/source3/lib/substitute.c
+++ b/source3/lib/substitute.c
@@ -157,15 +157,13 @@ static char *automount_server(char *user_name)
return server_name;
}
-
/****************************************************************************
Do some standard substitutions in a string.
****************************************************************************/
-static void standard_sub_advanced(int snum, char *user, char *connectpath, gid_t gid, char *str)
+void standard_sub_basic(char *str)
{
- char *p, *s, *home;
+ char *p, *s;
fstring pidstr;
- struct passwd *pass;
for (s=str; (p=strchr(s, '%'));s=p) {
int l = sizeof(pstring) - (int)(p-str);
@@ -176,7 +174,6 @@ static void standard_sub_advanced(int snum, char *user, char *connectpath, gid_t
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 'U' : string_sub(p,"%U", user,l); break;
case 'a' : string_sub(p,"%a", remote_arch,l); break;
case 'd' :
slprintf(pidstr,sizeof(pidstr), "%d",(int)getpid());
@@ -186,6 +183,31 @@ static void standard_sub_advanced(int snum, char *user, char *connectpath, gid_t
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 */
+
+ default: p+=2;
+ break;
+ }
+ }
+}
+
+
+/****************************************************************************
+ Do some standard substitutions in a string.
+****************************************************************************/
+static void standard_sub_advanced(int snum, char *user, char *connectpath, gid_t gid, char *str)
+{
+ char *p, *s, *home;
+ fstring pidstr;
+ struct passwd *pass;
+
+ for (s=str; (p=strchr(s, '%'));s=p) {
+ int l = sizeof(pstring) - (int)(p-str);
+
+ switch (*(p+1)) {
+ case 'U' : string_sub(p,"%U", user,l); break;
case 'G' :
if ((pass = Get_Pwnam(user,False))!=NULL) {
string_sub(p,"%G",gidtoname(pass->pw_gid),l);
@@ -234,6 +256,8 @@ static void standard_sub_advanced(int snum, char *user, char *connectpath, gid_t
break;
}
}
+
+ standard_sub_basic(str);
}
/****************************************************************************
@@ -252,15 +276,6 @@ void standard_sub_snum(int snum, char *str)
standard_sub_advanced(snum, "", "", -1, str);
}
-
-/*******************************************************************
- Substitute strings with useful parameters.
-********************************************************************/
-void standard_sub_basic(char *str)
-{
- standard_sub_advanced(-1, "", "", -1, str);
-}
-
/*******************************************************************
Substitute strings with useful parameters.
********************************************************************/