/[pdpsoft]/trunk/grid-mw-security/cgul/unixprivs/unixpriv.c
ViewVC logotype

Diff of /trunk/grid-mw-security/cgul/unixprivs/unixpriv.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1403 by okoeroo, Wed Jan 20 11:21:41 2010 UTC revision 1404 by okoeroo, Wed Jan 20 11:48:59 2010 UTC
# Line 6  C-GUL Line 6  C-GUL
6  ****************************************************/  ****************************************************/
7    
8    
9    uid_t threadsafe_getuid_from_name (const char * username)
10    {
11        struct passwd * p          = NULL;
12        uid_t           uid        = -1;
13        int             errno_save = 0;
14    #define HAVE_GETPWNAM_R
15    #ifdef HAVE_GETPWNAM_R || defined _LIBC
16      #ifdef _SC_GETPW_R_SIZE_MAX
17        size_t buflen = sysconf (_SC_GETPW_R_SIZE_MAX);
18      #else
19        size_t buflen = 128;
20      #endif
21        char *pwtmpbuf;
22        struct passwd pwbuf;
23    
24    
25        if (buflen == -1)
26            /* `sysconf' does not support _SC_GETPW_R_SIZE_MAX.  Try a
27               moderate value.  */
28            buflen = 128;
29    
30        pwtmpbuf = (char *) calloc (1, buflen);
31    
32        while (getpwnam_r (username, &pwbuf, pwtmpbuf, buflen, &p) != 0)
33        {
34            if (errno != ERANGE)
35            {
36                p = NULL;
37                break;
38            }
39            buflen *= 2;
40            free (pwtmpbuf);
41            
42            if (!(pwtmpbuf = (char *) calloc (1, buflen)))
43            {
44                if (errno == ENOMEM)
45                {
46                    /* No memory available, bail out */
47                    p = NULL;
48                    errno_save = errno;
49                    break;
50                }
51            }
52        }
53    #else
54        p = getpwnam (username);
55    #endif
56    
57        if (p)
58        {
59            uid = p -> pw_uid;
60        }
61    
62        free (pwtmpbuf);
63        errno = errno_save;
64        return uid;
65    }
66    
67    
68    

Legend:
Removed from v.1403  
changed lines
  Added in v.1404

grid.support@nikhef.nl
ViewVC Help
Powered by ViewVC 1.1.28