|
||||
File indexing completed on 2025-01-30 10:27:51
0001 #ifndef __SYS_PRIV_H__ 0002 #define __SYS_PRIV_H__ 0003 /******************************************************************************/ 0004 /* */ 0005 /* X r d S y s P r i v . h h */ 0006 /* */ 0007 /* (c) 2006 G. Ganis (CERN) */ 0008 /* */ 0009 /* This file is part of the XRootD software suite. */ 0010 /* */ 0011 /* XRootD is free software: you can redistribute it and/or modify it under */ 0012 /* the terms of the GNU Lesser General Public License as published by the */ 0013 /* Free Software Foundation, either version 3 of the License, or (at your */ 0014 /* option) any later version. */ 0015 /* */ 0016 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 0017 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 0018 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 0019 /* License for more details. */ 0020 /* */ 0021 /* You should have received a copy of the GNU Lesser General Public License */ 0022 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 0023 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 0024 /* */ 0025 /* The copyright holder's institutional names and contributor's names may not */ 0026 /* be used to endorse or promote products derived from this software without */ 0027 /* specific prior written permission of the institution or contributor. */ 0028 /* All Rights Reserved. See XrdInfo.cc for complete License Terms */ 0029 /******************************************************************************/ 0030 0031 ////////////////////////////////////////////////////////////////////////// 0032 // // 0033 // XrdSysPriv // 0034 // // 0035 // Author: G. Ganis, CERN, 2006 // 0036 // // 0037 // Implementation of a privileges handling API following the paper // 0038 // "Setuid Demystified" by H.Chen, D.Wagner, D.Dean // 0039 // also quoted in "Secure programming Cookbook" by J.Viega & M.Messier. // 0040 // // 0041 // NB: this class can only used via XrdSysPrivGuard (see below) // 0042 // // 0043 ////////////////////////////////////////////////////////////////////////// 0044 0045 #if !defined(WINDOWS) 0046 # include <sys/types.h> 0047 #else 0048 # define uid_t unsigned int 0049 # define gid_t unsigned int 0050 #endif 0051 0052 #include "XrdSys/XrdSysPthread.hh" 0053 0054 class XrdSysPriv 0055 { 0056 friend class XrdSysPrivGuard; 0057 private: 0058 // Ownership cannot be changed by thread, so there must be an overall 0059 // locking 0060 static XrdSysRecMutex fgMutex; 0061 0062 XrdSysPriv(); 0063 0064 static bool fDebug; 0065 0066 static int ChangeTo(uid_t uid, gid_t gid); 0067 static void DumpUGID(const char *msg = 0); 0068 static int Restore(bool saved = 1); 0069 0070 public: 0071 virtual ~XrdSysPriv() { } 0072 static int ChangePerm(uid_t uid, gid_t gid); 0073 }; 0074 0075 // 0076 // Guard class; 0077 // Usage: 0078 // 0079 // { XrdSysPrivGuard priv(tempuid); 0080 // 0081 // // Work as tempuid (maybe superuser) 0082 // ... 0083 // 0084 // } 0085 // 0086 class XrdSysPrivGuard 0087 { 0088 public: 0089 XrdSysPrivGuard(uid_t uid, gid_t gid); 0090 XrdSysPrivGuard(const char *user); 0091 virtual ~XrdSysPrivGuard(); 0092 bool Valid() const { return valid; } 0093 private: 0094 bool dum; 0095 bool valid; 0096 void Init(uid_t uid, gid_t gid); 0097 }; 0098 0099 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |