On Tue, 2009-08-18 at 18:34 -0500, Tom Collins wrote: > How often does the code actually reference the UID/GID? Could you > have a function to look it up and cache it in a static once found? > > A quick check and it looks like it's only referenced when adding a > user or updating the tcp.smtp.cdb file. There are a few other > references, but the common things (like vchkpw and vdelivermail) > don't appear to make use of it. > > Probably not a big deal to use getpwnam. >
Not a big deal using getpwnam(). Also if you run nscd daemon, password/group file lookups get cached http://docs.sun.com/app/docs/doc/816-5166/nscd-1m?a=view Also using getpwnam() function allows you to use hooks like NSS (Name Service Switch) - http://en.wikipedia.org/wiki/Name_Service_Switch In Unix-like operating systems, the Name Service Switch (NSS) allows Unix configuration databases to be provided by different sources, including local files (for example: /etc/passwd, /etc/group, /etc/hosts), LDAP, and other sources. In case it can be used, attaching a function GetVpopID() which I used with vpopmail in my early days of using vpopmail. It uses static variables to cache the uid/gid. Regards Manvendra http://www.indimail.org !DSPAM:4a8b792832719326514358!
/* * $Log: GetVpopID.c,v $ * Revision 1.3 2001-11-24 12:16:57+05:30 Cprogrammer * version information added * * Revision 1.2 2001-11-20 10:53:16+05:30 Cprogrammer * *** empty log message *** * * Revision 1.1 2001-10-24 18:15:00+05:30 Cprogrammer * Initial revision * */ #include "indimail.h" #include <pwd.h> #ifndef lint static char sccsid[] = "$Id: GetVpopID.c,v 1.3 2001-11-24 12:16:57+05:30 Cprogrammer Stab mbhangui $"; #endif int GetVpopID(uid_t *uid, gid_t *gid) { struct passwd *pw; static uid_t suid = -1; static gid_t sgid = -1; if(suid != -1 && sgid != -1) { *uid = suid; *gid = sgid; return(0); } if(!(pw = getpwnam(VPOPUSER))) { fprintf(stderr, "getpwnam failed for user %s\n", VPOPUSER); return(-1); } *uid = suid = pw->pw_uid; *gid = sgid = pw->pw_gid; return(0); } void getversion_GetVpopID_c() { printf("%s\n", sccsid); printf("%s\n", sccsidh); }