#include #include #include #include /* #include "gaa.h" #include "gaa_simple.h" #include "gaa_util.h" #include "gaa_private.h" */ #include "cond_eval.h" #define MAX_ERROR_LENGTH 100 typedef struct { char *malloc_content; char *curtoken; char *error; } method_parser; typedef enum { MA_ERROR=0, MA_ALLOW=1, MA_DENY=2 } method_answer; void method_initparser(method_parser *p, char *str) { p->malloc_content=(char *)malloc(strlen(str)*sizeof(char)+1); strcpy(p->malloc_content,str); p->curtoken=p->malloc_content; p->error=(char *)malloc(MAX_ERROR_LENGTH*sizeof(char)+1); } void method_freeparser(method_parser *p) { free(p->malloc_content); free(p->error); } void method_parsererror(method_parser *p, const char *fmt, /*args*/ ...) { va_list ap; va_start(ap, fmt); /* measure the required size */ vsprintf(p->error, fmt, ap); va_end(ap); } char *method_nexttoken(method_parser *p, char delim) { char *ret=p->curtoken; char *temp=p->curtoken; while (*temp!='\0' && *temp!=delim) { temp++; } if (*temp==delim) { *temp='\0'; p->curtoken=temp+1; } else { p->curtoken=temp; } temp--; while (*temp==' ' || *temp=='\t' || *temp=='\n') { *temp='\0'; temp--; } while (*ret==' ' || *ret=='\t' || *ret=='\n') { ret++; } return ret; } method_answer method_do_parse(method_parser *p, char *method) { char *token=method_nexttoken(p,','); while (*token!='\0') { if (strcmp(token,"*")==0) { return MA_ALLOW; } else if (strcasecmp(token,method)==0) { return MA_ALLOW; } token=method_nexttoken(p,','); } return MA_DENY; } typedef struct { char *method; } method_info; gaa_status cb_check_cond_access_method (gaa_ptr gaa, gaa_sc_ptr sc, gaa_condition *cond, gaa_time_period *valid_time, gaa_request_right_ptr right, gaa_status rstatus, gaa_string_data estatus, gaa_status *output_flags, void *params) { method_parser p; gaa_status ret=GAA_S_SUCCESS; method_answer answer; method_info *mi=(method_info *)get_request_option(right,"method",cond->authority); if (mi==0) { return GAA_S_INVALID_ARG; } if (mi->method==0) { return GAA_S_INVALID_ARG; } *output_flags |= GAA_COND_FLG_EVALUATED; method_initparser(&p, cond->value); answer=method_do_parse(&p, mi->method); if (answer==MA_ERROR) { ret=GAA_S_POLICY_PARSING_FAILURE; } else if (answer==MA_ALLOW) { *output_flags |= GAA_COND_FLG_MET; } else //MA_DENY { //none } method_freeparser(&p); return ret; }