xrootd
XrdSysPwd.hh
Go to the documentation of this file.
1 #ifndef __XRDSYSPWD_HH__
2 #define __XRDSYSPWD_HH__
3 /******************************************************************************/
4 /* */
5 /* X r d S y s P w d . h h */
6 /* */
7 /* (c) 2011 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
11 /******************************************************************************/
12 
13 #include <sys/types.h>
14 #include <pwd.h>
15 
16 class XrdSysPwd
17 {
18 public:
19 
20 int rc;
21 
22 struct passwd *Get(const char *Usr)
23  {rc = getpwnam_r(Usr,&pwStruct,pwBuff,sizeof(pwBuff),&Ppw);
24  return Ppw;
25  }
26 
27 struct passwd *Get(uid_t Uid)
28  {rc = getpwuid_r(Uid,&pwStruct,pwBuff,sizeof(pwBuff),&Ppw);
29  return Ppw;
30  }
31 
32  XrdSysPwd() : rc(2) {}
33 
34  XrdSysPwd(const char *Usr, struct passwd **pwP)
35  {rc = getpwnam_r(Usr,&pwStruct,pwBuff,sizeof(pwBuff),pwP);}
36 
37  XrdSysPwd(uid_t Uid, struct passwd **pwP)
38  {rc = getpwuid_r(Uid,&pwStruct,pwBuff,sizeof(pwBuff),pwP);}
39 
41 
42 private:
43 
44 struct passwd pwStruct, *Ppw;
45 char pwBuff[4096];
46 };
47 #endif