From b87eee983612c0d21b0c6f1346ba15ace797fe9e Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 22 May 2002 12:44:45 +0000 Subject: Add a bit more const, and kill of (finally!) sys_getpwnam and sys_getpwuid. These might be reimplmented as simple pass-through functions, but all users really should be doing 'getpwnam_alloc' or 'getpwuid_alloc' to ensure that there are not shared static buffers. I don't beleive we actually need a getpw*() cache inside samba - if we do then I think we should look at our code design first. (some of these changes are for platforms I don't have access to, but they look sane) Andrew Bartlett (This used to be commit 9d8431b04f41dceffe4c45cc969472ee59f7282f) --- source3/lib/util.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'source3/lib/util.c') diff --git a/source3/lib/util.c b/source3/lib/util.c index a23ef91a31..2fe9ec331b 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -1052,16 +1052,19 @@ BOOL process_exists(pid_t pid) Convert a uid into a user name. ********************************************************************/ -char *uidtoname(uid_t uid) +const char *uidtoname(uid_t uid) { static fstring name; struct passwd *pass; - pass = sys_getpwuid(uid); - if (pass) - return(pass->pw_name); - slprintf(name, sizeof(name) - 1, "%d",(int)uid); - return(name); + pass = getpwuid_alloc(uid); + if (pass) { + fstrcpy(name, pass->pw_name); + passwd_free(&pass); + } else { + slprintf(name, sizeof(name) - 1, "%ld",(long int)uid); + } + return name; } -- cgit