/* see if we know this guy... */ char *get_welcome_msg(char *username) { char line[256]; struct passwd *pw; char *welcome_msg = NULL; char *user = NULL; char *path; FILE *fp; if (!username) return NULL; /* see if this guy has a .qingy_welcome in the home */ pw = getpwnam(username); path = StrApp((char **)NULL, pw->pw_dir, "/.qingy_welcome", (char*)NULL); if (!access(path, F_OK)) { fp = fopen(path, "r"); free(path); if (fp) { fgets(line, 255, fp); welcome_msg = strdup(strtok(line, "\n")); fclose(fp); if (welcome_msg) return welcome_msg; } } path = StrApp((char**)NULL, datadir, "welcomes", (char*)NULL); fp = fopen(path, "r"); free(path); if (fp) { while (fgets(line, 255, fp)) { user = strtok(line, " \t"); if (!strcmp(user, username)) { welcome_msg = strdup(strtok(NULL, "\n")); break; } } fclose(fp); } if (!welcome_msg) return strdup(welcome_message); return welcome_msg; }
int set_last_user(char *user) { char *fileOUT; char *line = NULL; size_t len = 0; FILE *fpIN; FILE *fpOUT; if (last_user_policy == LU_NONE) return 1; if (!user) return 0; fileOUT = StrApp((char**)NULL, last_user, "-new", (char*)NULL); fpIN = fopen(last_user, "r"); fpOUT = fopen(fileOUT, "w"); if (!fpOUT) { if (fpIN) fclose(fpIN); free(fileOUT); return 0; } fprintf(fpOUT, "%s %d\n", user, current_tty); if (fpIN) { while (getline(&line, &len, fpIN) != -1) { char name[strlen(line) + 1]; int tty; if (sscanf(line, "%s%d", name, &tty) == 2) if (current_tty != tty) fprintf(fpOUT, "%s", line); } fclose(fpIN); } fclose(fpOUT); remove(last_user); rename(fileOUT, last_user); free(fileOUT); return 1; }
void yyerror(char *error) { WRITELOG(ERROR, "Error in configuration file %s:\n", file_error); WRITELOG(ERROR, "%s.\n", error); free(x_sessions_directory); free(text_sessions_directory); free(xinit); free(font); free(theme_dir); free(screensavers_dir); free(themes_dir); set_default_paths(); theme_dir = StrApp((char**)NULL, themes_dir, "/default/", (char*)NULL); settings_parse_error = 1; }
/* generic function to load a cursor shape */ void SetCursor(dfb_cursor_t **cursor, IDirectFB *dfb, cursor_t *cursor_data, float x_ratio, float y_ratio) { IDirectFBSurface *temp_surf; dfb_cursor_t *temp_curs; char *my_path; if (!cursor) return; if (!cursor_data) return; if (!cursor_data->enable) { if (*cursor) { free((*cursor)->surface); free(*cursor); *cursor = NULL; } return; } my_path = StrApp((char**)NULL, theme_dir, "/", cursor_data->path, (char*)NULL); temp_surf = load_image (my_path, dfb, x_ratio, y_ratio); free(my_path); if (temp_surf) { temp_curs = (dfb_cursor_t *)calloc(1, sizeof(dfb_cursor_t)); temp_curs->surface = temp_surf; temp_curs->x_off = cursor_data->x_off; temp_curs->y_off = cursor_data->y_off; temp_curs->locked = 0; *cursor = temp_curs; } }
int main( int argc, char **argv ) { int oldpid, oldumask, fd, noDaemonMode; char *pt, *errorLogFile, **opts; /* make sure at least world write access is disabled */ if (((oldumask = umask( 022 )) & 002) == 002) (void)umask( oldumask ); /* give /dev/null as stdin */ if ((fd = open( "/dev/null", O_RDONLY )) > 0) { dup2( fd, 0 ); close( fd ); } if (fcntl( 1, F_GETFD ) < 0) dup2( 0, 1 ); if (fcntl( 2, F_GETFD ) < 0) dup2( 0, 2 ); if (argv[0][0] == '/') { if (!StrDup( &progpath, argv[0] )) Panic( "Out of memory" ); } else #ifdef __linux__ { /* note that this will resolve symlinks ... */ int len; char fullpath[PATH_MAX]; if ((len = readlink( "/proc/self/exe", fullpath, sizeof(fullpath) )) < 0) Panic( "Invoke with full path specification or mount /proc" ); if (!StrNDup( &progpath, fullpath, len )) Panic( "Out of memory" ); } #else # if 0 Panic( "Must be invoked with full path specification" ); # else { char directory[PATH_MAX+1]; if (!getcwd( directory, sizeof(directory) )) Panic( "Can't find myself (getcwd failed)" ); if (strchr( argv[0], '/' )) StrApp( &progpath, directory, "/", argv[0], (char *)0 ); else { int len; char *path, *pathe, *name, *thenam, nambuf[PATH_MAX+1]; if (!(path = getenv( "PATH" ))) Panic( "Can't find myself (no PATH)" ); len = strlen( argv[0] ); name = nambuf + PATH_MAX - len; memcpy( name, argv[0], len + 1 ); *--name = '/'; do { if (!(pathe = strchr( path, ':' ))) pathe = path + strlen( path ); len = pathe - path; if (!len || (len == 1 && *path == '.')) { len = strlen( directory ); path = directory; } thenam = name - len; if (thenam >= nambuf) { memcpy( thenam, path, len ); if (!access( thenam, X_OK )) goto found; } path = pathe; } while (*path++ != '\0'); Panic( "Can't find myself (not in PATH)" ); found: if (!StrDup( &progpath, thenam )) Panic( "Out of memory" ); } } # endif #endif prog = strrchr( progpath, '/' ) + 1; #if !defined(HAVE_SETPROCTITLE) && !defined(NOXDMTITLE) Title = argv[0]; TitleLen = (argv[argc - 1] + strlen( argv[argc - 1] )) - Title; #endif /* * Parse command line options */ noDaemonMode = getppid(); errorLogFile = 0; if (!(opts = Malloc( 2 * sizeof(char *) ))) return 1; opts[0] = (char *)""; opts[1] = 0; while (*++argv) { if (**argv != '-') break; pt = *argv + 1; if (*pt == '-') pt++; if (!strcmp( pt, "help" ) || !strcmp( pt, "h" )) { printf( "Usage: %s [options] [tty]\n" " -daemon\t - Daemonize even when started by init\n" " -nodaemon\t - Don't daemonize even when started from command line\n" " -config <file> - Use alternative master configuration file\n" " -xrm <res>\t - Override frontend-specific resource\n" " -error <file>\t - Use alternative log file\n" " -debug <num>\t - Debug option bitfield:\n" "\t\t\t0x1 - core log\n" "\t\t\t0x2 - config reader log\n" "\t\t\t0x4 - greeter log\n" "\t\t\t0x8 - IPC log\n" "\t\t\t0x10 - session sub-daemon post-fork delay\n" "\t\t\t0x20 - config reader post-start delay\n" "\t\t\t0x40 - greeter post-start delay\n" "\t\t\t0x80 - don't use syslog\n" "\t\t\t0x100 - core Xauth log\n" "\t\t\t0x400 - valgrind config reader and greeter\n" "\t\t\t0x800 - strace config reader and greeter\n" , prog ); exit( 0 ); } else if (!strcmp( pt, "daemon" )) noDaemonMode = 0; else if (!strcmp( pt, "nodaemon" )) noDaemonMode = 1; else if (argv[1] && !strcmp( pt, "config" )) StrDup( opts, *++argv ); else if (argv[1] && !strcmp( pt, "xrm" )) opts = addStrArr( opts, *++argv, -1 ); else if (argv[1] && !strcmp( pt, "debug" )) sscanf( *++argv, "%i", &debugLevel ); else if (argv[1] && (!strcmp( pt, "error" ) || !strcmp( pt, "logfile" ))) errorLogFile = *++argv; else { fprintf( stderr, "\"%s\" is an unknown option or is missing a parameter\n", *argv ); exit( 1 ); } } /* * Only allow root to run in non-debug mode to avoid problems */ if (!debugLevel && getuid()) { fprintf( stderr, "Only root wants to run %s\n", prog ); exit( 1 ); } InitErrorLog( errorLogFile ); if (noDaemonMode != 1) BecomeDaemon(); /* * Step 1 - load configuration parameters */ if (!InitResources( opts ) || ScanConfigs( FALSE ) < 0) LogPanic( "Config reader failed. Aborting ...\n" ); /* SUPPRESS 560 */ if ((oldpid = StorePid())) { if (oldpid == -1) LogError( "Can't create/lock pid file %s\n", pidFile ); else LogError( "Can't lock pid file %s, another xdm is running (pid %d)\n", pidFile, oldpid ); exit( 1 ); } #ifdef NEED_ENTROPY AddOtherEntropy(); #endif /* * We used to clean up old authorization files here. As authDir is * supposed to be /var/run/xauth or /tmp, we needn't to care for it. */ #ifdef XDMCP init_session_id(); #else Debug( "not compiled for XDMCP\n" ); #endif if (pipe( signalFds )) LogPanic( "Unable to create signal notification pipe.\n" ); RegisterInput( signalFds[0] ); RegisterCloseOnFork( signalFds[0] ); RegisterCloseOnFork( signalFds[1] ); (void)Signal( SIGTERM, SigHandler ); (void)Signal( SIGINT, SigHandler ); (void)Signal( SIGHUP, SigHandler ); (void)Signal( SIGCHLD, SigHandler ); (void)Signal( SIGUSR1, SigHandler ); /* * Step 2 - run a sub-daemon for each entry */ #ifdef XDMCP UpdateListenSockets(); #endif openCtrl( 0 ); MainLoop(); closeCtrl( 0 ); if (sdRec.how) { commitBootOption(); if (Fork() <= 0) { char *cmd = sdRec.how == SHUT_HALT ? cmdHalt : cmdReboot; execute( parseArgs( (char **)0, cmd ), (char **)0 ); LogError( "Failed to execute shutdown command %\"s\n", cmd ); exit( 1 ); } else { sigset_t mask; sigemptyset( &mask ); sigaddset( &mask, SIGCHLD ); sigaddset( &mask, SIGHUP ); sigsuspend( &mask ); } } Debug( "nothing left to do, exiting\n" ); return 0; }
void AppendDescPart(StrApp & strDesc, BSTR bstr, bool & fFirst) { AppendDescPart(strDesc, StrApp(bstr).Chars(), fFirst); }
void AppendDescPart(StrApp & strDesc, int stidPart, bool & fFirst) { AppendDescPart(strDesc, StrApp(stidPart).Chars(), fFirst); }
void AppendDescPart(StrApp & strDesc, StrUni stuPart, bool & fFirst) { AppendDescPart(strDesc, StrApp(stuPart).Chars(), fFirst); }
int load_settings(void) { static int first_time = 1; struct stat status; cursor_t *cur; window_t *win; /* int i; */ if (!first_time) destroy_keybindings_list(); first_time = 0; datadir = strdup(SETTINGS_DIR "/"); settings = StrApp((char**)NULL, datadir, "settings", (char*)NULL); yyin = fopen(settings, "r"); if (!yyin) { fprintf(stderr, "qingy: load_settings: settings file (%s) not found:\n", settings); perror(NULL); fprintf(stderr, "Reverting to text mode\n"); return 0; } file_error = settings; yyparse(); fclose(yyin); if (settings_parse_error) { fprintf(stderr, "ERROR parsing settings file: reverting to text mode!\n"); return 0; } file_error = NULL; if ( (log_facilities_tty & LOG_TO_FILE) || (log_facilities_tty & LOG_TO_SYSLOG) || (log_facilities_tty & LOG_TO_CONSOLE) ) log_facilities = log_facilities_tty; if (!log_facilities) { log_facilities = LOG_TO_CONSOLE; } /* complain if tmp_files_dir does not exist (or is not a directory) */ if (!stat(tmp_files_dir, &status)) { if (!S_ISDIR(status.st_mode)) { WRITELOG(ERROR, "The temp files directory you chose (%s), is not a directory!\n", tmp_files_dir); return 0; } } else { WRITELOG(ERROR, "Cannot access temp files directory (%s): %s\n", tmp_files_dir, strerror(errno)); return 0; } last_user = StrApp((char**)NULL, tmp_files_dir, "/qingy-lastuser", (char*)NULL); if (!text_sessions_directory || !x_sessions_directory || !xinit || #ifdef USE_SCREEN_SAVERS !screensavers_dir || #endif !themes_dir) { writelog(ERROR, "You left some variables undefined in settings file!\n"); return 0; } #ifndef USE_DIRECTFB /* disable graphic mode login if DirectFB is not enabled */ text_mode_login = 1; #endif if (!got_theme && !text_mode_login) { writelog(ERROR, "Cannot proceed to graphic mode without a theme!\n"); return 0; } if (!check_windows_sanity()) { writelog(ERROR, "Error in windows configuration: make sure you set up at least login, password and session windows!\n"); return 0; } /* let's assign cursors to their appropriate windows... */ for (cur = cursorsList; cur; cur=cur->next) { static cursor_t *prevcur = NULL; if (prevcur) prevcur->next = NULL; if (cur->window_id == -1) { /* this is the global cursor for current theme */ cursor = cur; } else { /* we assign it to its intended window */ for (win = windowsList; win; win=win->next) if (win->id == cur->window_id) { win->cursor = cur; break; } } prevcur = cur; } writelog(DEBUG, "The following logging facilities will be used: "); WRITELOG(DEBUG, "%s", (log_facilities & LOG_TO_FILE) ? "FILE " : ""); WRITELOG(DEBUG, "%s", (log_facilities & LOG_TO_SYSLOG) ? "SYSLOG " : ""); WRITELOG(DEBUG, "%s", (log_facilities & LOG_TO_CONSOLE) ? "CONSOLE " : ""); writelog(DEBUG, "\n"); WRITELOG(DEBUG, "Session locking is%s enabled.\n", (lock_sessions) ? "" : " NOT"); /* if (cursor) */ /* { */ /* writelog(DEBUG, "Theme cursor:\n"); */ /* WRITELOG(DEBUG, " enable: %d\n", cursor->enable); */ /* WRITELOG(DEBUG, " path: %s\n", cursor->path); */ /* WRITELOG(DEBUG, " x_off: %d\n", cursor->x_off); */ /* WRITELOG(DEBUG, " y_off: %d\n", cursor->y_off); */ /* WRITELOG(DEBUG, " window_id: %d\n", cursor->window_id); */ /* writelog(DEBUG, "\n"); */ /* } */ /* window_t* temp2=windowsList; */ /* for (i=0; temp2; temp2=temp2->next) */ /* { */ /* cursor_t* temp=temp2->cursor; */ /* WRITELOG(DEBUG, "Window #%d:\n", i); */ /* WRITELOG(DEBUG, " type: %d\n", temp2->type); */ /* WRITELOG(DEBUG, " id: %d\n", temp2->id); */ /* if (temp) */ /* { */ /* writelog(DEBUG, " Cursor:\n"); */ /* WRITELOG(DEBUG, " enable: %d\n", temp->enable); */ /* WRITELOG(DEBUG, " path: %s\n", temp->path); */ /* WRITELOG(DEBUG, " x_off: %d\n", temp->x_off); */ /* WRITELOG(DEBUG, " y_off: %d\n", temp->y_off); */ /* } */ /* writelog(DEBUG, "\n"); */ /* i++; */ /* } */ return 1; }
void initialize_variables(void) { screensaver_name = NULL; autologin_file_basename = strdup("qingy-autologin-"); text_sessions_directory = NULL; x_sessions_directory = NULL; autologin_username = NULL; autologin_session = NULL; screensavers_dir = NULL; log_facilities = LOG_NONE; log_facilities_tty = LOG_NONE; dfb_interface = StrApp((char**)NULL, SBINDIR, "qingy-DirectFB", (char*)NULL); reset_console_utility = StrApp((char**)NULL, SBINDIR, "qingy-reset-console", (char*)NULL); tmp_files_dir = strdup("/var/lib/misc"); max_loglevel = ERROR; x_serv_tty_mgmt = QINGY_TTY; background = NULL; themes_dir = NULL; theme_dir = NULL; last_user = NULL; sleep_cmd = NULL; settings = NULL; x_server = NULL; x_args = NULL; datadir = NULL; xinit = NULL; font = NULL; screensaver_options = NULL; windowsList = NULL; fb_device = NULL; resolution = NULL; pre_gui_script = NULL; post_gui_script = NULL; cursor = NULL; excluded_runlevels = NULL; settings_parse_error = 0; x_server_offset = 1; do_autologin = 0; auto_relogin = 0; no_shutdown_screen = 0; disable_last_user = 0; hide_last_user = 0; hide_password = 0; text_mode_login = 0; clear_background = 0; do_runlevel_check = 0; shutdown_policy = EVERYONE; last_user_policy = LU_GLOBAL; last_session_policy = LS_USER; timeout_action = ST_NONE; idle_timeout = 0; got_theme = 0; lock_sessions = 0; theme_xres = 800; theme_yres = 600; #ifdef USE_SCREEN_SAVERS screensaver_timeout = 5; use_screensaver = 1; #else screensaver_timeout = 0; use_screensaver = 0; #endif use_screen_power_management = 0; screen_power_management_timeout = 0; countdown_timeout = 5; info_message_timeout = 2; welcome_message_timeout = 1; shutdown_timeout_message = strdup("system shutdown in <INS_TIMEOUT_HERE> seconds"); restart_timeout_message = strdup("system restart in <INS_TIMEOUT_HERE> seconds"); sleep_timeout_message = strdup("system will fall asleep in <INS_TIMEOUT_HERE> seconds"); sleep_forbidden_message = strdup("Putting this machine in sleep mode is not allowed!"); shutdown_forbidden_message = strdup("Shutting down this machine is not allowed!"); sleep_password_message = strdup("You must enter root password to put this machine to sleep!"); shutdown_password_message = strdup("You must enter root password to shut down this machine!"); shutdown_message = strdup("shutting down system..."); restart_message = strdup("rebooting system..."); login_message = strdup("Logging in"); login_failed_message = strdup("Login failed!"); abort_message = strdup("Press ESC key to abort"); caps_message = strdup("CAPS LOCK is pressed"); sleep_cmd_message = strdup("You must define sleep command in settings file!"); crypto_error_message = strdup("Crypto error - regenerate your keys!"); welcome_message = strdup("Starting selected session..."); }
char *get_random_theme() { DIR *dir; char *my_themes_dir = StrApp((char**)NULL, themes_dir, "/", (char*)NULL); char *result; struct dirent *entry; int n_themes = 0; char *themes[128]; int i; dir= opendir(my_themes_dir); if (!dir) { /* perror("Qingy error"); */ /* This is not a qingy error ;-P */ WRITELOG(ERROR, "Cannot open themes directory (%s)!\n", my_themes_dir); free(my_themes_dir); return strdup("default"); } while ((entry= readdir(dir))) { char *temp; /* To the genius who wrote this snippet: if(!entry){ perror("Qingy error"); break; } It will never be executed! (See above while() condition ;-P) */ if (!strcmp(entry->d_name, "." )) continue; if (!strcmp(entry->d_name, "..")) continue; temp = StrApp((char**)NULL, my_themes_dir, entry->d_name, (char*)NULL); if (is_a_directory(temp)) { themes[n_themes] = strdup(entry->d_name); n_themes++; } free(temp); } closedir(dir); /* If the opendir() some lines above didn't fail, * there is no reason to think closedir() will: * if(closedir(dir)== -1) * perror("Qingy error"); */ free(my_themes_dir); if (!n_themes) return strdup("default"); /* let's create a random number between 0 and n_themes-1 */ srand((unsigned int)time(NULL)); i = rand() % n_themes; result = strdup(themes[i]); for (i=0; i<n_themes; i++) free(themes[i]); return result; }