Changeset 4745:1e974ec321bd in roaraudio for libroar/auth.c
- Timestamp:
- 01/31/11 15:16:14 (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libroar/auth.c
r4708 r4745 129 129 130 130 static 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; 134 135 135 136 memset(&mes, 0, sizeof(struct roar_message)); // make valgrind happy! … … 143 144 header[3] = authmes->reserved.c[1]; 144 145 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 } 150 161 151 162 if ( mes.datalen < 4 ) { 152 163 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 156 169 authmes->stage = header[1]; 157 170 authmes->reserved.c[0] = header[2]; 158 171 authmes->reserved.c[1] = header[3]; 159 172 160 return 0;173 return ret; 161 174 } 162 175 … … 171 184 172 185 173 static int try_password (struct roar_connection * con ) {186 static int try_password (struct roar_connection * con, int * next) { 174 187 struct roar_message mes; 175 188 struct roar_auth_message authmes; 176 189 char * pw; 190 191 // TODO: add support for *next. 177 192 178 193 roar_auth_mes_init(&authmes, ROAR_AUTH_T_PASSWORD); … … 214 229 int ret; 215 230 int i; 231 int cur, next; 232 int done; 216 233 int ltt[] = { 217 234 ROAR_AUTH_T_TRUST, … … 224 241 225 242 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; 230 264 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; 242 275 } 243 244 if ( authmes.stage != 0 )245 continue;246 247 return 0;248 276 } 249 277
Note: See TracChangeset
for help on using the changeset viewer.