Changeset 4756:bc0883202f16 in roaraudio


Ignore:
Timestamp:
02/06/11 01:15:32 (11 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

Added support to roarshout to read password form user or file (Closes: #101)

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r4754 r4756  
    55        * Disable more stuff in minimal build (Closes: #104) 
    66        * Added time display to roarvorbis (Closes: #102) 
     7        * Added support to roarshout to read password form user or file (Closes: #101) 
    78 
    89v. 0.4beta3 - Wed Jan 26 2011 23:26 CET 
  • doc/man1/roarshout.1

    r4013 r4756  
    4343Show this help 
    4444 
     45.TP 
     46\fB\-\-pw\-arg\fR 
     47Password is supplied as argument (default). 
     48 
     49.TP 
     50\fB\-\-pw\-ask\fR 
     51Ask user for password interactively. 
     52 
     53.TP 
     54\fB\-\-pw\-dstr\fR 
     55Read password from file. Filename is supplied as normal password argument. 
     56 
    4557.SH "LIBSHOUT OPTIONS" 
    4658 
  • roarclients/roarshout.c

    r4708 r4756  
    4242        "    --codec  CODEC     - Set the codec\n" 
    4343        " -h --help             - Show this help\n" 
     44        "    --pw-arg           - Password is supplied as argument (default).\n" 
     45        "    --pw-ask           - Ask user for password interactively.\n" 
     46        "    --pw-dstr          - Read password from file. Filename is supplied\n" 
     47        "                         as normal password argument.\n" 
    4448       ); 
    4549 
     
    5559} 
    5660 
     61char * read_pw_from_file(char * filename, char * buffer, size_t bufferlen) { 
     62 struct roar_vio_defaults def; 
     63 struct roar_vio_calls file; 
     64 ssize_t len; 
     65 
     66 if (filename == NULL || buffer == NULL) 
     67  return NULL; 
     68 
     69 if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_RDONLY, 0644) == -1 ) 
     70  return NULL; 
     71 
     72 if ( roar_vio_open_dstr(&file, filename, &def, 1) == -1 ) 
     73  return NULL; 
     74 
     75 len = roar_vio_read(&file, buffer, bufferlen - 1); 
     76 
     77 if ( len == -1 ) 
     78  return NULL; 
     79 
     80 // strip newlions. 
     81 for (; buffer[len-1] == '\r' || buffer[len-1] == '\n'; len--); 
     82 
     83 buffer[len] = 0; 
     84 
     85 roar_vio_close(&file); 
     86 
     87 return buffer; 
     88} 
     89 
    5790int main (int argc, char * argv[]) { 
     91 enum { ARG, ASK, DSTR } pw_source = ARG; 
    5892 int    rate     = 44100; 
    5993 int    bits     = 16; 
     
    75109 char buf[BUFSIZE]; 
    76110 shout_t * shout; 
     111 char password_buf[128]; 
    77112 
    78113 for (i = 1; i < argc; i++) { 
     
    89124  } else if ( strcmp(k, "--codec") == 0 ) { 
    90125   codec = roar_str2codec(argv[++i]); 
     126  } else if ( strcmp(k, "--pw-arg") == 0 ) { 
     127   pw_source = ARG; 
     128  } else if ( strcmp(k, "--pw-ask") == 0 ) { 
     129   pw_source = ASK; 
     130  } else if ( strcmp(k, "--pw-dstr") == 0 ) { 
     131   pw_source = DSTR; 
    91132  } else if ( strcmp(k, "-p") == 0 || strcmp(k, "--public") == 0 ) { 
    92133   s_public = 1; 
     
    117158 } 
    118159 
     160 switch (pw_source) { 
     161  case ARG: 
     162    // nothing to do 
     163   break; 
     164  case ASK: 
     165    if ( roar_passwd_simple_ask_pw(&s_pw, "Password for icecast server?", NULL) == -1 ) { 
     166     fprintf(stderr, "Error: unabled to read password from user.\n"); 
     167     return 1; 
     168    } 
     169    strncpy(password_buf, s_pw, sizeof(password_buf)-1); 
     170    roar_mm_free(s_pw); 
     171    password_buf[sizeof(password_buf)-2] = 0; 
     172    s_pw = password_buf; 
     173   break; 
     174  case DSTR: 
     175    if ( (s_pw = read_pw_from_file(s_pw, password_buf, sizeof(password_buf))) == NULL ) { 
     176     fprintf(stderr, "Error: unabled to read password from file.\n"); 
     177     return 1; 
     178    } 
     179   break; 
     180 } 
     181 
    119182 if ( s_server == NULL ) 
    120183  s_server = "localhost"; 
Note: See TracChangeset for help on using the changeset viewer.