XRootD
XrdAccAuthFile Class Reference

#include <XrdAccAuthFile.hh>

+ Inheritance diagram for XrdAccAuthFile:
+ Collaboration diagram for XrdAccAuthFile:

Public Member Functions

 XrdAccAuthFile (XrdSysError *erp)
 
 ~XrdAccAuthFile ()
 
int Changed (const char *dbpath)
 
int Close ()
 
char getID (char **id)
 
int getPP (char **path, char **priv, bool &istmplt)
 
char getRec (char **recname)
 
int Open (XrdSysError &eroute, const char *path=0)
 
- Public Member Functions inherited from XrdAccAuthDB
 XrdAccAuthDB ()
 
virtual ~XrdAccAuthDB ()
 

Detailed Description

Definition at line 44 of file XrdAccAuthFile.hh.

Constructor & Destructor Documentation

◆ XrdAccAuthFile()

XrdAccAuthFile::XrdAccAuthFile ( XrdSysError erp)

Definition at line 54 of file XrdAccAuthFile.cc.

55 {
56 
57 // Set starting values
58 //
59  authfn = 0;
60  flags = Noflags;
61  modtime = 0;
62  Eroute = erp;
63 
64 // Setup for an error in the first record
65 //
66  strcpy(path_buff, "start of file");
67 }

◆ ~XrdAccAuthFile()

XrdAccAuthFile::~XrdAccAuthFile ( )

Definition at line 73 of file XrdAccAuthFile.cc.

74 {
75 
76 // If the file is open, close it
77 //
78  if (flags &isOpen) Close();
79 
80 // Free the authfn string
81 //
82  if (authfn) free(authfn);
83 }

References Close().

+ Here is the call graph for this function:

Member Function Documentation

◆ Changed()

int XrdAccAuthFile::Changed ( const char *  dbpath)
virtual

Implements XrdAccAuthDB.

Definition at line 89 of file XrdAccAuthFile.cc.

90 {
91  struct stat statbuff;
92 
93 // If no file here, indicate nothing changed
94 //
95  if (!authfn || !*authfn) return 0;
96 
97 // If file paths differ, indicate that something has changed
98 //
99  if (dbfn && strcmp(dbfn, authfn)) return 1;
100 
101 // Get the modification timestamp for this file
102 //
103  if (stat(authfn, &statbuff))
104  {Eroute->Emsg("AuthFile", errno, "find", authfn);
105  return 0;
106  }
107 
108 // Indicate whether or not the file has changed
109 //
110  return (modtime < statbuff.st_mtime);
111 }
int stat(const char *path, struct stat *buf)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.cc:95

References XrdSysError::Emsg(), and stat().

+ Here is the call graph for this function:

◆ Close()

int XrdAccAuthFile::Close ( )
virtual

Implements XrdAccAuthDB.

Definition at line 117 of file XrdAccAuthFile.cc.

118 {
119 // Return is the file is not open
120 //
121  if (!(flags & isOpen)) return 1;
122 
123 // Close the stream
124 //
125  DBfile.Close();
126 
127 // Unlock the protecting mutex
128 //
129  DBcontext.UnLock();
130 
131 // Indicate file is no longer open
132 //
133  flags = (DBflags)(flags & ~isOpen);
134 
135 // Return indicator of whether we had any errors
136 //
137  if (flags & dbError) return 0;
138  return 1;
139 }
void Close(int hold=0)

References XrdOucStream::Close(), and XrdSysMutex::UnLock().

Referenced by ~XrdAccAuthFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getID()

char XrdAccAuthFile::getID ( char **  id)
virtual

Implements XrdAccAuthDB.

Definition at line 145 of file XrdAccAuthFile.cc.

146 {
147  char *pp, idcode[2] = {0,0};
148 
149 // If a record has not been read, return end of record (i.e., 0)
150 //
151  if (!(flags & inRec)) return 0;
152 
153 // Read the next word from the record (if none, simulate end of record)
154 //
155  if (!(pp = DBfile.GetWord()))
156  {flags = (DBflags)(flags & ~inRec);
157  return 0;
158  }
159 
160 // Id's are of the form 'c', but historically they were 'c:' so we accept a
161 // two character specification but only validate the first to be backward
162 // compatible.
163 //
164  if (strlen(pp) > 2 || !index("ghoru", *pp))
165  {Eroute->Emsg("AuthFile", "Invalid ID sprecifier -", pp);
166  flags = (DBflags)(flags | dbError);
167  return 0;
168  }
169  idcode[0] = *pp;
170 
171 // Now get the actual id associated with it
172 //
173  if (!(pp = DBfile.GetWord()))
174  {flags = (DBflags)(flags & ~inRec);
175  Eroute->Emsg("AuthFile", "ID value missing after", idcode);
176  flags = (DBflags)(flags | dbError);
177  return 0;
178  }
179 
180 // Copy the value since the stream buffer might get overlaid.
181 //
182  Copy(path_buff, pp, sizeof(path_buff)-1);
183 
184 // Return result
185 //
186  *id = path_buff;
187  return idcode[0];
188 }
char * GetWord(int lowcase=0)

References XrdSysError::Emsg(), and XrdOucStream::GetWord().

+ Here is the call graph for this function:

◆ getPP()

int XrdAccAuthFile::getPP ( char **  path,
char **  priv,
bool &  istmplt 
)
virtual

Implements XrdAccAuthDB.

Definition at line 194 of file XrdAccAuthFile.cc.

