/* [ DUMPENV: system tool -- version 1.1. ] ********************************** * simple system tool for dumping all processes environmental data, requires * * root to run. * * * * AUTHOR: * * v9/vade79@realhalo.org, realhalo.org. * * * * dumpenv.c: program source code for dumpenv, for linux. (98l!220w!2849b) * *****************************************************************************/ #include #include #include char id[]="$Id: dumpenv.c,v 1.1 2001/04/04 01:21:02 EST vade79 Exp $"; int main(){ int i=0; glob_t gb; setuid(geteuid()); if(getuid()) printe("dumpenv must run as root to process correctly",1); gb.gl_offs=1; glob("/proc/*",0,0,&gb); while(gb.gl_pathc>i){ if(atoi((char *)basename(gb.gl_pathv[i])) ||!strcmp((char *)basename(gb.gl_pathv[i]),"0")) getenviron((char *)basename(gb.gl_pathv[i])); i++; } globfree(&gb); exit(0); } int getenviron(char *pid){ int i=0; int chr=0; char *envfile; char *cmdfile; char cmd[256]; char string[4096]; FILE *fd; struct stat mod; if(!(envfile=(char *)malloc(strlen(pid)+15))) printe("getenviron(): allocating memory",0); sprintf(envfile,"/proc/%s/environ",pid); if(!(cmdfile=(char *)malloc(strlen(pid)+15))) printe("getenviron(): allocating memory",0); sprintf(cmdfile,"/proc/%s/cmdline",pid); if(!(fd=fopen(cmdfile,"r"))) printe("command line of the pid doesn't exist or isn't readable",0); else{ bzero(cmd,sizeof(cmd)); while((chr=fgetc(fd))!=0x0&&chr!=0x20&&chr!=EOF) if(isprint(chr)) if(isizeof(string)){ bzero(string,sizeof(string)); i=0; } } else if(chr==0x0){ if(strlen(string)) printf("P:%s C:%s U:%u G:%u E:%s\n",pid,basename(cmd),mod.st_uid, mod.st_gid,string); bzero(string,sizeof(string)); i=0; } } if(strlen(string)) printf("P:%s C:%s U:%u G:%u E:%s\n",pid,basename(cmd),mod.st_uid, mod.st_gid,string); } } fclose(fd); free(envfile); free(cmdfile); return(0); } int printe(char *err,int quit){ printf("error: %s.\n",err); if(quit) exit(1); }