Changeset 4788:482fc1a96c7a in roaraudio
- Timestamp:
- 03/11/11 04:10:22 (13 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
ChangeLog
r4779 r4788 12 12 (enumdev only at the moment) (pr1) 13 13 * Added support for a simple trap mechanism (pr1) 14 * Added simple authfile support to roard (pr1) 14 15 15 16 v. 0.4beta3 - Wed Jan 26 2011 23:26 CET -
libroar/auth.c
r4745 r4788 137 137 138 138 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; 140 143 141 144 header[0] = authmes->type; … … 143 146 header[2] = authmes->reserved.c[0]; 144 147 header[3] = authmes->reserved.c[1]; 148 149 if ( authmes->len ) { 150 memcpy(mes.data + 4, authmes->data, authmes->len); 151 } 145 152 146 153 if ( (ret = roar_req(con, &mes, NULL)) == -1 ) { … … 222 229 223 230 return -1; 231 } 232 233 static 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; 224 262 } 225 263 … … 236 274 ROAR_AUTH_T_RHOST, 237 275 // ROAR_AUTH_T_PASSWORD, 276 ROAR_AUTH_T_COOKIE, 238 277 ROAR_AUTH_T_NONE, 239 278 _EOL … … 249 288 250 289 switch (cur) { 251 290 case ROAR_AUTH_T_PASSWORD: 252 291 if ( (ret = try_password(con, &next)) == -1 ) 253 292 done = 0; 254 293 break; 255 256 257 258 294 case ROAR_AUTH_T_TRUST: 295 case ROAR_AUTH_T_IDENT: 296 case ROAR_AUTH_T_RHOST: 297 case ROAR_AUTH_T_NONE: 259 298 roar_auth_mes_init(&authmes, ltt[i]); 260 299 if ( (ret = roar_auth_ask_server(con, &authmes)) == -1 ) … … 262 301 263 302 next = authmes.type; 303 break; 304 case ROAR_AUTH_T_COOKIE: 305 if ( (ret = try_cookie(con, &next)) == -1 ) 306 done = 0; 307 break; 264 308 break; 265 309 default: /* Bad error! */ -
roard/roard.c
r4761 r4788 32 32 RESTART_RETRY, 33 33 SHUTDOWN 34 }; 35 36 enum af_mode { 37 AF_MODE_NONE, 38 AF_MODE_LOAD, 39 AF_MODE_GEN 34 40 }; 35 41 … … 189 195 " --trust-root - Trust root user\n" 190 196 " --no-trust-root - Don't trust root user\n" 197 " --authfile-gen FILE - Generate an new authfile\n" 198 // " --authfile-load FILE - Load an authfile\n" 199 " --authfile-type TYPE - Type of authfile\n" 200 " --authfile-acclev ACCLEV\n" 201 " - Sets the access level for authfile\n" 191 202 ); 192 203 … … 1358 1369 #endif 1359 1370 1371 int add_authfile (const char * file, const char * type, enum af_mode mode, enum roard_client_acclev acclev) { 1372 struct roar_authfile * authfile = NULL; 1373 struct roar_authfile_key * key = NULL; 1374 int af_type = ROAR_AUTHFILE_TYPE_AUTO; 1375 1376 if ( type == NULL ) { 1377 // noop. 1378 } else if ( !strcasecmp(type, "roar") ) { 1379 af_type = ROAR_AUTHFILE_TYPE_ROAR; 1380 } else if ( !strcasecmp(type, "roar") ) { 1381 af_type = ROAR_AUTHFILE_TYPE_ROAR; 1382 } else if ( !strcasecmp(type, "esd") ) { 1383 af_type = ROAR_AUTHFILE_TYPE_ESD; 1384 } else if ( !strcasecmp(type, "pulse") ) { 1385 af_type = ROAR_AUTHFILE_TYPE_PULSE; 1386 } else if ( !strcasecmp(type, "htpasswd") ) { 1387 af_type = ROAR_AUTHFILE_TYPE_HTPASSWD; 1388 } else if ( !strcasecmp(type, "xauth") ) { 1389 af_type = ROAR_AUTHFILE_TYPE_XAUTH; 1390 } else { 1391 ROAR_ERR("add_authfile(*): unknown authfile type '%s'.", type); 1392 return -1; 1393 } 1394 1395 if ( mode == AF_MODE_GEN && af_type == ROAR_AUTHFILE_TYPE_AUTO ) 1396 af_type = ROAR_AUTHFILE_TYPE_ESD; 1397 1398 switch (mode) { 1399 case AF_MODE_NONE: 1400 return 0; 1401 break; 1402 case AF_MODE_GEN: 1403 switch (af_type) { 1404 case ROAR_AUTHFILE_TYPE_ESD: 1405 key = roar_authfile_key_new_random(ROAR_AUTH_T_COOKIE, 16, NULL); 1406 break; 1407 case ROAR_AUTHFILE_TYPE_PULSE: 1408 key = roar_authfile_key_new_random(ROAR_AUTH_T_COOKIE, 256, NULL); 1409 break; 1410 default: 1411 return -1; 1412 break; 1413 } 1414 1415 if ( key == NULL ) { 1416 ROAR_ERR("add_authfile(*): Can not generate key."); 1417 return -1; 1418 } 1419 1420 if ( (authfile = roar_authfile_open(af_type, file, 1, ROAR_AUTHFILE_VERSION_AUTO)) == NULL ) { 1421 roar_authfile_key_unref(key); 1422 return -1; 1423 } 1424 1425 if ( roar_authfile_add_key(authfile, key) == -1 ) { 1426 ROAR_WARN("add_authfile(*): Can not add key to authfile."); 1427 } 1428 1429 if ( auth_addkey_cookie(acclev, key->data, key->len) == -1 ) { 1430 ROAR_WARN("add_authfile(*): Can not add key to internal key storage."); 1431 } 1432 1433 roar_authfile_key_unref(key); 1434 if ( roar_authfile_close(authfile) != 0 ) 1435 return -1; 1436 return 0; 1437 break; 1438 } 1439 1440 return -1; 1441 } 1442 1360 1443 // X11: 1361 1444 #ifdef ROAR_HAVE_LIBX11 … … 1610 1693 enum roard_client_acclev trust_acclev = ACCLEV_ALL; 1611 1694 int trust_root = 1; 1695 char * af_file = NULL; 1696 char * af_type = NULL; 1697 enum af_mode af_mode = AF_MODE_NONE; 1698 enum roard_client_acclev af_acclev = ACCLEV_ALL; 1612 1699 #ifndef ROAR_WITHOUT_DCOMP_LIGHT 1613 1700 int light_channels = LIGHT_CHANNELS_DEFAULT; … … 1890 1977 } else if ( strcmp(k, "--no-trust-root") == 0 ) { 1891 1978 trust_root = 0; 1979 1980 } else if ( strcmp(k, "--authfile-gen") == 0 ) { 1981 _CKHAVEARGS(1); 1982 af_file = argv[++i]; 1983 af_mode = AF_MODE_GEN; 1984 } else if ( strcmp(k, "--authfile-load") == 0 ) { 1985 _CKHAVEARGS(1); 1986 af_file = argv[++i]; 1987 af_mode = AF_MODE_LOAD; 1988 } else if ( strcmp(k, "--authfile-type") == 0 ) { 1989 _CKHAVEARGS(1); 1990 af_type = argv[++i]; 1991 } else if ( strcmp(k, "--authfile-acclev") == 0 ) { 1992 _CKHAVEARGS(1); 1993 af_acclev = clients_str2acclev(argv[++i]); 1892 1994 1893 1995 } else if ( strcmp(k, "--list-cf") == 0 ) { … … 2448 2550 #endif 2449 2551 2552 if ( af_mode != AF_MODE_NONE ) { 2553 if ( add_authfile(af_file, af_type, af_mode, af_acclev) == -1 ) { 2554 ROAR_ERR("main(*): adding authfile '%s' failed!", af_file); 2555 } 2556 } 2557 2450 2558 #ifndef ROAR_WITHOUT_DCOMP_MIXER 2451 2559 if ( m_drv != NULL ) {
Note: See TracChangeset
for help on using the changeset viewer.