void clear_mtrie_conf_links() { aConfItem *found_conf; aConfItem *found_conf_next; I_LINE_IP_ENTRY *found_ip_entry; I_LINE_IP_ENTRY *found_ip_entry_next; if(trie_list) { clear_sub_mtrie(trie_list); trie_list = (DOMAIN_LEVEL *)NULL; } for(found_conf=unsortable_list_ilines; found_conf;found_conf=found_conf_next) { found_conf_next = found_conf->next; /* this is an I line list */ if(found_conf->clients) found_conf->status |= CONF_ILLEGAL; else free_conf(found_conf); } unsortable_list_ilines = (aConfItem *)NULL; for(found_conf=unsortable_list_klines; found_conf;found_conf=found_conf_next) { found_conf_next = found_conf->next; free_conf(found_conf); } unsortable_list_klines = (aConfItem *)NULL; for(found_conf=wild_card_ilines; found_conf;found_conf=found_conf_next) { found_conf_next = found_conf->next; free_conf(found_conf); } wild_card_ilines = (aConfItem *)NULL; for(found_ip_entry = ip_i_lines; found_ip_entry; found_ip_entry = found_ip_entry_next) { found_ip_entry_next = found_ip_entry->next; /* The aconf's pointed to by each ip entry here, * have already been cleared out of the mtrie tree above. */ MyFree(found_ip_entry); } ip_i_lines = (I_LINE_IP_ENTRY *)NULL; }
gint set_int_conf(gchar *key, gint value) { t_conf conf; conf.line = g_strdup_printf("%d", value); if (set_conf(key, &conf)) { free_conf(&conf); return (1); } free_conf(&conf); return (0); }
gint set_string_conf(gchar *key, gchar *value) { t_conf conf; conf.line = g_strdup(value); if (set_conf(key, &conf)) { free_conf(&conf); return (1); } free_conf(&conf); return (0); }
gint get_int_conf(gchar *key) { t_conf conf; gint ret_val; if (get_conf(key, &conf)) { free_conf(&conf); return (0); } ret_val = (gint) g_strtod(conf.line, NULL); free_conf(&conf); return (ret_val); }
/** Disassociate configuration from the client. * @param cptr Client to operate on. * @param aconf ConfItem to detach. */ static void detach_conf(struct Client* cptr, struct ConfItem* aconf) { struct SLink** lp; struct SLink* tmp; assert(0 != aconf); assert(0 != cptr); assert(0 < aconf->clients); lp = &(cli_confs(cptr)); while (*lp) { if ((*lp)->value.aconf == aconf) { if (aconf->conn_class && (aconf->status & CONF_CLIENT_MASK) && ConfLinks(aconf) > 0) --ConfLinks(aconf); assert(0 < aconf->clients); if (0 == --aconf->clients && IsIllegal(aconf)) free_conf(aconf); tmp = *lp; *lp = tmp->next; free_link(tmp); return; } lp = &((*lp)->next); } }
enum nss_status _nss_map_getgrnam_r( const char *name, struct group *g, char *buffer, size_t buflen, int *errnop) { map_conf_t *conf; if ((conf = read_conf()) == NULL) { return NSS_STATUS_NOTFOUND; } /* If out of memory */ if ((g->gr_name = get_static(&buffer, &buflen, strlen(name) + 1)) == NULL) { return NSS_STATUS_TRYAGAIN; } /* gr_name stay as the name given */ strcpy(g->gr_name, name); if ((g->gr_passwd = get_static(&buffer, &buflen, strlen("x") + 1)) == NULL) { return NSS_STATUS_TRYAGAIN; } strcpy(g->gr_passwd, "x"); g->gr_gid = conf->pw_gid; /* GID_NUMBER; */ free_conf(conf); return NSS_STATUS_SUCCESS; }
gchar *get_string_conf(gchar *key) { t_conf conf; gchar *ret_val; if (get_conf(key, &conf)) { free_conf(&conf); ret_val = g_malloc(1); ret_val[0] = '\0'; return (ret_val); } ret_val = parse_string(conf.line); free_conf(&conf); return (ret_val); }
/* fun: _nss_map_getpwuid * txt: get the passwd struct from uid, for mapped users, the value of user * name is taken from the environment, using the LOGNAME variable. */ enum nss_status _nss_map_getpwuid_r(uid_t uid, struct passwd *p, char *buffer, size_t buflen, int *errnop) { map_conf_t *conf; char * name; /* XXX: The logname hack */ if ( (name = getenv("LOGNAME")) == NULL ) return NSS_STATUS_NOTFOUND; if ((conf = read_conf()) == NULL) { return NSS_STATUS_NOTFOUND; } /* If out of memory */ if ((p->pw_name = get_static(&buffer, &buflen, strlen(name) + 1)) == NULL) { return NSS_STATUS_TRYAGAIN; } /* pw_name stay as the name given */ strcpy(p->pw_name, name); if ((p->pw_passwd = get_static(&buffer, &buflen, strlen("x") + 1)) == NULL) { return NSS_STATUS_TRYAGAIN; } strcpy(p->pw_passwd, "x"); p->pw_uid = conf->pw_uid; /* UID_NUMBER; */ p->pw_gid = conf->pw_gid; /* GID_NUMBER; */ if ((p->pw_gecos = get_static(&buffer, &buflen, strlen(conf->pw_gecos) + 1 )) == NULL) { return NSS_STATUS_TRYAGAIN; } strcpy(p->pw_gecos, conf->pw_gecos); if ((p->pw_dir = get_static(&buffer, &buflen, strlen(conf->pw_dir) + 1 + strlen(name) + 1 )) == NULL) { return NSS_STATUS_TRYAGAIN; } /* XXX: the dirname hack */ strcpy(p->pw_dir, conf->pw_dir); strcat(p->pw_dir,"/"); strcat(p->pw_dir,name); if ((p->pw_shell = get_static(&buffer, &buflen, strlen(conf->pw_shell) + 1 )) == NULL) { return NSS_STATUS_TRYAGAIN; } strcpy(p->pw_shell, conf->pw_shell); free_conf(conf); return NSS_STATUS_SUCCESS; }
gint set_bool_conf(gchar *key, gboolean value) { t_conf conf; if (value) conf.line = g_strdup("TRUE"); else conf.line = g_strdup("FALSE"); if (set_conf(key, &conf)) { free_conf(&conf); return (1); } free_conf(&conf); return (0); }
void config_init(void) { if(get_conf(W->confpath) == -1) { warnl("parsing configuration file (%s) failed.", W->confpath); sprintf(W->confpath, "%s/"CONFIG_DEFAULT_PATH, getenv("HOME")); if(get_conf(W->confpath) == -1) { warnxl("parsing default configuration file (%s) failed.", W->confpath); sprintf(W->confpath, "%s/wmfs/wmfsrc", XDG_CONFIG_DIR); if(get_conf(W->confpath) == -1) errxl(1, "parsing system configuration file (%s) failed.", W->confpath); } } config_theme(); config_keybind(); config_tag(); config_client(); config_bars(); config_rule(); config_launcher(); free_conf(); }
struct gra2cairo_local * gra2cairo_free(struct objlist *obj, N_VALUE *inst) { struct gra2cairo_local *local; _getobj(obj, "_local", inst, &local); if (local == NULL) return NULL; if (local->cairo) { gra2cairo_draw_path(local); cairo_destroy(local->cairo); } if (local->layout) { g_object_unref(local->layout); } if (local->fontalias) { g_free(local->fontalias); } Instance--; if (Instance == 0) { free_conf(); } return local; }
int main() { char **value; int valnum; int i; void *cfgdata; cfgdata = init_conf(); if(load_conf(cfgdata,"../../etc/dp.conf") < 0) { printf("load configuration file failure.\n"); return -1; } const char *weekday[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; printf("[test] int: %d\n",getconfint(cfgdata,"test","int",0,1,2,6)); printf("[test] float: %.2f\n",getconfloat(cfgdata,"test","float",0,1.0,1.0,999.99)); printf("[test] string: %s\n",getconfstring(cfgdata,"test","string",0,"not fount",weekday,NULL,7,NULL)); printf("[test] multi-value: \n"); getconfmulti(cfgdata,"test","multi",0,"not found"," ",&value,&valnum); for(i=0;i<valnum;i++) printf("%s ",value[i]); printf("\n"); free_conf(cfgdata); }
gboolean get_bool_conf(gchar *key) { t_conf conf; gboolean ret_val; if (get_conf(key, &conf)) { free_conf(&conf); return (0); } if (!g_strcasecmp(conf.line, TRUE_STR)) ret_val = 1; else ret_val = 0; free_conf(&conf); return (ret_val); }
static int fster_opt_proc (void *data, const char *arg, int key, struct fuse_args *outargs) { gchar *param_name = NULL; gchar *param_value = NULL; switch (key) { case KEY_HELP: usage (); fuse_opt_add_arg (outargs, "-ho"); fuse_main (outargs->argc, outargs->argv, &ifs_oper, NULL); free_conf (); exit (0); break; case KEY_CONFIGFILE: Config.conf_file = g_strdup (arg + 2); break; case KEY_VERSION: printf ("FSter version " VERSION "\n"); exit (0); break; case KEY_USER_PARAMETER: if (strchr (arg + 2, '=') == NULL) { g_warning ("Malformed parameter, should be name=value"); free_conf (); exit (1); } param_name = g_strdup (arg + 2); param_value = strchr (param_name, '='); *param_value = '\0'; param_value = g_strdup (param_value + 1); set_user_param (param_name, param_value); break; default: return 1; break; } return 0; }
static void clear_sub_mtrie(DOMAIN_LEVEL *dl_ptr) { DOMAIN_PIECE *dp_ptr; DOMAIN_PIECE *next_dp_ptr; aConfItem *conf_ptr; int i; if(!dl_ptr) return; for(i=0; i < MAX_PIECE_LIST; i++) { dp_ptr = dl_ptr->piece_list[i]; dl_ptr->piece_list[i] = NULL; for(;dp_ptr; dp_ptr = next_dp_ptr) { clear_sub_mtrie(dp_ptr->next_level); if(dp_ptr->wild_conf_ptr) { conf_ptr = dp_ptr->wild_conf_ptr; if( (conf_ptr->status & CONF_CLIENT) && conf_ptr->clients) conf_ptr->status |= CONF_ILLEGAL; else free_conf(conf_ptr); } if(dp_ptr->conf_ptr) { conf_ptr = dp_ptr->conf_ptr; if( (conf_ptr->status & CONF_CLIENT) && conf_ptr->clients) conf_ptr->status |= CONF_ILLEGAL; else free_conf(conf_ptr); } next_dp_ptr = dp_ptr->next_piece; MyFree(dp_ptr); } } MyFree(dl_ptr); }
/** Main of the program */ int main (int argc, char *argv []) { GMainLoop *gloop; GFuseLoop *loop; struct fuse_args args = FUSE_ARGS_INIT (argc, argv); umask (0); g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL); memset (&Config, 0, sizeof (Config)); if (fuse_opt_parse (&args, &Config, fster_opts, fster_opt_proc) == -1) { free_conf (); exit (1); } if (Config.conf_file == NULL) Config.conf_file = g_strdup (DEFAULT_CONFIG_FILE); if (access (Config.conf_file, F_OK | R_OK) != 0) { g_warning ("Unable to find configuration file in %s", Config.conf_file); free_conf (); exit (1); } loop = gfuse_loop_new (); gfuse_loop_set_operations (loop, &ifs_oper); gfuse_loop_set_config (loop, args.argc, args.argv); gfuse_loop_run (loop); gloop = g_main_loop_new (NULL, FALSE); g_main_loop_run (gloop); fuse_opt_free_args (&args); g_object_unref (loop); g_object_unref (gloop); exit (0); }
/* * clear_sxlines * * inputs - none * output - none * side effects - clear the sxline list */ void clear_sxlines(void) { aConfItem *aconf; aConfItem *sxl=sxlines; while(sxl) { aconf = sxl->next; free_conf(sxl); sxl = aconf; } sxlines = NULL; }
static int gra2cairo_init(struct objlist *obj, N_VALUE *inst, N_VALUE *rval, int argc, char **argv) { struct gra2cairo_local *local = NULL; int antialias = ANTIALIAS_TYPE_DEFAULT; if (_exeparent(obj, (char *)argv[1], inst, rval, argc, argv)) return 1; if (Gra2cairoConf == NULL && init_conf()) { goto errexit; } local = g_malloc(sizeof(struct gra2cairo_local)); if (local == NULL) goto errexit; if (_putobj(obj, "_local", inst, local)) goto errexit; if (_putobj(obj, "antialias", inst, &antialias)) goto errexit; local->cairo = NULL; local->fontalias = NULL; local->layout = NULL; local->pixel_dot_x = 1; local->pixel_dot_y = 1; local->linetonum = 0; local->text2path = FALSE; local->antialias = antialias; local->region = NULL; local->font_style = GRA_FONT_STYLE_NORMAL; local->symbol = FALSE; local->use_opacity = FALSE; Instance++; return 0; errexit: if (Instance == 0) free_conf(); g_free(local); return 1; }
void xexit(int exit_value) /* exit after having freed memory and removed lock file */ { cf_t *f = NULL; now = time(NULL); /* we save all files now and after having waiting for all * job being executed because we might get a SIGKILL * if we don't exit quickly */ save_file(NULL); #ifdef FCRONDYN close_socket(); #endif f = file_base; while (f != NULL) { if (f->cf_running > 0) { /* */ debug("waiting jobs for %s ...", f->cf_user); /* */ wait_all(&f->cf_running); save_file(f); } delete_file(f->cf_user); /* delete_file remove the f file from the list : * next file to remove is now pointed by file_base. */ f = file_base; } remove(pidfile); exe_list_destroy(exe_list); lavg_list_destroy(lavg_list); free_conf(); Free_safe(orig_tz_envvar); explain("Exiting with code %d", exit_value); exit(exit_value); }
void config_parse(void) { if(get_conf(hftirc.conf.path) == -1) { ui_print_buf(0, "parsing configuration file (%s) failed.", hftirc.conf.path); sprintf(hftirc.conf.path, "%s/hftirc/hftirc.conf", XDG_CONFIG_DIR); get_conf(hftirc.conf.path); } config_misc(); config_ui(); config_ignore(); config_server(); free_conf(); return; }
/* * m_unsxline() - remove sxline * * parv[0] = sender prefix * parv[1] = sxlined name */ int m_unsxline(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) { aConfItem *sxl = sxlines; aConfItem *last_sxl = NULL; if (!IsService(sptr) && !IsServer(cptr)) { sendto_one(sptr, form_str(ERR_NOPRIVILEGES), me.name, parv[0]); return 0; } if(parc<2) { sendto_one(sptr, form_str(ERR_NEEDMOREPARAMS), me.name, parv[0], "UNSXLINE"); return 0; } while(sxl && irccmp(sxl->name, parv[1])) { last_sxl = sxl; sxl = sxl->next; } if (sxl) /* if sxline does exist */ { if(last_sxl) /* this is not the first sxline */ last_sxl->next=sxl->next; /* adjust list link -> */ else sxlines = sxl->next; free_conf(sxl); sendto_serv_butone(cptr, ":%s UNSXLINE :%s", parv[0], parv[1]); } return 0; }
void generate_vgyro() { // Allocates memory for new Iteration and Params_Vaccel structures. Iterate *iter = generate_iter(); Params_Vgyro *params_ = malloc(sizeof(Params_Vgyro)); // Create a kalman filter using the data configuration for it. Conf *c = load_config_data(); params_->kf = build_kalman(c); free_conf(c); // Initializes iter's fields. iter->compute_result = &compute_result_vgyro; iter->initialize_per_axis = &initialize_per_axis_vgyro; iter->free_params = &free_params_vgyro; iter->scan = &scan_vgyro; iter->params->params = params_; iter->params->result_type = GYROSCOPE; iter->params->result_model = VIRTUAL; // Iterates. iterate_devices(iter); // Frees allocated ressources. free_iter(iter); }
static map_conf_t * read_conf() { map_conf_t *conf; static FILE *fd; char buff[BUFSIZ]; char *b; char *value; if ((conf = new_conf()) == NULL) return NULL; if ((fd = fopen(MAIN_CONF_FILE, "r")) == NULL ) { free_conf(conf); return NULL; } if (fgets (buff, BUFSIZ, fd) == NULL) { fclose(fd); free_conf(conf); return NULL; } fclose(fd); /* start reading configuration file */ b = buff; /* pw_name */ value = b; while (*b != ':' && *b != '\0') b++; if (*b != ':') goto format_error; *b = '\0'; b++; conf->pw_name = strdup(value); /* NOT USED pw_passwd will be set equal to x (we like shadows) */ while (*b != ':' && *b != '\0') b++; if ( *b != ':' ) goto format_error; b++; /* pw_uid */ value = b; while (*b != ':' && *b != '\0') b++; if (*b != ':') goto format_error; b++; conf->pw_uid = atoi(value); if ( conf->pw_uid < MIN_UID_NUMBER ) conf->pw_uid = MIN_UID_NUMBER; /* pw_gid */ value = b; while (*b != ':' && *b != '\0') b++; if (*b != ':') goto format_error; b++; conf->pw_gid = atoi(value); if ( conf->pw_gid < MIN_GID_NUMBER ) conf->pw_gid = MIN_GID_NUMBER; /* pw_gecos */ value = b; while (*b != ':' && *b != '\0') b++; if (*b != ':') goto format_error; *b = '\0'; b++; conf->pw_gecos = strdup (value); /* pw_dir */ value = b; while (*b != ':' && *b != '\0') b++; if (*b != ':') goto format_error; *b = '\0'; b++; conf->pw_dir = strdup (value); /* pw_shell takes the rest */ /* Kyler Laird suggested to strip end line */ value = b; while (*b != '\n' && *b != '\0') b++; *b = '\0'; conf->pw_shell = strdup(value); return conf; format_error: free (conf); return NULL; }
/** Uninit the filesystem, destroying local tree of contents got from Item Manager @param conn Unused */ static void ifs_destroy (void *conn) { g_main_loop_quit (g_main_loop_new (NULL, FALSE)); destroy_hierarchy_tree (); free_conf (); }
/** Reload the configuration file. * @param cptr Client that requested rehash (if a signal, &me). * @param sig Type of rehash (0 = oper-requested, 1 = signal, 2 = * oper-requested but do not restart resolver) * @return CPTR_KILLED if any client was K/G-lined because of the * rehash; otherwise 0. */ int rehash(struct Client *cptr, int sig) { struct ConfItem** tmp = &GlobalConfList; struct ConfItem* tmp2; struct Client* acptr; int i; int ret = 0; int found_g = 0; if (1 == sig) sendto_opmask_butone(0, SNO_OLDSNO, "Got signal SIGHUP, reloading ircd conf. file"); while ((tmp2 = *tmp)) { if (tmp2->clients) { /* * Configuration entry is still in use by some * local clients, cannot delete it--mark it so * that it will be deleted when the last client * exits... */ if (CONF_CLIENT == (tmp2->status & CONF_CLIENT)) tmp = &tmp2->next; else { *tmp = tmp2->next; tmp2->next = 0; } tmp2->status |= CONF_ILLEGAL; } else { *tmp = tmp2->next; free_conf(tmp2); } } conf_erase_crule_list(); conf_erase_deny_list(); conf_erase_webirc_list(); conf_erase_shost_list(); conf_erase_except_list(); motd_clear(); /* * delete the juped nicks list */ clearNickJupes(); clear_quarantines(); class_mark_delete(); mark_listeners_closing(); auth_mark_closing(); close_mappings(); read_configuration_file(); if (sig != 2) restart_resolver(); log_reopen(); /* reopen log files */ auth_close_unused(); close_listeners(); class_delete_marked(); /* unless it fails */ /* * Flush out deleted I and P lines although still in use. */ for (tmp = &GlobalConfList; (tmp2 = *tmp);) { if (CONF_ILLEGAL == (tmp2->status & CONF_ILLEGAL)) { *tmp = tmp2->next; tmp2->next = NULL; if (!tmp2->clients) free_conf(tmp2); } else tmp = &tmp2->next; } for (i = 0; i <= HighestFd; i++) { if ((acptr = LocalClientArray[i])) { assert(!IsMe(acptr)); if (IsServer(acptr)) det_confs_butmask(acptr, ~(CONF_UWORLD | CONF_ILLEGAL)); /* Because admin's are getting so uppity about people managing to * get past K/G's etc, we'll "fix" the bug by actually explaining * whats going on. */ if ((found_g = find_kill(acptr))) { sendto_opmask_butone(0, found_g > -1 ? SNO_GLINE : SNO_OPERKILL, found_g == -2 ? "G-line active for %s%s" : (found_g == -3 ? "Z-line active for %s%s" : "K-line active for %s%s"), IsUnknown(acptr) ? "Unregistered Client ":"", get_client_name(acptr, SHOW_IP)); if (exit_client(cptr, acptr, &me, found_g == -2 ? "G-lined" : (found_g == -3 ? "Z-lined" : "K-lined")) == CPTR_KILLED) ret = CPTR_KILLED; } } } attach_conf_uworld(&me); geoip_init(); auth_send_event("rehash", NULL); return ret; }
static void find_or_add_user_piece(DOMAIN_PIECE *piece_ptr, aConfItem *aconf, int flags, char *host_piece) { DOMAIN_PIECE *ptr; DOMAIN_PIECE *new_ptr; DOMAIN_PIECE *last_ptr; aConfItem *found_aconf; char *user; #ifdef DEBUG_MTRIE if(aconf->status & CONF_KILL) sendto_realops("DEBUG: found kline"); #endif last_ptr = (DOMAIN_PIECE *)NULL; user = aconf->name; if(user[0] == '*' && user[1] == '\0') { if(!(piece_ptr->wild_conf_ptr)) { aconf->status |= flags; piece_ptr->wild_conf_ptr = aconf; piece_ptr->flags |= flags; return; } else { found_aconf = piece_ptr->wild_conf_ptr; if(found_aconf->status & CONF_ELINE) { /* if requested kline aconf =exactly= * matches an already present aconf * discard the requested K line * it should also be NOTICE'd back to the * oper who did the K-line, if I'm not * reading the conf file. */ free_conf(aconf); /* toss it in the garbage */ found_aconf->status |= flags; found_aconf->status &= ~CONF_KILL; piece_ptr->flags |= flags; piece_ptr->flags &= ~CONF_KILL; } else if(flags & CONF_KILL) { if(found_aconf->clients) found_aconf->status |= CONF_ILLEGAL; else free_conf(found_aconf); piece_ptr->wild_conf_ptr = aconf; } else if(flags & CONF_CLIENT) /* I line replacement */ { /* another I line/CONF_CLIENT exactly matching this * toss the new one into the garbage */ free_conf(aconf); } found_aconf->status |= flags; piece_ptr->flags |= flags; return; } } /* * if the piece_ptr->conf_ptr is NULL, then its the first piece_ptr * being added. The flags in piece_ptr will have already been set * but OR them in again anyway. aconf->status will also already have * the right flags. hint, these are optimization places for later. * * -Dianora */ for( ptr = piece_ptr; ptr; ptr = ptr->next_piece) { if(!ptr->conf_ptr) { aconf->status |= flags; /* redundant -db */ piece_ptr->flags |= flags; /* redundant -db */ ptr->conf_ptr = aconf; return; } found_aconf=ptr->conf_ptr; if( (!matches(ptr->host_piece,host_piece)) && (!matches(found_aconf->name,user)) ) { found_aconf->status |= flags; piece_ptr->flags |= flags; if(found_aconf->status & CONF_ELINE) { free_conf(aconf); /* toss it in the garbage */ found_aconf->status &= ~CONF_KILL; piece_ptr->flags &= ~CONF_KILL; } else if(found_aconf->status & CONF_CLIENT) { if(flags & CONF_CLIENT) free_conf(aconf); /* toss new I line into the garbage */ else { /* Its a K line */ if(found_aconf->clients) found_aconf->status |= CONF_ILLEGAL; else free_conf(found_aconf); ptr->conf_ptr = aconf; } } return; } last_ptr = ptr; } if(last_ptr) { new_ptr = (DOMAIN_PIECE *)MyMalloc(sizeof(DOMAIN_PIECE)); memset((void *)new_ptr,0,sizeof(DOMAIN_PIECE)); DupString(new_ptr->host_piece,host_piece); new_ptr->conf_ptr = aconf; last_ptr->next_piece = new_ptr; } else { /* */ sendto_realops("Bug in mtrie_conf.c last_ptr found NULL"); } return; }
static enum nss_status _nss_map_setgrent_locked() { map_conf_t *conf; char *dir; struct stat s; char *name; conf = read_conf(); if (conf == NULL) { DEBUG("%s:%d:setgrent_r:unable to open configuration file (%s).\n", __FILE__, __LINE__, MAIN_CONF_FILE); return NSS_STATUS_UNAVAIL; } /* XXX: The logname hack */ if ( (name = getenv("LOGNAME")) == NULL ) { DEBUG("%s:%d:setgrent_r:environment LOGNAME is not set.\n", __FILE__, __LINE__); return NSS_STATUS_UNAVAIL; } if (( dir = (char *)malloc( (strlen(name) + 1 + strlen(conf->pw_dir) + 1 + strlen(MAIN_CONF_FILE)) * sizeof(char) ) ) == NULL) { DEBUG("%s:%d:setgrent_r:unable to adquire memory for config.\n", __FILE__, __LINE__); return NSS_STATUS_TRYAGAIN; } strcpy(dir, conf->pw_dir); strcat(dir,"/"); strcat(dir,name); strcat(dir,"/"); strcat(dir,USER_CONF_FILE); free_conf(conf); /* some security checking */ if ( stat(dir, &s) == -1 ) goto format_error; if ( ! S_ISREG(s.st_mode) ) goto format_error; if ( (s.st_mode & S_IWGRP) || (s.st_mode & S_IWOTH) ) goto format_error; if ( (s.st_uid) || (s.st_gid) ) goto format_error; g_file = fopen(dir, "r"); if (g_file == NULL) goto format_error; return NSS_STATUS_SUCCESS; format_error: if(g_file != NULL) fclose(g_file); free(dir); return NSS_STATUS_UNAVAIL; }
enum nss_status _nss_map_initgroups_dyn (const char *user, gid_t group, long int *start, long int *size, gid_t **groupsp, long int limit, int *errnop) { gid_t *groups = *groupsp; FILE *fp = NULL; map_conf_t *conf; char *dir; struct stat s; struct group *g; conf = read_conf(); if (conf == NULL) { DEBUG("%s:%d:initgroups_dyn:unable to open configuration file (%s).\n", __FILE__, __LINE__, MAIN_CONF_FILE); return NSS_STATUS_UNAVAIL; } if (( dir = (char *)malloc( (strlen(user) + 1 + strlen(conf->pw_dir) + 1 + strlen(MAIN_CONF_FILE)) * sizeof(char) ) ) == NULL) { DEBUG("%s:%d:initgroups_dyn:unable to adquire memory for config.\n", __FILE__, __LINE__); return NSS_STATUS_TRYAGAIN; } strcpy(dir, conf->pw_dir); strcat(dir,"/"); strcat(dir,user); strcat(dir,"/"); strcat(dir,USER_CONF_FILE); free_conf(conf); /* some security checking */ if ( stat(dir, &s) == -1 ) goto format_error; if ( ! S_ISREG(s.st_mode) ) goto format_error; if ( (s.st_mode & S_IWGRP) || (s.st_mode & S_IWOTH) ) goto format_error; if ( (s.st_uid) || (s.st_gid) ) goto format_error; if ( (fp = fopen(dir, "r")) == NULL ) goto format_error; if ( (g = fgetgrent(fp)) == NULL ) goto format_error; else fclose(fp); if (!internal_gid_in_list (groups, group, *start)) { if (__builtin_expect (*start == *size, 0)) { /* Need a bigger buffer. */ gid_t *newgroups; long int newsize; if (limit > 0 && *size == limit) /* We reached the maximum. */ goto done; if (limit <= 0) newsize = 2 * *size; else newsize = MIN (limit, 2 * *size); newgroups = realloc (groups, newsize * sizeof (*groups)); if (newgroups == NULL) goto done; *groupsp = groups = newgroups; *size = newsize; } groups[(*start)++] = group; } groups[(*start)++] = g->gr_gid; done: return NSS_STATUS_SUCCESS; format_error: if(fp != NULL) fclose(fp); free(dir); return NSS_STATUS_UNAVAIL; }
/** Clean wmfs before the exit */ void quit(void) { Client *c; size_t i, len; /* Set the silent error handler */ XSetErrorHandler(errorhandlerdummy); /* Unmanage all clients */ for(c = clients; c; c = c->next) { client_unhide(c); XReparentWindow(dpy, c->win, ROOT, c->geo.x, c->geo.y); } free(tags); free(seltag); systray_freeicons(); XftFontClose(dpy, font); for(i = 0; i < CurLast; ++i) XFreeCursor(dpy, cursor[i]); XFreeGC(dpy, gc_stipple); infobar_destroy(); free(sgeo); free(spgeo); free(infobar); free(keys); free(net_atom); /* Clean conf alloced thing */ free(menulayout.item); if(conf.menu) { len = LEN(conf.menu); for(i = 0; i < len; ++i) free(conf.menu[i].item); free(conf.menu); } free(conf.launcher); free(conf.rule); free(conf.bars.mouse); free(conf.selbar.mouse); free(conf.titlebar.button); free(conf.client.mouse); free(conf.root.mouse); free_conf(); XSync(dpy, False); XCloseDisplay(dpy); /* kill status script */ if (conf.status_pid != (pid_t)-1) kill(conf.status_pid, SIGTERM); return; }