int optionspanel_button_cross(OptionsPanel* prPanel) { HexPad* prPad = NULL; if (prPanel == NULL) { return OPTIONSPANEL_NULLPTR; } prPad = get_hexpad(prPanel); if (prPad->visible == 1) { if (hexpad_button_cross(prPad) < 0) { return OPTIONSPANEL_FAILURE; } return OPTIONSPANEL_SUCCESS; } if (edit_value(prPanel) < 0) { return OPTIONSPANEL_FAILURE; } return OPTIONSPANEL_SUCCESS; }
int main(int argc, char *argv[]) { int a, i; int curr; char buf[1024]; char aaa[128]; int relh = 0; int home = 0; int nRetries = 0; char relhome[PATH_MAX]=""; char ctdldir[PATH_MAX]=CTDLDIR; struct passwd *pw; gid_t gid; char *activity = NULL; /* Keep a mild groove on */ program_title = _("Citadel setup program"); /* set an invalid setup type */ setup_type = (-1); /* parse command line args */ for (a = 0; a < argc; ++a) { if (!strncmp(argv[a], "-u", 2)) { strcpy(aaa, argv[a]); strcpy(aaa, &aaa[2]); setup_type = atoi(aaa); } else if (!strcmp(argv[a], "-q")) { setup_type = UI_SILENT; } else if (!strncmp(argv[a], "-h", 2)) { relh=argv[a][2]!='/'; if (!relh) { safestrncpy(ctdl_home_directory, &argv[a][2], sizeof ctdl_home_directory); } else { safestrncpy(relhome, &argv[a][2], sizeof relhome); } home = 1; } } calc_dirs_n_files(relh, home, relhome, ctdldir, 0); SetTitles(); /* If a setup type was not specified, try to determine automatically * the best one to use out of all available types. */ if (setup_type < 0) { setup_type = discover_ui(); } enable_home = ( relh | home ); if (chdir(ctdl_run_dir) != 0) { display_error("%s: [%s]\n", _("The directory you specified does not exist"), ctdl_run_dir); exit(errno); } /* * Connect to the running Citadel server. */ while ((serv_sock < 0) && (nRetries < 10)) { serv_sock = uds_connectsock(file_citadel_admin_socket); nRetries ++; if (serv_sock < 0) sleep(1); } if (serv_sock < 0) { display_error( "%s: %s %s\n", _("Setup could not connect to a running Citadel server."), strerror(errno), file_citadel_admin_socket ); exit(1); } /* * read the server greeting */ serv_gets(buf); if (buf[0] != '2') { display_error("%s\n", buf); exit(2); } /* * Are we connected to the correct Citadel server? */ serv_puts("INFO"); serv_gets(buf); if (buf[0] != '1') { display_error("%s\n", buf); exit(3); } a = 0; while (serv_gets(buf), strcmp(buf, "000")) { if (a == 5) { if (atoi(buf) != REV_LEVEL) { display_error("%s\n", _("Your setup program and Citadel server are from different versions.") ); exit(4); } } ++a; } /* * Now begin. */ if (setup_type == UI_TEXT) { printf("\n\n\n *** %s ***\n\n", program_title); } if (setup_type == UI_DIALOG) { system("clear 2>/dev/null"); } /* Go through a series of dialogs prompting for config info */ for (curr = 1; curr < eMaxQuestions; ++curr) { edit_value(curr); if ( (curr == eAuthType) && (getconf_int("c_auth_mode") != AUTHMODE_LDAP) && (getconf_int("c_auth_mode") != AUTHMODE_LDAP_AD) ) { curr += 5; /* skip LDAP questions if we're not authenticating against LDAP */ } if (curr == eSysAdminName) { if (getconf_int("c_auth_mode") == AUTHMODE_NATIVE) { /* for native auth mode, fetch the admin's existing pw */ snprintf(buf, sizeof buf, "AGUP %s", admin_name); serv_puts(buf); serv_gets(buf); if (buf[0] == '2') { extract_token(admin_pass, &buf[4], 1, '|', sizeof admin_pass); } } else { ++curr; /* skip the password question for non-native auth modes */ } } } if ((pw = getpwuid( getconf_int("c_ctdluid") )) == NULL) { gid = getgid(); } else { gid = pw->pw_gid; } if (create_run_directories(getconf_int("c_ctdluid"), gid) != 0) { display_error("%s\n", _("failed to create directories")); } activity = _("Reconfiguring Citadel server"); progress(activity, 0, 5); sleep(1); /* Let the message appear briefly */ /* * Create the administrator account. It's ok if the command fails if this user already exists. */ progress(activity, 1, 5); snprintf(buf, sizeof buf, "CREU %s|%s", admin_name, admin_pass); serv_puts(buf); progress(activity, 2, 5); serv_gets(buf); progress(activity, 3, 5); /* * Assign the desired password and access level to the administrator account. */ snprintf(buf, sizeof buf, "AGUP %s", admin_name); serv_puts(buf); progress(activity, 4, 5); serv_gets(buf); if (buf[0] == '2') { int admin_flags = extract_int(&buf[4], 2); int admin_times_called = extract_int(&buf[4], 3); int admin_msgs_posted = extract_int(&buf[4], 4); snprintf(buf, sizeof buf, "ASUP %s|%s|%d|%d|%d|6", admin_name, admin_pass, admin_flags, admin_times_called, admin_msgs_posted ); serv_puts(buf); serv_gets(buf); } progress(activity, 5, 5); #ifndef __CYGWIN__ check_xinetd_entry(); /* Check /etc/xinetd.d/telnet */ disable_other_mtas(); /* Offer to disable other MTAs */ fixnss(); /* Check for the 'db' nss and offer to disable it */ #endif /* * Restart citserver */ activity = _("Restarting Citadel server to apply changes"); progress(activity, 0, 41); serv_puts("TIME"); serv_gets(buf); long original_start_time = extract_long(&buf[4], 3); progress(activity, 1, 41); serv_puts("DOWN 1"); progress(activity, 2, 41); serv_gets(buf); if (buf[0] != '2') { display_error("%s\n", buf); exit(6); } close(serv_sock); serv_sock = (-1); for (i=3; i<=6; ++i) { /* wait for server to shut down */ progress(activity, i, 41); sleep(1); } for (i=7; ((i<=38) && (serv_sock < 0)) ; ++i) { /* wait for server to start up */ progress(activity, i, 41); serv_sock = uds_connectsock(file_citadel_admin_socket); sleep(1); } progress(activity, 39, 41); serv_gets(buf); progress(activity, 40, 41); serv_puts("TIME"); serv_gets(buf); long new_start_time = extract_long(&buf[4], 3); close(serv_sock); progress(activity, 41, 41); if ( (original_start_time == new_start_time) || (new_start_time <= 0) ) { display_error("%s\n", _("Setup failed to restart Citadel server. Please restart it manually.")); exit(7); } exit(0); return 0; }