195 {
196 // char *pp, *bp;
197  char *pp;
198 
199 // If a record has not been read, return end of record (i.e., 0)
200 //
201  if (!(flags & inRec)) return 0;
202 
203 // read the next word from the record (if none, simulate end of record)
204 //
205  if (!(pp = DBfile.GetWord()))
206  {flags = (DBflags)(flags & ~inRec);
207  return 0;
208  }
209 
210 // Check of objectid specification
211 //
212  istmplt = false;
213  *path = path_buff;
214  if (*pp == '\\')
215  {if (*(pp+1)) pp++;
216  else {Eroute->Emsg("AuthFile", "Object ID missing after '\\'");
217  *path = 0;
218  flags = (DBflags)(flags | dbError);
219  }
220  } else if (*pp != '/') istmplt = true;
221 
222 // Copy the value since the stream buffer might get overlaid.
223 //
224 // bp = Copy(path_buff, pp, sizeof(path_buff)-1);
225  if (path) Copy(path_buff, pp, sizeof(path_buff)-1);
226 
227 // Check if this is really a path or a template
228 //
229  if (istmplt) {*priv = (char *)0; return 1;}
230 
231 // Verify that the path ends correctly (normally we would force a slash to
232 // appear at the end but that prevents caps on files. So, we commented the
233 // code out until we decide that maybe we really need to do this, sigh.
234 //
235 // bp--;
236 // if (*bp != '/') {bp++; *bp = '/'; bp++; *bp = '\0';}
237 
238 // Get the next word which should be the privilege string
239 //
240  if (!(pp = DBfile.GetWord()))
241  {flags = (DBflags)(flags & ~inRec);
242  Eroute->Emsg("AuthFile", "Privileges missing after", path_buff);
243  flags = (DBflags)(flags | dbError);
244  *priv = (char *)0;
245  return 0;
246  }
247 
248 // All done here
249 //
250  *priv = pp;
251  return 1;
252 }

References XrdSysError::Emsg(), and XrdOucStream::GetWord().

+ Here is the call graph for this function:

◆ getRec()

char XrdAccAuthFile::getRec ( char **  recname)
virtual

Implements XrdAccAuthDB.

Definition at line 258 of file XrdAccAuthFile.cc.

259 {
260  char *pp;
261  int idok;
262 
263 // Do this until we get a vlaid record
264 //
265  while(1)
266  {
267  // If we arer still in the middle of a record, flush it
268  //
269  if (flags & inRec) while(DBfile.GetWord()) {}
270  else flags = (DBflags)(flags | inRec);
271 
272  // Get the next word, the record type
273  //
274  if (!(pp = DBfile.GetWord()))
275  {*recname = (char *)0; return '\0';}
276 
277  // Verify the id-type
278  //
279  idok = 0;
280  if (strlen(pp) == 1)
281  switch(*pp)
282  {case 'g':
283  case 'h':
284  case 's':
285  case 'n':
286  case 'o':
287  case 'r':
288  case 't':
289  case 'u':
290  case 'x':
291  case '=': idok = 1;
292  break;
293  default: break;
294  }
295 
296  // Check if the record type was valid
297  //
298  if (!idok) {Eroute->Emsg("AuthFile", "Invalid id type -", pp);
299  flags = (DBflags)(flags | dbError);
300  continue;
301  }
302  rectype = *pp;
303 
304  // Get the record name. It must exist
305  //
306  if (!(pp = DBfile.GetWord()))
307  {Eroute->Emsg("AuthFile","Record name is missing after",path_buff);
308  flags = (DBflags)(flags | dbError);
309  continue;
310  }
311 
312  // Copy the record name
313  //
314  Copy(recname_buff, pp, sizeof(recname_buff));
315  *recname = recname_buff;
316  return rectype;
317  }
318  return '\0'; // Keep the compiler happy :-)
319 }

References XrdSysError::Emsg(), and XrdOucStream::GetWord().

+ Here is the call graph for this function:

◆ Open()

int XrdAccAuthFile::Open ( XrdSysError eroute,
const char *  path = 0 
)
virtual

Implements XrdAccAuthDB.

Definition at line 325 of file XrdAccAuthFile.cc.

326 {
327  struct stat statbuff;
328  int authFD;
329 
330 // Enter the DB context (serialize use of this database)
331 //
332  DBcontext.Lock();
333  Eroute = &eroute;
334 
335 // Use whichever path is the more recent
336 //
337  if (path)
338  {if (authfn) free(authfn); authfn = strdup(path);}
339  if( !authfn || !*authfn) return Bail(0, "Authorization file not specified.");
340 
341 // Get the modification timestamp for this file
342 //
343  if (stat(authfn, &statbuff)) return Bail(errno, "find", authfn);
344 
345 // Try to open the authorization file.
346 //
347  if ( (authFD = open(authfn, O_RDONLY, 0)) < 0)
348  return Bail(errno,"open authorization file",authfn);
349 
350 // Copy in all the relevant information
351 //
352  modtime = statbuff.st_mtime;
353  flags = isOpen;
354  DBfile.SetEroute(Eroute);
355  DBfile.Tabs(0);
356 
357 // Attach the file to the stream
358 //
359  if (DBfile.Attach(authFD))
360  return Bail(DBfile.LastError(), "initialize stream for", authfn);
361  return 1;
362 }
int open(const char *path, int oflag,...)
int Attach(int FileDescriptor, int bsz=2047)
void SetEroute(XrdSysError *eroute)
void Tabs(int x=1)

References XrdOucStream::Attach(), XrdOucStream::LastError(), XrdSysMutex::Lock(), open(), XrdOucStream::SetEroute(), stat(), and XrdOucStream::Tabs().

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: