diff options
author | Andrew Tridgell <tridge@samba.org> | 2000-08-25 03:58:02 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2000-08-25 03:58:02 +0000 |
commit | e1b9b33e2baa0ec22d62b0c3389ded4d597f7efb (patch) | |
tree | 6cadd2af694eb19c716e1f6b843714ac0ff232d3 /source3 | |
parent | ebe8a05062c2385ff32ddef4d5438437d014a57e (diff) | |
download | samba-e1b9b33e2baa0ec22d62b0c3389ded4d597f7efb.tar.gz samba-e1b9b33e2baa0ec22d62b0c3389ded4d597f7efb.tar.bz2 samba-e1b9b33e2baa0ec22d62b0c3389ded4d597f7efb.zip |
- fixed the %U macro so that the old (and documented) semantics work
again. This got broken with one of the substitute.c updates a couple
of months ago.
- also fixed %u to return the username from the current_user structure
when called via a method that does not have direct access to the
username. I cache the uidtoname() result to prevent thrashing nss.
(This used to be commit 2520a0eff9c5decbec79aababe9910db3535890a)
Diffstat (limited to 'source3')
-rw-r--r-- | source3/lib/substitute.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/source3/lib/substitute.c b/source3/lib/substitute.c index 5eb557d03c..0212147161 100644 --- a/source3/lib/substitute.c +++ b/source3/lib/substitute.c @@ -206,7 +206,7 @@ void standard_sub_advanced(int snum, char *user, char *connectpath, gid_t gid, c int l = sizeof(pstring) - (int)(p-str); switch (*(p+1)) { - case 'U' : string_sub(p,"%U", user,l); break; + case 'U' : string_sub(p,"%U",sam_logon_in_ssb?samlogon_user:sesssetup_user,l); break; case 'G' : if ((pass = Get_Pwnam(user,False))!=NULL) { string_sub(p,"%G",gidtoname(pass->pw_gid),l); @@ -272,7 +272,18 @@ like standard_sub but by snum ****************************************************************************/ void standard_sub_snum(int snum, char *str) { - standard_sub_advanced(snum, "", "", -1, str); + extern struct current_user current_user; + static uid_t cached_uid = -1; + static fstring cached_user; + /* calling uidtoname() on every substitute would be too expensive, so + we cache the result here as nearly every call is for the same uid */ + + if (cached_uid != current_user.uid) { + fstrcpy(cached_user, uidtoname(current_user.uid)); + cached_uid = current_user.uid; + } + + standard_sub_advanced(snum, cached_user, "", -1, str); } /******************************************************************* |