From: Patrick M. <ume...@us...> - 2007-05-30 18:11:59
|
Update of /cvsroot/radmind/radmind In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv32319 Modified Files: command.c ktcheck.c transcript.c transcript.h Log Message: Added support for minus transcripts and special files in command files. Index: transcript.h =================================================================== RCS file: /cvsroot/radmind/radmind/transcript.h,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** transcript.h 17 Feb 2006 20:30:01 -0000 1.40 --- transcript.h 30 May 2007 18:11:49 -0000 1.41 *************** *** 49,54 **** --- 49,56 ---- struct transcript { struct transcript *t_next; + struct transcript *t_prev; struct pathinfo t_pinfo; int t_type; + int t_num; char t_fullname[ MAXPATHLEN ]; char t_shortname[ MAXPATHLEN ]; Index: transcript.c =================================================================== RCS file: /cvsroot/radmind/radmind/transcript.c,v retrieving revision 1.117 retrieving revision 1.118 diff -C2 -d -r1.117 -r1.118 *** transcript.c 23 Feb 2007 20:21:14 -0000 1.117 --- transcript.c 30 May 2007 18:11:49 -0000 1.118 *************** *** 29,32 **** --- 29,35 ---- int read_kfile( char *kfile, int location ); + static void t_new( int type, char *fullname, char *shortname, char *kfile ); + static void t_remove( int type, char *shortname ); + static void t_display( void ); struct transcript *tran_head = NULL; *************** *** 34,38 **** extern int edit_path; extern int case_sensitive; - static int foundspecial = 0; static char *kdir; static struct list *kfile_list; --- 37,40 ---- *************** *** 726,729 **** --- 728,735 ---- new->t_next = tran_head; + if ( tran_head != NULL ) { + tran_head->t_prev = new; + new->t_num = new->t_next->t_num + 1; + } tran_head = new; *************** *** 731,734 **** --- 737,796 ---- } + static void + t_remove( int type, char *shortname ) + { + struct transcript *cur, *next = NULL; + + cur = tran_head; + while ( cur->t_type != T_NULL ) { + next = cur->t_next; + if (( cur->t_type == type ) + && ( strcmp( cur->t_shortname, shortname ) == 0 )) { + if ( cur == tran_head ) { + tran_head = cur->t_next; + free( cur ); + } else { + cur->t_prev->t_next = cur->t_next; + cur->t_next->t_prev = cur->t_prev; + free( cur ); + } + } + cur = next; + } + return; + } + + static void + t_display( void ) + { + struct transcript *cur = NULL; + + for ( cur = tran_head; cur != NULL; cur = cur->t_next ) { + printf( "%d: ", cur->t_num ); + switch( cur->t_type ) { + case T_POSITIVE: + printf( "p %s\n", cur->t_shortname ); + break; + + case T_NEGATIVE: + printf( "n %s\n", cur->t_shortname ); + break; + + case T_SPECIAL: + printf( "s %s\n", cur->t_shortname ); + break; + + case T_NULL: + printf( "NULL\n" ); + break; + + default: + printf( "? %s\n", cur->t_shortname ); + break; + } + } + return; + } + void transcript_init( char *kfile, int location ) *************** *** 776,780 **** } ! if ( foundspecial && ( location == K_CLIENT )) { /* open the special transcript if there were any special files */ if ( strlen( kdir ) + strlen( special ) + 2 > MAXPATHLEN ) { --- 838,842 ---- } ! if (( list_size( special_list ) > 0 ) && ( location == K_CLIENT )) { /* open the special transcript if there were any special files */ if ( strlen( kdir ) + strlen( special ) + 2 > MAXPATHLEN ) { *************** *** 798,802 **** read_kfile( char *kfile, int location ) { ! int length, ac, linenum = 0; char line[ MAXPATHLEN ]; char fullpath[ MAXPATHLEN ]; --- 860,864 ---- read_kfile( char *kfile, int location ) { ! int length, ac, linenum = 0, minus = 0; char line[ MAXPATHLEN ]; char fullpath[ MAXPATHLEN ]; *************** *** 824,827 **** --- 886,897 ---- } + if ( *av[ 0 ] == '-' ) { + minus = 0; + av++; + ac--; + } else { + minus = 1; + } + if ( ac != 2 ) { fprintf( stderr, *************** *** 866,906 **** switch( *av[ 0 ] ) { case 'k': /* command file */ ! if ( list_check( kfile_list, fullpath )) { ! fprintf( stderr, ! "command file %s: line %d: command file loop: %s already included\n", ! kfile, linenum, av[ 1 ] ); ! return( -1 ); ! } ! if ( list_insert( kfile_list, fullpath ) != 0 ) { ! perror( "list_insert" ); return( -1 ); } - if ( read_kfile( fullpath, location ) != 0 ) { - return( -1 ); - } break; case 'n': /* negative */ ! t_new( T_NEGATIVE, fullpath, av[ 1 ], kfile ); break; case 'p': /* positive */ ! t_new( T_POSITIVE, fullpath, av[ 1 ], kfile ); break; case 'x': /* exclude */ ! t_new( T_EXCLUDE, fullpath, av[ 1 ], kfile ); break; case 's': /* special */ ! foundspecial++; ! if ( location == K_SERVER ) { ! if ( list_insert( special_list, av[ 1 ] ) != 0 ) { ! perror( "list_insert" ); ! return( -1 ); } } ! continue; default: --- 936,1001 ---- switch( *av[ 0 ] ) { case 'k': /* command file */ ! if ( minus ) { ! /* Error on minus command files for now */ ! fprintf( stderr, "command file %s: line %d: " ! "minus 'k' not supported\n", kfile, linenum ); return( -1 ); + } else { + if ( list_check( kfile_list, fullpath )) { + fprintf( stderr, + "command file %s: line %d: command file loop: %s already included\n", + kfile, linenum, av[ 1 ] ); + return( -1 ); + } + if ( list_insert( kfile_list, fullpath ) != 0 ) { + perror( "list_insert" ); + return( -1 ); + } + if ( read_kfile( fullpath, location ) != 0 ) { + return( -1 ); + } } break; case 'n': /* negative */ ! if ( minus ) { ! t_remove( T_NEGATIVE, av[ 1 ] ); ! } else { ! t_new( T_NEGATIVE, fullpath, av[ 1 ], kfile ); ! } break; case 'p': /* positive */ ! if ( minus ) { ! t_remove( T_POSITIVE, av[ 1 ] ); ! } else { ! t_new( T_POSITIVE, fullpath, av[ 1 ], kfile ); ! } break; case 'x': /* exclude */ ! if ( minus ) { ! t_remove( T_EXCLUDE, av[ 1 ] ); ! } else { ! t_new( T_EXCLUDE, fullpath, av[ 1 ], kfile ); ! } break; case 's': /* special */ ! if ( minus ) { ! if ( list_check( special_list, av[ 1 ] )) { ! list_remove( special_list, av[ 1 ] ); } + } else { + if ( !list_check( special_list, av[ 1 ] )) { + if ( list_insert( special_list, av[ 1 ] ) != 0 ) { + perror( "list_insert" ); + return( -1 ); + } + } + } ! break; default: Index: command.c =================================================================== RCS file: /cvsroot/radmind/radmind/command.c,v retrieving revision 1.137 retrieving revision 1.138 diff -C2 -d -r1.137 -r1.138 *** command.c 23 Feb 2007 20:21:14 -0000 1.137 --- command.c 30 May 2007 18:11:49 -0000 1.138 *************** *** 1355,1358 **** --- 1355,1369 ---- } + /* Skip minus lines in command files for now. Eventually, + * the server should not give access to command files, special files + * and transcripts that have been ultimately removed with a '-'. + * This is difficult as ktcheck reads command files line by line + * and will request info on a file that might be removed with a + * later '-'. + */ + if ( *av[ 0 ] == '-' ) { + continue; + } + if ( ac != 2 ) { syslog( LOG_ERR, "%s: line %d: invalid number of arguments", Index: ktcheck.c =================================================================== RCS file: /cvsroot/radmind/radmind/ktcheck.c,v retrieving revision 1.119 retrieving revision 1.120 diff -C2 -d -r1.119 -r1.120 *** ktcheck.c 23 Feb 2007 20:21:14 -0000 1.119 --- ktcheck.c 30 May 2007 18:11:49 -0000 1.120 *************** *** 71,75 **** const EVP_MD *md; SSL_CTX *ctx; ! struct list *special_list, *kfile_list, *kfile_seen; extern struct timeval timeout; --- 71,75 ---- const EVP_MD *md; SSL_CTX *ctx; ! struct list *special_list, *kfile_seen; extern struct timeval timeout; *************** *** 545,549 **** char tempfile[ MAXPATHLEN ]; struct servent *se; - struct node *node; char **capa = NULL; /* capabilities */ --- 545,548 ---- *************** *** 675,682 **** exit( 2 ); } - if (( kfile_list = list_new( )) == NULL ) { - perror( "list_new" ); - exit( 2 ); - } if (( kfile_seen = list_new( )) == NULL ) { perror( "list_new" ); --- 674,677 ---- *************** *** 755,768 **** } ! /* Parse any included command files */ ! while (( node = list_pop_head( kfile_list )) != NULL ) { ! if ( read_kfile( node->n_path ) != 0 ) { ! exit( 2 ); ! } ! free( node ); ! ! if ( !update && change ) { ! exit( 1 ); ! } } --- 750,758 ---- } ! /* Exit here if there's already been a change to avoid processing ! * the special transcript. ! */ ! if ( !update && change ) { ! exit( 1 ); } *************** *** 903,907 **** read_kfile( char * kfile ) { ! int ac; char **av; char line[ MAXPATHLEN ]; --- 893,897 ---- read_kfile( char * kfile ) { ! int ac, minus = 0; char **av; char line[ MAXPATHLEN ]; *************** *** 929,932 **** --- 919,936 ---- } + /* Skip non-special minus lines */ + if ( *av[ 0 ] == '-' ) { + if ( *av[ 1 ] == 's' ) { + minus = 1; + av++; + ac--; + } else { + continue; + } + } else { + /* Set incase previous line was a minus */ + minus = 0; + } + if ( ac != 2 ) { fprintf( stderr, "%s: %d: invalid command line\n", *************** *** 943,955 **** } if ( !list_check( kfile_seen, path )) { - if ( list_insert_tail( kfile_list, path ) != 0 ) { - perror( "list_insert_tail" ); - goto error; - } if ( list_insert_tail( kfile_seen, path ) != 0 ) { perror( "list_insert_tail" ); goto error; } } switch( check( sn, "COMMAND", av[ ac - 1] )) { case 0: --- 947,959 ---- } if ( !list_check( kfile_seen, path )) { if ( list_insert_tail( kfile_seen, path ) != 0 ) { perror( "list_insert_tail" ); goto error; } + if ( read_kfile( path ) != 0 ) { + exit( 2 ); + } } + switch( check( sn, "COMMAND", av[ ac - 1] )) { case 0: *************** *** 969,976 **** case 's': /* Added special file if it's not already in the list */ ! if ( !list_check( special_list, av[ 1 ] )) { ! if ( list_insert( special_list, av[ 1 ] ) != 0 ) { ! perror( "list_insert" ); ! exit( 2 ); } } --- 973,986 ---- case 's': /* Added special file if it's not already in the list */ ! if ( minus ) { ! if ( list_check( special_list, av[ 1 ] )) { ! list_remove( special_list, av[ 1 ] ); ! } ! } else { ! if ( !list_check( special_list, av[ 1 ] )) { ! if ( list_insert( special_list, av[ 1 ] ) != 0 ) { ! perror( "list_insert" ); ! exit( 2 ); ! } } } |