38 #include <arpa/inet.h>
39 #include <sys/param.h>
40 #include <sys/socket.h>
42 #include "XrdVersion.hh"
107 if (msg) std::cerr <<
"xrdacctest: " <<msg <<std::endl;
108 std::cerr <<
"Usage: xrdacctest [-c <cfn>] [<ids> | <user> <host>] <act>\n\n";
109 std::cerr <<
"<ids>: -a <auth> -g <grp> -h <host> -o <org> -r <role> -u <user>\n";
110 std::cerr <<
"<act>: <opc> <path> [<path> [...]]\n";
111 std::cerr <<
"<opc>: cr - create mv - rename st - status lk - lock\n";
112 std::cerr <<
" rd - read wr - write ls - readdir rm - remove\n";
113 std::cerr <<
" ec - excl create ei - excl rename\n";
114 std::cerr <<
" * - zap args ? - display privs\n";
115 std::cerr << std::flush;
125 if (dest) free(dest);
126 dest = (strcmp(val,
"none") ? strdup(val) : 0);
135 strncpy(Entity.prot,
"host",
sizeof(Entity.prot));
136 if (Entity.grps) free(Entity.grps);
138 if (Entity.host) free(Entity.host);
140 if (Entity.vorg) free(Entity.vorg);
142 if (Entity.role) free(Entity.role);
144 if (Entity.name) free(Entity.name);
152 int main(
int argc,
char **argv)
160 XrdVersionInfo &myVer);
161 int DoIt(
int argpnt,
int argc,
char **argv,
bool singleshot);
163 const char *cfHost =
"localhost", *cfProg =
"xrootd";
165 char *argval[32], buff[255],
tident[80], c;
166 int DoIt(
int argnum,
int argc,
char **argv,
int singleshot);
168 const int maxargs =
sizeof(argval)/
sizeof(argval[0]);
169 char *at, *lp, *ConfigFN = (
char *)
"./acc.cf";
171 bool singleshot=
false;
175 if (argc == 1)
Usage(0);
176 Entity.addrInfo = &netAddr;
177 sprintf(
tident,
"acctest.%d:0@localhost", getpid());
182 while ((c=getopt(argc,argv,
"a:c:de:g:h:o:r:u:s")) != (
char)EOF)
186 {
size_t size =
sizeof(Entity.prot)-1;
187 strncpy(Entity.prot, optarg, size);
188 Entity.prot[size] =
'\0';
192 case 'e': Entity.ueid = atoi(optarg); v2 =
true;
break;
193 case 'g':
SetID(Entity.grps, optarg); v2 =
true;
break;
194 case 'h':
SetID(Entity.host, optarg); v2 =
true;
break;
195 case 'o':
SetID(Entity.vorg, optarg); v2 =
true;
break;
196 case 'r':
SetID(Entity.role, optarg); v2 =
true;
break;
197 case 'u':
SetID(Entity.name, optarg); v2 =
true;
break;
198 case 'c': ConfigFN = optarg;
break;
199 case 's': singleshot =
true;
break;
200 default: sprintf(buff,
"-%c option is invalid.", c);
207 if ((at = index(ConfigFN,
'@')))
208 {*at++ = 0;
if (*at) cfHost = at;}
209 sprintf(buff,
"%s anon@%s", cfProg, cfHost);
215 {std::cerr <<
"testaccess: Initialization failed." <<std::endl;
227 std::cerr <<
"Enter arguments: ";
228 while((lp = Command.
GetLine()) && *lp)
236 {
if (*xp ==
' ') *xp =
'\t';
237 else if (*xp ==
'\'') {*xp++ =
' ';
break;}
244 argnum < maxargs && (argval[argnum]=Command.
GetToken());
247 {
for (
int i = 1; i < argnum; i++)
248 {
char *ap = argval[i];
249 while(*ap) {
if (*ap ==
'\t') *ap =
' '; ap++;}
253 rc |=
DoIt(1, argnum, argval, singleshot=0);
254 std::cerr <<
"Enter arguments: ";
262 int DoIt(
int argpnt,
int argc,
char **argv,
bool singleshot)
264 char *opc, *opv, *path, *result, buff[80];
266 void Usage(
const char *);
273 while(argpnt < argc && *argv[argpnt] ==
'-')
274 {opc = argv[argpnt++];
276 {sprintf(buff,
"%s option value not specified.", opc);
279 opv = argv[argpnt++];
280 if (strlen(opc) != 2)
281 {sprintf(buff,
"%s option is invalid.", opc);
285 {
case 'a': {
size_t size =
sizeof(Entity.prot)-1;
286 strncpy(Entity.prot, opv, size);
287 Entity.prot[size] =
'\0';
290 case 'e': Entity.ueid = atoi(opv); v2 =
true;
break;
291 case 'g':
SetID(Entity.grps, opv); v2 =
true;
break;
292 case 'h':
SetID(Entity.host, opv); v2 =
true;
break;
293 case 'o':
SetID(Entity.vorg, opv); v2 =
true;
break;
294 case 'r':
SetID(Entity.role, opv); v2 =
true;
break;
295 case 'u':
SetID(Entity.name, opv); v2 =
true;
break;
296 default: sprintf(buff,
"%s option is invalid.", opc);
305 {
if (argpnt >= argc)
Usage(
"user not specified.");
306 Entity.name = argv[argpnt++];
307 if (argpnt >= argc)
Usage(
"host not specified.");
308 Entity.host = argv[argpnt++];
315 else Usage(
"operation not specified.");
317 if (!strcmp(argv[argpnt],
"*"))
321 optype =
cmd2op(argv[argpnt++]);
325 if (argpnt >= argc)
Usage(
"path not specified.");
329 if (Entity.host) netAddr.Set(Entity.host, 0);
334 {path = argv[argpnt++];
338 if (optype !=
AOP_Any) result=(auth?(
char *)
"allowed":(
char *)
"denied");
342 std::cout <<result <<
": " <<path <<std::endl;
343 if (singleshot)
return !auth;
356 for (i = 0; i <
opcnt; i++)
358 std::cerr <<
"testaccess: Invalid operation - " <<opname <<std::endl;
368 int i=0, j, k=2, bmax = blen-1;
370 static struct {
XrdAccPrivs pcode;
char plet;} p2l[] =
379 static int p2lnum =
sizeof(p2l)/
sizeof(p2l[0]);
383 {
for (j = 0; j < p2lnum && i < bmax; j++)
384 if (privs & p2l[j].pcode) buff[i++] = p2l[j].plet;
XrdAccAuthorize * XrdAccDefaultAuthorizeObject(XrdSysLogger *lp, const char *cfn, const char *parm, XrdVersionInfo &urVer)
Access_Operation
The following are supported operations.
@ AOP_Delete
rm() or rmdir()
@ AOP_Update
open() r/w or append
@ AOP_Create
open() with create
@ AOP_Any
Special for getting privs.
@ AOP_Stat
exists(), stat()
@ AOP_Rename
mv() for source
@ AOP_Read
open() r/o, prepare()
@ AOP_Excl_Create
open() with O_EXCL|O_CREAT
@ AOP_Excl_Insert
mv() where destination doesn't exist.
Access_Operation cmd2op(char *opname)
int main(int argc, char **argv)
void Usage(const char *msg)
char * PrivsConvert(XrdAccPrivCaps &ctab, char *buff, int blen)
int DoIt(int argpnt, int argc, char **argv, bool singleshot)
void SetID(char *&dest, char *val)
XrdAccAuthorize * Authorize
virtual XrdAccPrivs Access(const XrdSecEntity *Entity, const char *path, const Access_Operation oper, XrdOucEnv *Env=0)=0
static int Export(const char *Var, const char *Val)
int Attach(int FileDescriptor, int bsz=2047)
char * GetToken(int lowcase=0)
XrdVERSIONINFODEF(myVersion, cmsclient, XrdVNUMBER, XrdVERSION)