bool StandardContactList::load_new() { QString cfgName = ProfileManager::instance()->profilePath() + QDir::separator() + "contacts.xml"; QFile f(cfgName); if(!f.open(QIODevice::ReadOnly)) return false; QDomDocument doc; doc.setContent(f.readAll()); QDomElement el = doc.elementsByTagName("global").at(0).toElement(); if(!m_userData->deserialize(el)) return false; QDomElement owner = doc.elementsByTagName("owner").at(0).toElement(); load_owner(owner); QDomElement groups = doc.elementsByTagName("groups").at(0).toElement(); if(!load_groups(groups)) return false; QDomElement contacts = doc.elementsByTagName("contacts").at(0).toElement(); if(!load_contacts(contacts)) return false; return true; }
void RulesConfigWidget::reconfigureGroups() { groupSelect->clear(); const QList<GroupData> &gl = load_groups(KGlobal::config().data()); foreach(GroupData gd, gl) { groupSelect->addItem(gd.name, gd.name); }
void do_whacklisten() { fflush(stderr); fflush(stdout); close_peerlog(); /* close any open per-peer logs */ libreswan_log("listening for IKE messages"); listening = TRUE; daily_log_reset(); reset_adns_restart_count(); set_myFQDN(); find_ifaces(); load_preshared_secrets(); load_groups(); }
static void do_whacklisten(void) { fflush(stderr); fflush(stdout); close_peerlog(); /* close any open per-peer logs */ #ifdef USE_SYSTEMD_WATCHDOG pluto_sd(PLUTO_SD_RELOADING, SD_REPORT_NO_STATUS); #endif libreswan_log("listening for IKE messages"); listening = TRUE; daily_log_reset(); set_myFQDN(); find_ifaces(); load_preshared_secrets(); load_groups(); #ifdef USE_SYSTEMD_WATCHDOG pluto_sd(PLUTO_SD_READY, SD_REPORT_NO_STATUS); #endif }
bool cps_api_db_get_node_group(const std::string &group,std::vector<std::string> &lst) { if (group.find(':')!=std::string::npos) {//case where a node is a group (or more that a node is a group) lst.push_back(group); return true; } std::lock_guard<std::recursive_mutex> lg(_mutex); (void)load_groups(); cps_api_node_data_type_t type; if(!_nodes->get_group_type(group,type)) { const char * _alias = _nodes->addr(group); if (_alias!=nullptr) { lst.push_back(_alias); return true; } EV_LOGGING(DSAPI,ERR,"GET-NODE-GRUOP","Failed to get group type for %s",group.c_str()); return false; } if((type == cps_api_node_data_1_PLUS_1_REDUNDENCY) && (_nodes->is_master_set(group))) { auto it = _nodes->_master.find(group); if(it == _nodes->_master.end()) { EV_LOGGING(DSAPI,ERR,"GET-NODE-GRUOP","Master not set for %s",group.c_str()); return false; } lst.push_back(it->second); return true; } if (!_nodes->group_addresses(group,lst)) { const char * __addr = _nodes->addr(group.c_str()); if (__addr==nullptr) return false; lst.push_back(__addr); } return true; }
/*======================================================================== ** The Main Procedure ** Initialization and FIFO command dispatch routine. ========================================================================*/ static int real_main(int argc, char *argv[]) { const char function[] = "real_main"; int option_foreground = FALSE; int FIFO; /* First-in-first-out which feeds us requests */ sigset_t lock_set; struct timeval next_tick; /* Initialize internation messages library. */ #ifdef INTERNATIONAL setlocale(LC_ALL, ""); bindtextdomain(PACKAGE_PPRD, LOCALEDIR); textdomain(PACKAGE_PPRD); #endif /* ** Set some environment variables, (PATH, IFS, and ** SHELL) for safety and for the convenience of the ** programs we launch (HOME, and PPR_VERSION). ** Remove unnecessary and potentially misleading ** variables. */ set_ppr_env(); prune_env(); parse_command_line(argc, argv, &option_foreground); /* Switch all UIDs to USER_PPR, all GIDS to GROUP_PPR. */ adjust_ids(); /* If the --forground switch wasn't used, then dropt into background. */ if(! option_foreground) gu_daemon(PPR_PPRD_UMASK); else umask(PPR_PPRD_UMASK); /* Change the home directory to the PPR home directory: */ chdir(HOMEDIR); /* Create /var/spool/ppr/pprd.pid. */ create_lock_file(); /* Signal handlers for silly stuff. */ signal_restarting(SIGPIPE, signal_ignore); signal_restarting(SIGHUP, signal_ignore); /* Signal handler for shutdown request. */ signal_interupting(SIGTERM, sigterm_handler); /* Arrange for child termination to be noted. */ signal_restarting(SIGCHLD, sigchld_handler); /* Move /var/spool/ppr/logs/pprd to pprd.old before we call debug() for the first time (below). */ rename_old_log_file(); /* ** This code must come after adjust_ids() and gu_daemon(). ** It makes the first log entry and tells queue-display ** programs that we are starting up. */ debug("PPRD startup, pid=%ld", (long)getpid()); state_update("STARTUP"); /* Make sure the local node gets the node id of 0. */ if(! nodeid_is_local_node(nodeid_assign(ppr_get_nodename()))) fatal(1, "%s(): line %d: assertion failed", function, __LINE__); /* Initialize other subsystems. */ question_init(); /* Load the printers database. */ DODEBUG_STARTUP(("loading printers database")); load_printers(); /* Load the groups database. */ DODEBUG_STARTUP(("loading groups database")); load_groups(); /* Set up the FIFO. */ DODEBUG_STARTUP(("opening FIFO")); FIFO = open_fifo(); /* Initialize the queue. This is likely to start printers. */ DODEBUG_STARTUP(("initializing the queue")); initialize_queue(); /* Schedule the first timer tick. */ gettimeofday(&next_tick, NULL); next_tick.tv_sec += TICK_INTERVAL; /* ** Create a signal block set which will be used to block SIGCHLD except ** when we are calling select(). */ sigemptyset(&lock_set); sigaddset(&lock_set, SIGCHLD); sigprocmask(SIG_BLOCK, &lock_set, (sigset_t*)NULL); /* ** This is the Main Loop. It runs until the sigterm_handler ** sets sigterm_received. */ while(!sigterm_received) { int readyfds; /* return value from select() */ fd_set rfds; /* list of file descriptors for select() to watch */ struct timeval time_now; /* the current time */ DODEBUG_MAINLOOP(("top of main loop")); gettimeofday(&time_now, NULL); /* If it is time for or past time for the next tick, */ if(gu_timeval_cmp(&time_now, &next_tick) >= 0) { readyfds = 0; } /* If it is not time for the next tick yet, */ else { /* Set the select() timeout so that it will return in time for the next tick(). */ gu_timeval_cpy(&select_tv, &next_tick); gu_timeval_sub(&select_tv, &time_now); /* Create a file descriptor list which contains only the descriptor of the FIFO. */ FD_ZERO(&rfds); FD_SET(FIFO, &rfds); /* Call select() with SIGCHLD unblocked. */ sigprocmask(SIG_UNBLOCK, &lock_set, (sigset_t*)NULL); readyfds = select(FIFO + 1, &rfds, NULL, NULL, &select_tv); sigprocmask(SIG_BLOCK, &lock_set, (sigset_t*)NULL); } /* If there is something to read, */ if(readyfds > 0) { if(!FD_ISSET(FIFO, &rfds)) fatal(0, "%s(): assertion failed: select() returned but FIFO not ready", function); do_command(FIFO); continue; } /* If the SIGCHLD handler set the flag, handle child termination. Once we have done that, we must go back to the top of the loop because we don't really know if it is time for a tick() call yet. */ if(sigchld_caught) { sigchld_caught = FALSE; reapchild(); continue; } /* If there was no error and no file descriptors are ready, then the timeout must have expired. Call tick(). */ if(readyfds == 0) { tick(); next_tick.tv_sec += TICK_INTERVAL; continue; } /* If interupted by a system call, restart it. */ if(errno == EINTR) continue; /* If we get this far, there was an error. */ fatal(0, "%s(): select() failed, errno=%d (%s)", function, errno, gu_strerror(errno)); } /* end of endless while() loop */ state_update("SHUTDOWN"); fatal(0, "Received SIGTERM, exiting"); } /* end of real_main() */
/* * fillin() * Given account record, fill in uinfo struct */ static void fillin(char *rec, struct uinfo *u) { char *p; extern void zero_ids(); /* * Default to something harmless */ u->u_uid = u->u_gid = 2; strcpy(u->u_passwd, "*"); strcpy(u->u_home, DEFHOME); strcpy(u->u_shell, _PATH_DEFAULT_SHELL); strcpy(u->u_env, _PATH_ENV); zero_ids(u->u_perms, PROCPERMS); /* * Password */ p = strchr(rec, ':'); if (p) { *p++ = '\0'; } strcpy(u->u_passwd, rec); if ((rec = p) == 0) { return; } /* * UID */ u->u_uid = atoi(rec); rec = strchr(rec, ':'); if (rec == 0) { return; } rec++; /* * GID */ u->u_gid = atoi(rec); rec = strchr(rec, ':'); if (rec == 0) { return; } rec++; /* * Skip name */ rec = strchr(rec, ':'); if (rec == 0) { return; } rec++; /* * Parse permission string */ p = strchr(rec, ':'); if (p) { *p++ = '\0'; } parse_perm(&u->u_perms[0], rec); u->u_perms[0].perm_uid = u->u_uid; if ((rec = p) == 0) { return; } /* * If there are further groups to be added because of * GID, add them here. */ load_groups(u); /* * Parse home */ p = strchr(rec, ':'); if (p) { *p++ = '\0'; } strcpy(u->u_home, rec); if ((rec = p) == 0) { return; } /* * Parse environment */ p = strchr(rec, ':'); if (p) { *p++ = '\0'; } strcpy(u->u_env, rec); if ((rec = p) == 0) { return; } /* * The rest is the shell */ strcpy(u->u_shell, rec); }
bool cps_api_nodes::load() { load_aliases(); return load_groups(); }
/*! \brief load_gui_tabs_pf() is called after interrogation completes successfully. It's purpose is to load all the glade files and datamaps as specified in the interrogation profile of the detected firmware. \param notebook is the pointer to the notebook the new tab should be placed \param page is the page number to load \returns TRUE on success, FALSE on failure */ G_MODULE_EXPORT gboolean load_actual_tab(GtkNotebook *notebook, gint page) { ConfigFile *cfgfile = NULL; gchar * map_file = NULL; gchar * glade_file = NULL; gchar * tmpbuf = NULL; GladeXML *xml = NULL; GtkWidget *label = NULL; GtkWidget *topframe = NULL; GtkWidget *placeholder = NULL; GHashTable *groups = NULL; GList *tab_widgets = NULL; BindGroup *bindgroup = NULL; extern GdkColor red; ENTER(); placeholder = gtk_notebook_get_nth_page(notebook,page); label = gtk_notebook_get_tab_label(notebook,placeholder); glade_file = (gchar *)OBJ_GET(label,"glade_file"); map_file = (gchar *)OBJ_GET(label,"datamap_file"); xml = glade_xml_new(glade_file,"topframe",NULL); g_return_val_if_fail(xml,FALSE); thread_update_logbar("interr_view",NULL,g_strdup(_("Load of tab: ")),FALSE,FALSE); thread_update_logbar("interr_view","info", g_strdup_printf("\"%s\"",glade_file),FALSE,FALSE); thread_update_logbar("interr_view",NULL,g_strdup(_(" completed.\n")),FALSE,FALSE); thread_update_logbar("interr_view",NULL,g_strdup(_("Load of tabconf: ")),FALSE,FALSE); thread_update_logbar("interr_view","info", g_strdup_printf("\"%s\"",map_file),FALSE,FALSE); cfgfile = cfg_open_file(map_file); if (cfgfile) { topframe = glade_xml_get_widget(xml,"topframe"); if (topframe == NULL) { MTXDBG(TABLOADER|CRITICAL,_("\"topframe\" not found in xml, ABORTING!!\n")); set_title(g_strdup(_("ERROR Gui Tab XML problem, \"topframe\" element not found!!!"))); EXIT(); return FALSE; } OBJ_SET_FULL(topframe,"glade_xml",(gpointer)xml,g_object_unref); // bind_data() is recursive and will take // care of all children bindgroup = g_new0(BindGroup,1); groups = load_groups(cfgfile); bindgroup->cfgfile = cfgfile; bindgroup->groups = groups; bindgroup->map_file = g_strdup(map_file); /* tab_widgets = g_list_prepend(tab_widgets,topframe); OBJ_SET(topframe,"tab_widgets",tab_widgets); */ bindgroup->topframe = topframe; bind_data(topframe,(gpointer)bindgroup); g_free(bindgroup->map_file); if (groups) g_hash_table_destroy(groups); groups = NULL; /* Clear not_rendered flag */ OBJ_SET(label,"not_rendered",NULL); populate_master(topframe,(gpointer)cfgfile); gtk_box_pack_start(GTK_BOX(placeholder),topframe,TRUE,TRUE,0); OBJ_SET(placeholder,"topframe",topframe); glade_xml_signal_autoconnect(xml); g_free(bindgroup); if (cfg_read_string(cfgfile,"global","post_functions",&tmpbuf)) { run_post_functions(tmpbuf); g_free(tmpbuf); } cfg_free(cfgfile); gtk_widget_show(topframe); /*printf("Current length of tab_widgets is %i\n",g_list_length(OBJ_GET(topframe,"tab_widgets")));*/ thread_update_logbar("interr_view",NULL,g_strdup(_(" completed.\n")),FALSE,FALSE); } update_groups_pf(); update_sources_pf(); /* Allow gui to update as it should.... */ gdk_flush(); EXIT(); return TRUE; }
int main(int argc, char **argv) { int i, j, snapshot_number; /* Read input and output files */ i=1; if (argc==1) usage(); while (i<argc) { if (!strcmp(argv[i],"-f")) { i++; strcpy(filename,argv[i]); i++; } else if (*argv[i]!='-') { strcpy(filename,argv[i]); i++; } else if (!strcmp(argv[i],"-i")) { i++; strcpy(filename,argv[i]); i++; } else if (!strcmp(argv[i],"-use")) { i++; use_cm=atoi(argv[i]); i++; } else if (!strcmp(argv[i],"-ind")) { i++; use_ind = 1; } else if (!strcmp(argv[i],"-s")) { i++; StarMassThreshold = atof(argv[i]); i++; } else if (!strcmp(argv[i],"-sfid")) { i++; sfid = atoi(argv[i]); i++; } else if (!strcmp(argv[i],"-m")) { i++; TotalMassThreshold = atof(argv[i]); i++; } else usage(); } char snap_number_dum[4]; sprintf(snap_number_dum, "%.*s", 3, &filename[ strlen(filename)-3]); snapshot_number = atoi( snap_number_dum ); printf("num %d\n", snapshot_number); load_groups(snapshot_number); load_group_ids(snapshot_number); load_snapshot(filename, snapshot_number); write_ascii(snapshot_number); return 0; }
cps_api_return_code_t cps_api_set_master_node(const char *group,const char * node_name) { std::lock_guard<std::recursive_mutex> lg(_mutex); (void)load_groups(); cps_api_node_data_type_t type; if(!_nodes->get_group_type(std::string(group),type)) { EV_LOGGING(DSAPI,ERR,"SET-MASTER","Failed to get group type for %s",group); return cps_api_ret_code_ERR; } if(type != cps_api_node_data_1_PLUS_1_REDUNDENCY) { EV_LOGGING(DSAPI,ERR,"SET-MASTER","Setting master for group type %d not supported",type); return cps_api_ret_code_ERR; } auto it = _nodes->_db_node_map.find(group); if( it == _nodes->_db_node_map.end()) { EV_LOGGING(DSAPI,ERR,"CPS-DB","No group named %s found",group); return cps_api_ret_code_ERR; } bool found = false; std::string master_node; for ( auto node_it : it->second) { if (strncmp(node_it._name.c_str(),node_name,strlen(node_name))==0) { auto master_it = _nodes->_master.find(group); if(master_it != _nodes->_master.end()) { if(master_it->second.compare(node_it._addr) == 0) { return cps_api_ret_code_OK; } else { if(!cps_api_remove_slave(node_it._addr)) { return cps_api_ret_code_ERR; } } } _nodes->_master[group]=node_it._addr; _nodes->mark_master_set(std::string(group)); master_node = node_it._addr; if(strncmp(node_it._addr.c_str(),"127.0.0.1",strlen("127.0.0.1"))==0) { EV_LOGGING(DSAPI,DEBUG,"SET-MASTER","Setting local node %s master for group %s",node_name,group); return cps_api_remove_slave(node_it._addr) ? cps_api_ret_code_OK : cps_api_ret_code_ERR; } found = true; break; } } if(!found) { EV_LOGGING(DSAPI,ERR,"CPS-DB","Failed to find a node named %s in group %s",node_name,group); return cps_api_ret_code_ERR; } for ( auto node_it : it->second) { if (strncmp(node_it._name.c_str(),node_name,strlen(node_name))) { cps_db::connection_request b(cps_db::ProcessDBCache(),node_it._addr.c_str()); if (!b.valid()) { return cps_api_ret_code_ERR; } if (!cps_db::make_slave(b.get(),master_node)) { EV_LOGGING(DSAPI,ERR,"SET-MASTER","Failed to make %s slave of %s", node_it._name.c_str(),master_node.c_str()); return cps_api_ret_code_ERR; } } } return cps_api_ret_code_OK; }