X-Git-Url: http://dolda2000.com/gitweb/?p=utils.git;a=blobdiff_plain;f=krb5mapcc.c;fp=krb5mapcc.c;h=0cc3418494c1a8fdff021ac4ee0efe8e2a1bb950;hp=0000000000000000000000000000000000000000;hb=35f3e6fac31f4cf005516ab61a345cff9b22df10;hpb=375cc58e73f1f96ea52ec5a7ed9aaedfc16f5023 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); +}