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 /* This file is part of the XRootD software suite. */
13 /* */
14 /* XRootD is free software: you can redistribute it and/or modify it under */
15 /* the terms of the GNU Lesser General Public License as published by the */
16 /* Free Software Foundation, either version 3 of the License, or (at your */
17 /* option) any later version. */
18 /* */
19 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22 /* License for more details. */
23 /* */
24 /* You should have received a copy of the GNU Lesser General Public License */
25 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27 /* */
28 /* The copyright holder's institutional names and contributor's names may not */
29 /* be used to endorse or promote products derived from this software without */
30 /* specific prior written permission of the institution or contributor. */
31 /******************************************************************************/
32 
33 #include <sys/types.h>
34 #include <pwd.h>
35 
36 class XrdSysPwd
37 {
38 public:
39 
40 int rc;
41 
42 struct passwd *Get(const char *Usr)
43  {rc = getpwnam_r(Usr,&pwStruct,pwBuff,sizeof(pwBuff),&Ppw);
44  return Ppw;
45  }
46 
47 struct passwd *Get(uid_t Uid)
48  {rc = getpwuid_r(Uid,&pwStruct,pwBuff,sizeof(pwBuff),&Ppw);
49  return Ppw;
50  }
51 
52  XrdSysPwd() : rc(2) {}
53 
54  XrdSysPwd(const char *Usr, struct passwd **pwP)
55  {rc = getpwnam_r(Usr,&pwStruct,pwBuff,sizeof(pwBuff),pwP);}
56 
57  XrdSysPwd(uid_t Uid, struct passwd **pwP)
58  {rc = getpwuid_r(Uid,&pwStruct,pwBuff,sizeof(pwBuff),pwP);}
59 
61 
62 private:
63 
64 struct passwd pwStruct, *Ppw;
65 char pwBuff[4096];
66 };
67 #endif
XrdSysPwd()
Definition: XrdSysPwd.hh:52
struct passwd pwStruct * Ppw
Definition: XrdSysPwd.hh:64
Definition: XrdSysPwd.hh:36
XrdSysPwd(uid_t Uid, struct passwd **pwP)
Definition: XrdSysPwd.hh:57
struct passwd * Get(const char *Usr)
Definition: XrdSysPwd.hh:42
XrdSysPwd(const char *Usr, struct passwd **pwP)
Definition: XrdSysPwd.hh:54
int rc
Definition: XrdSysPwd.hh:40
struct passwd * Get(uid_t Uid)
Definition: XrdSysPwd.hh:47
char pwBuff[4096]
Definition: XrdSysPwd.hh:65
~XrdSysPwd()
Definition: XrdSysPwd.hh:60