From: Andrew M. <fit...@us...> - 2006-08-02 00:00:13
|
Update of /cvsroot/radmind/radmind-assistant In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv1098 Modified Files: rumd.c Log Message: If we can't read prefs from global domain, try reading from user domain. Use fileno() rather than passing fd and FILE pointer to readline(). Index: rumd.c =================================================================== RCS file: /cvsroot/radmind/radmind-assistant/rumd.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** rumd.c 22 Nov 2005 20:19:46 -0000 1.8 --- rumd.c 2 Aug 2006 00:00:09 -0000 1.9 *************** *** 22,25 **** --- 22,26 ---- #define RADMIND_PREFS CFSTR( "/Library/Preferences/edu.umich.radmind" ) #define OLD_PREFS CFSTR("/Library/Preferences/edu.umich.radmindassistant") + #define USER_PREFS CFSTR( "edu.umich.radmindassistant" ) #define HOST_PREF CFSTR( "radmindhost" ) #define TLS_PREF CFSTR( "tlslevel" ) *************** *** 30,34 **** void term( int ); int inprogress( void ); ! char *readline( int, FILE * ); int hup_signal = 0; --- 31,35 ---- void term( int ); int inprogress( void ); ! char *readline( FILE * ); int hup_signal = 0; *************** *** 69,81 **** char * ! readline( int fd, FILE *of ) { static char buf[ LINE_MAX ]; fd_set readmask; ! int len; memset( buf, '\0', sizeof( buf )); setbuf( of, NULL ); /* read the first line of output, if any, from ktcheck */ --- 70,87 ---- char * ! readline( FILE *of ) { static char buf[ LINE_MAX ]; fd_set readmask; ! int fd, len; ! ! if ( of == NULL ) { ! return( NULL ); ! } memset( buf, '\0', sizeof( buf )); setbuf( of, NULL ); + fd = fileno( of ); /* read the first line of output, if any, from ktcheck */ *************** *** 124,128 **** static void ! read_prefs() { CFArrayRef keys = NULL; --- 130,134 ---- static void ! read_prefs( void ) { CFArrayRef keys = NULL; *************** *** 132,135 **** --- 138,142 ---- CFStringRef path; CFStringRef global_id = RADMIND_PREFS; + CFStringRef consoleUser = NULL; const CFStringRef user = kCFPreferencesCurrentUser; const CFStringRef host = kCFPreferencesAnyHost; *************** *** 139,142 **** --- 146,150 ---- }; int lvl; + uid_t uid; if (( keys = CFArrayCreate( kCFAllocatorDefault, *************** *** 149,158 **** if ( CFDictionaryGetCount( dict ) == 0 || dict == NULL ) { /* try old prefs instead */ ! CFRelease( dict ); global_id = OLD_PREFS; dict = CFPreferencesCopyMultiple( keys, global_id, user, host ); if ( CFDictionaryGetCount( dict ) == 0 || dict == NULL ) { ! /* use default values */ ! syslog( LOG_ERR, "CFPreferencesCopyMultiple failed" ); } } --- 157,202 ---- if ( CFDictionaryGetCount( dict ) == 0 || dict == NULL ) { /* try old prefs instead */ ! if ( dict ) { ! CFRelease( dict ); dict = NULL; ! } ! global_id = OLD_PREFS; dict = CFPreferencesCopyMultiple( keys, global_id, user, host ); if ( CFDictionaryGetCount( dict ) == 0 || dict == NULL ) { ! if ( dict ) { ! CFRelease( dict ); dict = NULL; ! } ! ! /* one last try before giving up. grab prefs from console user */ ! if (( consoleUser = SCDynamicStoreCopyConsoleUser( NULL, ! &uid, NULL )) != NULL ) { ! /* drop privileges */ ! if ( seteuid( uid ) != 0 ) { ! syslog( LOG_ERR, "seteuid %d: %m", uid ); ! } else { ! global_id = USER_PREFS; ! dict = CFPreferencesCopyMultiple( keys, ! global_id, user, host ); ! ! /* resume running as root */ ! if ( seteuid( 0 ) != 0 ) { ! syslog( LOG_ERR, "seteuid 0: %m. Exiting." ); ! exit( 2 ); ! } ! ! if ( CFDictionaryGetCount( dict ) == 0 || dict == NULL ) { ! /* no good, use defaults */ ! syslog( LOG_ERR, "CFPreferencesCopyMultiple failed" ); ! syslog( LOG_ERR, "Using default values" ); ! ! if ( dict ) { ! CFRelease( dict ); dict = NULL; ! } ! } ! } ! } ! if ( consoleUser != NULL ) { ! CFRelease( consoleUser ); ! } } } *************** *** 471,479 **** if ( SCNetworkCheckReachabilityByName( radmind_server, &flags ) == FALSE ) { ! syslog( LOG_ERR, "SCNetworkCheckReachabilityByName failed\n" ); continue; } if ( ! ( flags & kSCNetworkFlagsReachable )) { ! syslog( LOG_ERR, "Network not available\n" ); continue; } --- 515,523 ---- if ( SCNetworkCheckReachabilityByName( radmind_server, &flags ) == FALSE ) { ! syslog( LOG_ERR, "SCNetworkCheckReachabilityByName failed" ); continue; } if ( ! ( flags & kSCNetworkFlagsReachable )) { ! syslog( LOG_ERR, "Network not available" ); continue; } *************** *** 545,549 **** } } else { ! line = readline( ofd[ 0 ], of ); if ( fclose( of ) != 0 ) { syslog( LOG_ERR, "fclose: %m" ); --- 589,593 ---- } } else { ! line = readline( of ); if ( fclose( of ) != 0 ) { syslog( LOG_ERR, "fclose: %m" ); |