Changeset 4478:b5ee5b9431ae in roaraudio


Ignore:
Timestamp:
10/11/10 14:32:08 (14 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

implemented trust and cookie auth

Location:
roard
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • roard/auth.c

    r4476 r4478  
    4444 // test password for API tests... 
    4545 auth_addkey_password(ACCLEV_ALL, "test"); 
     46#endif 
     47 
     48#if 0 
     49 // test trust for API tests... 
     50 auth_addkey_trust(ACCLEV_ALL, -1, 0, getuid()+1, -1, getgid()+1, -1); 
    4651#endif 
    4752 
     
    6974} 
    7075 
     76static int _ck_cookie(struct auth_key * key, struct roar_auth_message * authmes) { 
     77 if ( key->at_data.cookie.len == authmes->len ) { 
     78  if ( memcmp(key->at_data.cookie.cookie, authmes->data, authmes->len) ) { 
     79   return -1; 
     80  } else { 
     81   return 1; 
     82  } 
     83 } 
     84 
     85 return -1; 
     86} 
     87 
    7188static int _ck_password(struct auth_key * key, struct roar_auth_message * authmes) { 
    7289 size_t len = strlen(key->at_data.password.password); 
     
    8198  } 
    8299 } 
     100 
     101 return -1; 
     102} 
     103 
     104static int _ck_trust(struct auth_key * key, struct roar_auth_message * authmes, struct roar_client_server * cs) { 
     105 struct at_trust * t = &(key->at_data.trust); 
     106 size_t i; 
     107 
     108 // we ship pids at the moment as cs does not contain a verifyed one. 
     109 
     110 for (i = 0; i < t->uids_len; i++) 
     111  if ( t->uids[i] == ROAR_CLIENT(cs)->uid ) 
     112   return 1; 
     113 
     114 for (i = 0; i < t->gids_len; i++) 
     115  if ( t->gids[i] == ROAR_CLIENT(cs)->gid ) 
     116   return 1; 
    83117 
    84118 return -1; 
     
    103137      ret = _ck_password(key, authmes); 
    104138     break; 
     139    case ROAR_AUTH_T_COOKIE: 
     140      ret = _ck_cookie(key, authmes); 
     141     break; 
    105142    case ROAR_AUTH_T_TRUST: 
    106     case ROAR_AUTH_T_COOKIE: 
     143      ret = _ck_trust(key, authmes, cs); 
     144     break; 
    107145    case ROAR_AUTH_T_SYSUSER: 
    108146    case ROAR_AUTH_T_RHOST: 
     
    150188} 
    151189 
     190int auth_addkey_cookie(enum roard_client_acclev acclev, const void * cookie, const size_t len) { 
     191 union auth_typeunion * key; 
     192 
     193 if ( (key = auth_regkey_simple(ROAR_AUTH_T_COOKIE, acclev)) == NULL ) 
     194  return -1; 
     195 
     196 key->cookie.cookie = (void*)cookie; 
     197 key->cookie.len    = len; 
     198 
     199 return 0; 
     200} 
     201 
     202int auth_addkey_trust(enum roard_client_acclev acclev, ...) { 
     203 union auth_typeunion * key; 
     204 size_t i; 
     205 va_list va; 
     206 pid_t pid; 
     207 uid_t uid; 
     208 gid_t gid; 
     209 int err = 0; 
     210 
     211 if ( (key = auth_regkey_simple(ROAR_AUTH_T_TRUST, acclev)) == NULL ) 
     212  return -1; 
     213 
     214 // zerosize all counters. 
     215 memset(key, 0, sizeof(union auth_typeunion)); 
     216 
     217 va_start(va, acclev); 
     218 
     219 do { // eval block we can leave with continue. 
     220 
     221#define _block(var,type,array)  i = 0; \ 
     222                                do { \ 
     223                                 if ( i == AT_TRUST_MAX_ENTRYS ) { err = 1; continue; } \ 
     224                                 var = va_arg(va, type); \ 
     225                                 key->trust.array[i] = var; \ 
     226                                 i++; \ 
     227                                } while (var != -1); \ 
     228                                if ( err ) continue; \ 
     229                                key->trust.array ## _len = i; 
     230 
     231 
     232 _block(pid, pid_t, pids); 
     233 _block(uid, uid_t, uids); 
     234 _block(gid, gid_t, gids); 
     235 
     236#undef _block 
     237 
     238 } while(0); 
     239 
     240 va_end(va); 
     241 
     242 if ( !err ) 
     243  return 0; 
     244 
     245 memset(key, 0, sizeof(union auth_typeunion)); 
     246 
     247 return -1; 
     248} 
     249 
    152250//ll 
  • roard/include/auth.h

    r4476 r4478  
    7777int auth_addkey_anonymous(enum roard_client_acclev acclev); 
    7878int auth_addkey_password(enum roard_client_acclev acclev, const char * password); 
     79int auth_addkey_cookie(enum roard_client_acclev acclev, const void * cookie, const size_t len); 
     80int auth_addkey_trust(enum roard_client_acclev acclev, ...); 
    7981 
    8082#endif 
Note: See TracChangeset for help on using the changeset viewer.