XRootD
Loading...
Searching...
No Matches
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 <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 87 of file XrdMacaroonsHandler.cc.

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

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 74 of file XrdMacaroonsHandler.cc.

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

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 81 of file XrdMacaroonsHandler.cc.

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

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

+ Here is the caller graph for this function:

◆ unquote()

char * unquote ( const char * str)

Definition at line 20 of file XrdMacaroonsHandler.cc.

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