Changeset 4788:482fc1a96c7a in roaraudio


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)

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r4779 r4788  
    1212          (enumdev only at the moment) (pr1) 
    1313        * Added support for a simple trap mechanism (pr1) 
     14        * Added simple authfile support to roard (pr1) 
    1415 
    1516v. 0.4beta3 - Wed Jan 26 2011 23:26 CET 
  • 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! */ 
  • roard/roard.c

    r4761 r4788  
    3232 RESTART_RETRY, 
    3333 SHUTDOWN 
     34}; 
     35 
     36enum af_mode { 
     37 AF_MODE_NONE, 
     38 AF_MODE_LOAD, 
     39 AF_MODE_GEN 
    3440}; 
    3541 
     
    189195        " --trust-root          - Trust root user\n" 
    190196        " --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" 
    191202       ); 
    192203 
     
    13581369#endif 
    13591370 
     1371int 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 
    13601443// X11: 
    13611444#ifdef ROAR_HAVE_LIBX11 
     
    16101693 enum roard_client_acclev trust_acclev = ACCLEV_ALL; 
    16111694 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; 
    16121699#ifndef ROAR_WITHOUT_DCOMP_LIGHT 
    16131700 int    light_channels = LIGHT_CHANNELS_DEFAULT; 
     
    18901977  } else if ( strcmp(k, "--no-trust-root") == 0 ) { 
    18911978   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]); 
    18921994 
    18931995  } else if ( strcmp(k, "--list-cf") == 0 ) { 
     
    24482550#endif 
    24492551 
     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 
    24502558#ifndef ROAR_WITHOUT_DCOMP_MIXER 
    24512559 if ( m_drv != NULL ) { 
Note: See TracChangeset for help on using the changeset viewer.