XRootD
XrdMacaroonsHandler.cc File Reference
#include "XrdMacaroonsHandler.hh"
#include "XrdAcc/XrdAccAuthorize.hh"
#include "XrdAcc/XrdAccPrivs.hh"
#include "XrdOuc/XrdOucTUtils.hh"
#include "XrdSec/XrdSecEntity.hh"
#include "XrdSys/XrdSysError.hh"
#include <cstring>
#include <iostream>
#include <set>
#include <sstream>
#include <string>
#include <json.h>
#include <macaroons.h>
#include <uuid/uuid.h>
+ Include dependency graph for XrdMacaroonsHandler.cc:

Go to the source code of this file.

Functions

static ssize_t determine_validity (const std::string &input)
 
static bool is_reserved_caveat (const std::string &cv)
 
static bool is_supported_caveat (const std::string &cv)
 
char * unquote (const char *str)
 

Function Documentation

◆ determine_validity()

static ssize_t determine_validity ( const std::string &  input)
static

Definition at line 88 of file XrdMacaroonsHandler.cc.

89 {
90  ssize_t duration = 0;
91  if (input.find("PT") != 0)
92  {
93  return -1;
94  }
95  size_t pos = 2;
96  std::string remaining = input;
97  do
98  {
99  remaining = remaining.substr(pos);
100  if (remaining.size() == 0) break;
101  long cur_duration;
102  try
103  {
104  cur_duration = stol(remaining, &pos);
105  } catch (...)
106  {
107  return -1;
108  }
109  if (pos >= remaining.size())
110  {
111  return -1;
112  }
113  char unit = remaining[pos];
114  switch (unit) {
115  case 'S':
116  break;
117  case 'M':
118  cur_duration *= 60;
119  break;
120  case 'H':
121  cur_duration *= 3600;
122  break;
123  default:
124  return -1;
125  };
126  pos ++;
127  duration += cur_duration;
128  } while (1);
129  return duration;
130 }

Referenced by Macaroons::Handler::ProcessReq().

+ Here is the caller graph for this function:

◆ is_reserved_caveat()

static bool is_reserved_caveat ( const std::string &  cv)
static

Definition at line 75 of file XrdMacaroonsHandler.cc.

76 {
77  return cv.compare(0, 5, "name:") == 0 ||
78  cv.compare(0, 5, "path:") == 0 ||
79  cv.compare(0, 7, "before:") == 0;
80 }

Referenced by Macaroons::Handler::ProcessReq().

+ Here is the caller graph for this function:

◆ is_supported_caveat()

static bool is_supported_caveat ( const std::string &  cv)
static

Definition at line 82 of file XrdMacaroonsHandler.cc.

83 {
84  return cv.compare(0, 9, "activity:") == 0;
85 }

Referenced by Macaroons::Handler::ProcessReq().

+ Here is the caller graph for this function:

◆ unquote()

char* unquote ( const char *  str)

Definition at line 21 of file XrdMacaroonsHandler.cc.

21  {
22  int l = strlen(str);
23  char *r = (char *) malloc(l + 1);
24  r[0] = '\0';
25  int i, j = 0;
26 
27  for (i = 0; i < l; i++) {
28 
29  if (str[i] == '%') {
30  char savec[3];
31  if (l <= i + 3) {
32  free(r);
33  return nullptr;
34  }
35  savec[0] = str[i + 1];
36  savec[1] = str[i + 2];
37  savec[2] = '\0';
38 
39  r[j] = strtol(savec, 0, 16);
40 
41  i += 2;
42  } else if (str[i] == '+') r[j] = ' ';
43  else r[j] = str[i];
44 
45  j++;
46  }
47 
48  r[j] = '\0';
49 
50  return r;
51 
52 }