static int setup_environment (char *line, void *arg) { pam_handle_t *ph = (pam_handle_t*)arg; char *x; int ret; /* * Called for each stdout output line from the daemon * presumably environment variables. */ assert (line); assert (arg); /* Make sure it is in fact an environment variable */ if (!strchr (line, '=')) return PAM_SUCCESS; line = strbtrim (line); ret = pam_putenv (ph, line); /* If it's the PID line then we're interested in it */ if (strncmp (line, ENV_PID, strlen (ENV_PID)) == 0) { x = line + strlen (ENV_PID); if (x[0] == '=') pam_set_data (ph, "gkr-pam-pid", strdup (x + 1), cleanup_free); } return ret; }
static char* strtrim (char* data) { data = (char*)strbtrim (data); stretrim (data); return data; }
void AddLine(int SkipLineInfo) { if(/*ooutptr!=outptr&&*/dbgact==0&&(oline!=linenumber||omodule!=currentfileinfo)){ while(ooutptr>outptr&&pdbg!=0&&ooutptr!=0xffffffff)KillLastLine(); if(pdbg==pdbgmax){ pdbgmax+=MAXDBGS; dbgloc=(unsigned int *) REALLOC(dbgloc,pdbgmax*sizeof(unsigned int)); dbgnum=(unsigned int *) REALLOC(dbgnum,pdbgmax*sizeof(unsigned int)); dbgmod=(unsigned short *)REALLOC(dbgmod,pdbgmax*sizeof(unsigned short)); if(lstflag){ lststring=(char **)REALLOC(lststring,pdbgmax*sizeof(char *)); lstflag=(unsigned char *)REALLOC(lstflag,pdbgmax*sizeof(char)); lstend=(unsigned int *)REALLOC(lstend,pdbgmax*sizeof(unsigned int)); memset((char *)lstflag+(pdbgmax-MAXDBGS),-1,MAXDBGS*sizeof(char)); memset((unsigned int *)lstend+(pdbgmax-MAXDBGS),0,MAXDBGS*sizeof(unsigned int)); } } dbgloc[pdbg]=ooutptr=outptr; dbgnum[pdbg]=oline=linenumber; dbgmod[pdbg]=(unsigned short)currentfileinfo; omodule=currentfileinfo; if(dbg&2){ if(SkipLineInfo)lststring[pdbg]=NULL; else{ char *ofs=startline; char c; int sizestring=0; char buf[MAXLSTSTR]; for(;sizestring<(MAXLSTSTR-1);sizestring++){ c=*ofs; ofs=ofs+1; if(c==13||ofs==endinput)break; buf[sizestring]=c; } buf[sizestring]=0; strbtrim(buf); if((sizestring=strlen(buf))==0)lststring[pdbg]=NULL; else{ lststring[pdbg]=(char *)MALLOC(sizestring+1); strcpy(lststring[pdbg],buf); } } lstflag[pdbg]=(unsigned char)(am32|lsttypedata); AddEndLine(); // printf("%s(%d) outptr=%d\n",(startfileinfo+currentfileinfo)->filename,linenumber,outptr); } pdbg++; (startfileinfo+currentfileinfo)->numdline++; } }
hashmap * _p11_conf_parse_file (const char* filename, int flags) { char *name; char *value; hashmap *map = NULL; char *data; char *next; char *end; int error = 0; assert (filename); debug ("reading config file: %s", filename); /* Adds an extra newline to end of file */ data = read_config_file (filename, flags); if (!data) return NULL; map = hash_create (hash_string_hash, hash_string_equal, free, free); if (map == NULL) { free (data); errno = ENOMEM; return NULL; } next = data; /* Go through lines and process them */ while ((end = strchr (next, '\n')) != NULL) { *end = 0; name = strbtrim (next); next = end + 1; /* Empty lines / comments at start */ if (!*name || *name == '#') continue; /* Look for the break between name: value on the same line */ value = name + strcspn (name, ":"); if (!*value) { _p11_message ("%s: invalid config line: %s", filename, name); error = EINVAL; break; } /* Null terminate and split value part */ *value = 0; value++; name = strtrim (name); value = strtrim (value); name = strdup (name); if (!name) { error = ENOMEM; break; } value = strdup (value); if (!value) { free (name); error = ENOMEM; break; } debug ("config value: %s: %s", name, value); if (!hash_set (map, name, value)) { free (name); free (value); error = ENOMEM; break; } } free (data); if (error != 0) { hash_free (map); map = NULL; errno = error; } return map; }