From 35f3e6fac31f4cf005516ab61a345cff9b22df10 Mon Sep 17 00:00:00 2001 From: fredrik Date: Fri, 22 Jul 2005 03:39:59 +0000 Subject: [PATCH] Initial import. git-svn-id: svn+ssh://svn.dolda2000.com/srv/svn/repos/src/utils@300 959494ce-11ee-0310-bf91-de5d638817bd --- krb5mapcc.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 krb5mapcc.c diff --git a/krb5mapcc.c b/krb5mapcc.c new file mode 100644 index 0000000..0cc3418 --- /dev/null +++ b/krb5mapcc.c @@ -0,0 +1,95 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +int isnumeric(char *str) +{ + while(*str) { + if(!isdigit(*str)) + return(0); + str++; + } + return(1); +} + +char *findcc(int fd) +{ + int ret, dlen; + static char retbuf[1024]; + char readbuf[1024]; + char *p, *p2; + + dlen = 0; + p = readbuf; + do { + if(dlen == 1024) + dlen = 0; + ret = read(fd, readbuf + dlen, sizeof(readbuf) - dlen); + if(ret < 0) { + perror("read environ"); + return(NULL); + } + dlen += ret; + + while((p = memchr(readbuf, 0, dlen)) != NULL) { + if((p2 = strchr(readbuf, '=')) != NULL) { + *(p2++) = 0; + if(!strcasecmp(readbuf, "KRB5CCNAME") && !strncasecmp(p2, "FILE:", 5)) { + if(strlen(p2 + 5) >= sizeof(retbuf)) { + fprintf(stderr, "really long ccname!\n"); + return(NULL); + } + strcpy(retbuf, p2 + 5); + return(retbuf); + } + } + p++; + memmove(readbuf, p, dlen -= (p - readbuf)); + } + } while(ret != 0); + return(NULL); +} + +int main(int argc, char **argv) +{ + int fd; + DIR *proc; + struct dirent *de; + char envbuf[1024]; + char *p, *cc; + + if((proc = opendir("/proc")) == NULL) { + perror("/proc"); + exit(1); + } + while((de = readdir(proc)) != NULL) { + if(!isnumeric(de->d_name)) + continue; + if(strlen(de->d_name) > 30) + continue; + + p = envbuf; + strcpy(p, "/proc/"); + p += 6; + strcpy(p, de->d_name); + p += strlen(de->d_name); + *(p++) = '/'; + strcpy(p, "environ"); + + if((fd = open(envbuf, O_RDONLY)) < 0) + continue; + cc = findcc(fd); + close(fd); + + if(cc != NULL) { + printf("%s %s\n", de->d_name, cc); + } + } + closedir(proc); + return(0); +} -- 2.11.0