XRootD
Loading...
Searching...
No Matches
XrdMacaroonsHandler.cc File Reference
#include <cstring>
#include <string>
#include <iostream>
#include <sstream>
#include <uuid/uuid.h>
#include "json.h"
#include "macaroons.h"
#include "XrdAcc/XrdAccPrivs.hh"
#include "XrdAcc/XrdAccAuthorize.hh"
#include "XrdSys/XrdSysError.hh"
#include "XrdSec/XrdSecEntity.hh"
#include "XrdMacaroonsHandler.hh"
#include "XrdOuc/XrdOucTUtils.hh"
+ 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)
 
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 78 of file XrdMacaroonsHandler.cc.

79{
80 return cv.compare(0, 5, "name:") == 0 ||
81 cv.compare(0, 5, "path:") == 0 ||
82 cv.compare(0, 9, "activity:") == 0 ||
83 cv.compare(0, 7, "before:") == 0;
84}

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

+ Here is the caller graph for this function:

◆ unquote()

char * unquote ( const char * str)

Definition at line 23 of file XrdMacaroonsHandler.cc.

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