Changeset 4745:1e974ec321bd in roaraudio


Ignore:
Timestamp:
01/31/11 15:16:14 (13 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

Better auth type oder support (Closes: #6)

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r4740 r4745  
    11v. 0.4beta4 - ? 
    22        * Added support for UNMAPPED volume control (Closes: #55) 
     3        * Better auth type oder support (Closes: #6) 
    34 
    45v. 0.4beta3 - Wed Jan 26 2011 23:26 CET 
  • libroar/auth.c

    r4708 r4745  
    129129 
    130130static int roar_auth_ask_server (struct roar_connection * con, struct roar_auth_message * authmes) { 
    131  struct roar_message   mes; 
    132  char                * header = mes.data; 
    133  int                   ret; 
     131 struct roar_error_frame error_frame; 
     132 struct roar_message     mes; 
     133 char                  * header = mes.data; 
     134 int                     ret; 
    134135 
    135136 memset(&mes, 0, sizeof(struct roar_message)); // make valgrind happy! 
     
    143144 header[3] = authmes->reserved.c[1]; 
    144145 
    145  if ( (ret = roar_req(con, &mes, NULL)) == -1 ) 
    146   return -1; 
    147  
    148  if ( mes.cmd != ROAR_CMD_OK ) 
    149   return -1; 
     146 if ( (ret = roar_req(con, &mes, NULL)) == -1 ) { 
     147  authmes->type = -1; 
     148  return -1; 
     149 } 
     150 
     151 if ( mes.cmd != ROAR_CMD_OK ) { 
     152  ret = -1; 
     153  if ( roar_err_parsemsg(&mes, &error_frame) == -1 ) { 
     154   authmes->type = -1; 
     155   return -1; 
     156  } 
     157 
     158  header = error_frame.data; 
     159  mes.datalen = error_frame.datalen; 
     160 } 
    150161 
    151162 if ( mes.datalen < 4 ) { 
    152163  memset(header+mes.datalen, 0, 4-mes.datalen); 
    153  } 
    154  
    155  authmes->type          = header[0]; 
     164  authmes->type          = -1; 
     165 } else { 
     166  authmes->type          = header[0]; 
     167 } 
     168 
    156169 authmes->stage         = header[1]; 
    157170 authmes->reserved.c[0] = header[2]; 
    158171 authmes->reserved.c[1] = header[3]; 
    159172 
    160  return 0; 
     173 return ret; 
    161174} 
    162175 
     
    171184 
    172185 
    173 static int try_password (struct roar_connection * con) { 
     186static int try_password (struct roar_connection * con, int * next) { 
    174187 struct roar_message mes; 
    175188 struct roar_auth_message authmes; 
    176189 char * pw; 
     190 
     191 // TODO: add support for *next. 
    177192 
    178193 roar_auth_mes_init(&authmes, ROAR_AUTH_T_PASSWORD); 
     
    214229 int ret; 
    215230 int i; 
     231 int cur, next; 
     232 int done; 
    216233 int ltt[] = { 
    217234              ROAR_AUTH_T_TRUST, 
     
    224241 
    225242 for (i = 0; ltt[i] != _EOL; i++) { 
    226   switch (ltt[i]) { 
    227     case ROAR_AUTH_T_PASSWORD: 
    228      if ( (ret = try_password(con)) == -1 ) 
    229       continue; 
     243  next = ltt[i]; 
     244  while (next != -1) { 
     245   done = 1; 
     246 
     247   cur  = next; 
     248   next = -1; 
     249 
     250   switch (cur) { 
     251     case ROAR_AUTH_T_PASSWORD: 
     252      if ( (ret = try_password(con, &next)) == -1 ) 
     253       done = 0; 
     254      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: 
     259      roar_auth_mes_init(&authmes, ltt[i]); 
     260      if ( (ret = roar_auth_ask_server(con, &authmes)) == -1 ) 
     261       done = 0; 
     262 
     263      next = authmes.type; 
    230264     break; 
    231     case ROAR_AUTH_T_TRUST: 
    232     case ROAR_AUTH_T_IDENT: 
    233     case ROAR_AUTH_T_RHOST: 
    234     case ROAR_AUTH_T_NONE: 
    235      roar_auth_mes_init(&authmes, ltt[i]); 
    236      if ( (ret = roar_auth_ask_server(con, &authmes)) == -1 ) 
    237       continue; 
    238     break; 
    239    default: /* Bad error! */ 
    240      return -1; 
    241     break; 
     265    default: /* Bad error! */ 
     266      return -1; 
     267     break; 
     268   } 
     269 
     270   if ( authmes.stage != 0 ) 
     271    done = 0; 
     272 
     273   if ( done ) 
     274    return 0; 
    242275  } 
    243  
    244   if ( authmes.stage != 0 ) 
    245    continue; 
    246  
    247   return 0; 
    248276 } 
    249277 
  • roard/auth.c

    r4739 r4745  
    115115} 
    116116 
    117 int auth_client_ckeck(struct roar_client_server * cs, struct roar_auth_message * authmes) { 
     117int auth_client_ckeck(struct roar_client_server * cs, struct roar_auth_message * authmes, int * next) { 
    118118 struct auth_key * key; 
    119119 int i; 
    120120 int ret; 
    121121 
    122  if ( cs == NULL || authmes == NULL ) 
    123   return -1; 
     122 if ( cs == NULL || authmes == NULL || next == NULL ) 
     123  return -1; 
     124 
     125 *next = -1; 
    124126 
    125127 for (i = 0; i < AUTH_KEYRING_LEN; i++) { 
     
    150152      /* ignore this case and continue */ 
    151153     break; 
    152     case 0: 
     154    case 0: // fatal auth error (server side auth cancel) 
    153155      return 0; 
    154156     break; 
     
    163165  } 
    164166 } 
     167 
     168 // make a better guess: 
     169/* 
     170 if ( authmes->type == ROAR_AUTH_T_PASSWORD ) { 
     171  *next = -1; 
     172 } else { 
     173  *next = ROAR_AUTH_T_PASSWORD; 
     174 } 
     175*/ 
    165176 
    166177 return -1; 
  • roard/include/auth.h

    r4708 r4745  
    7272union auth_typeunion * auth_regkey_simple(int type, enum roard_client_acclev acclev); 
    7373 
    74 int auth_client_ckeck(struct roar_client_server * cs, struct roar_auth_message * authmes); 
    75  
     74int auth_client_ckeck(struct roar_client_server * cs, struct roar_auth_message * authmes, int * next); 
    7675 
    7776int auth_addkey_anonymous(enum roard_client_acclev acclev); 
  • roard/req.c

    r4740 r4745  
    100100 
    101101int req_on_auth        (int client, struct roar_message * mes, char ** data, uint32_t flags[2]) { 
     102 struct roar_error_frame   error_frame; 
     103 void                    * error_data; 
     104 struct roar_message       error_mes; 
    102105 struct roar_client_server * cs; 
    103106 struct roar_auth_message    authmes; 
     107 int next = -1; 
    104108 int ret; 
    105109 
     
    114118                           client, roar_autht2str(authmes.type), authmes.type); 
    115119 
    116  ret = auth_client_ckeck(cs, &authmes); 
    117  
    118  if ( ret != 1 ) 
    119   return -1; 
     120 ret = auth_client_ckeck(cs, &authmes, &next); 
     121 
     122 if ( ret != 1 ) { 
     123  if ( next != -1 ) { 
     124   memset(&authmes, 0, sizeof(authmes)); 
     125 
     126   authmes.type = next; 
     127 
     128   if ( roar_auth_to_mes(&error_mes, NULL, &authmes) == -1 ) 
     129    return -1; 
     130 
     131   if ( roar_err_int(&error_frame) == -1 ) 
     132    return -1; 
     133 
     134   error_frame.ra_errno = ROAR_ERROR_PERM; 
     135   error_frame.datalen  = error_mes.datalen; 
     136 
     137   error_data   = roar_err_buildmsg(mes, &error_frame); 
     138 
     139   memcpy(error_data, error_mes.data, error_mes.datalen); 
     140 
     141   mes->cmd     = ROAR_CMD_ERROR; 
     142   mes->pos     = g_pos; 
     143   return 0; 
     144  } 
     145 
     146  return -1; 
     147 } 
    120148 
    121149 mes->cmd     = ROAR_CMD_OK; 
Note: See TracChangeset for help on using the changeset viewer.