From: Andrew M. <fit...@us...> - 2006-06-06 14:24:46
|
Update of /cvsroot/radmind/radmind-assistant/rte In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv21643 Modified Files: RTEAuditor.m Log Message: Using mode_t and bitwise comparisons instead of strings. Index: RTEAuditor.m =================================================================== RCS file: /cvsroot/radmind/radmind-assistant/rte/RTEAuditor.m,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RTEAuditor.m 7 Mar 2005 14:53:15 -0000 1.2 --- RTEAuditor.m 6 Jun 2006 13:58:27 -0000 1.3 *************** *** 6,9 **** --- 6,13 ---- #import "RTEAuditor.h" + #include <sys/stat.h> + + //define WORLDWRITABLE ( S_IWUSR | S_IWGRP | S_IWOTH ) + @implementation RTEAuditor *************** *** 45,50 **** - ( BOOL )auditLine: ( NSMutableDictionary * )line { ! NSString *owner, *mode; NSString *objectType = @"unknown"; int type; --- 49,55 ---- - ( BOOL )auditLine: ( NSMutableDictionary * )line { ! NSString *owner, *modeString; NSString *objectType = @"unknown"; + mode_t mode; int type; *************** *** 54,81 **** owner = [ line objectForKey: @"owner" ]; ! mode = [ line objectForKey: @"perm" ]; type = [[ line objectForKey: @"type" ] characterAtIndex: 0 ]; if ( [ owner isEqualToString: @"0" ] ) { ! switch ( [ mode characterAtIndex: 0 ] ) { ! case '2': ! [ line setObject: NSLocalizedString( @"setgid root", @"setgid root" ) forKey: @"RTEAuditorAnalysis" ]; return( YES ); ! ! case '4': ! [ line setObject: NSLocalizedString( @"setuid root", @"setuid root" ) forKey: @"RTEAuditorAnalysis" ]; return( YES ); - default: - break; } } ! /* XXX surely there's a better way to do this. later. */ ! if ( [ mode isEqualToString: @"0777" ] || ! [ mode isEqualToString: @"0666" ] || ! [ mode isEqualToString: @"0333" ] || ! [ mode isEqualToString: @"0222" ] ) { switch ( type ) { default: --- 59,90 ---- owner = [ line objectForKey: @"owner" ]; ! modeString = [ line objectForKey: @"perm" ]; type = [[ line objectForKey: @"type" ] characterAtIndex: 0 ]; + + if ( modeString == nil || [ modeString characterAtIndex: 0 ] == '-' ) { + return( NO ); + } + + errno = 0; + mode = strtol( [ modeString UTF8String ], NULL, 8 ); + if ( errno ) { + NSLog( @"strtol %@: %s", modeString, strerror( errno )); + return( NO ); + } if ( [ owner isEqualToString: @"0" ] ) { ! if ( mode & S_ISUID ) { ! [ line setObject: NSLocalizedString( @"setuid root", @"setuid root" ) forKey: @"RTEAuditorAnalysis" ]; return( YES ); ! } ! if ( mode & S_ISGID ) { ! [ line setObject: NSLocalizedString( @"setgid root", @"setgid root" ) forKey: @"RTEAuditorAnalysis" ]; return( YES ); } } ! if (( mode & S_IWOTH ) && !( mode & S_ISVTX )) { switch ( type ) { default: |