Changeset 4788:482fc1a96c7a in roaraudio for libroar


Ignore:
Timestamp:
03/11/11 04:10:22 (13 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

Added simple authfile support to roard (pr1)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroar/auth.c

    r4745 r4788  
    137137 
    138138 mes.cmd     = ROAR_CMD_AUTH; 
    139  mes.datalen = 4; 
     139 mes.datalen = 4 + authmes->len; 
     140 
     141 if ( mes.datalen > sizeof(mes.data) ) 
     142  return -1; 
    140143 
    141144 header[0] = authmes->type; 
     
    143146 header[2] = authmes->reserved.c[0]; 
    144147 header[3] = authmes->reserved.c[1]; 
     148 
     149 if ( authmes->len ) { 
     150  memcpy(mes.data + 4, authmes->data, authmes->len); 
     151 } 
    145152 
    146153 if ( (ret = roar_req(con, &mes, NULL)) == -1 ) { 
     
    222229 
    223230 return -1; 
     231} 
     232 
     233static int try_cookie (struct roar_connection * con, int * next) { 
     234 struct roar_libroar_config * config = roar_libroar_get_config(); 
     235 struct roar_auth_message authmes; 
     236 struct roar_authfile * authfile; 
     237 struct roar_authfile_key * key; 
     238 int idx; 
     239 int done = 0; 
     240 
     241 roar_auth_mes_init(&authmes, ROAR_AUTH_T_COOKIE); 
     242 
     243 if ( (authfile = roar_authfile_open(ROAR_AUTHFILE_TYPE_AUTO, config->authfile, 0, ROAR_AUTHFILE_VERSION_AUTO)) == NULL ) 
     244  return -1; 
     245 
     246 for (idx = 0; !done; idx++) { 
     247  if ( (key = roar_authfile_lookup_key(authfile, ROAR_AUTH_T_COOKIE, idx, NULL)) == NULL ) 
     248   break; 
     249 
     250  authmes.data = key->data; 
     251  authmes.len  = key->len; 
     252 
     253  if ( roar_auth_ask_server(con, &authmes) != -1 ) 
     254   done = 1; 
     255 
     256  roar_authfile_key_unref(key); 
     257 } 
     258 
     259 roar_authfile_close(authfile); 
     260 
     261 return done ? 0 : -1; 
    224262} 
    225263 
     
    236274              ROAR_AUTH_T_RHOST, 
    237275//              ROAR_AUTH_T_PASSWORD, 
     276              ROAR_AUTH_T_COOKIE, 
    238277              ROAR_AUTH_T_NONE, 
    239278              _EOL 
     
    249288 
    250289   switch (cur) { 
    251      case ROAR_AUTH_T_PASSWORD: 
     290    case ROAR_AUTH_T_PASSWORD: 
    252291      if ( (ret = try_password(con, &next)) == -1 ) 
    253292       done = 0; 
    254293      break; 
    255      case ROAR_AUTH_T_TRUST: 
    256      case ROAR_AUTH_T_IDENT: 
    257      case ROAR_AUTH_T_RHOST: 
    258      case ROAR_AUTH_T_NONE: 
     294    case ROAR_AUTH_T_TRUST: 
     295    case ROAR_AUTH_T_IDENT: 
     296    case ROAR_AUTH_T_RHOST: 
     297    case ROAR_AUTH_T_NONE: 
    259298      roar_auth_mes_init(&authmes, ltt[i]); 
    260299      if ( (ret = roar_auth_ask_server(con, &authmes)) == -1 ) 
     
    262301 
    263302      next = authmes.type; 
     303     break; 
     304    case ROAR_AUTH_T_COOKIE: 
     305      if ( (ret = try_cookie(con, &next)) == -1 ) 
     306       done = 0; 
     307      break; 
    264308     break; 
    265309    default: /* Bad error! */ 
Note: See TracChangeset for help on using the changeset viewer.