X-Git-Url: http://www.average.org/gitweb/?p=pam_pcsc_cr.git;a=blobdiff_plain;f=authfile.c;h=c43b2d655b0a6f2ee1d7640b648b0cc0cf9f35c7;hp=923cb8824fb31db39089e451edb95120de02d780;hb=01f9e2f01d2fac650601ba5a2573cd21f57744b5;hpb=da2a84904dd17e4ed70a6497c0d18f69d004d453;ds=inline diff --git a/authfile.c b/authfile.c index 923cb88..c43b2d6 100644 --- a/authfile.c +++ b/authfile.c @@ -136,6 +136,7 @@ struct _auth_obj authfile(const char *tokenid, FILE *fp = NULL; char *fn, *nfn; int fnl; + struct stat st = {0}; char *buf = NULL; struct { const char *tokenid; @@ -159,10 +160,7 @@ struct _auth_obj authfile(const char *tokenid, snprintf(nfn, fnl+32, "%s.%d.%ld", fn, (int)getpid(), (long)time(NULL)); fp = fopen(fn, "r"); if (fp) { - struct stat st; - int fd = fileno(fp); - - if (fstat(fd, &st)) st.st_size = 2047; + if (fstat(fileno(fp), &st)) st.st_size = 2047; if (st.st_size > 2047) st.st_size = 2047; buf = alloca(st.st_size + 1); if (!fgets(buf, st.st_size + 1, fp)) { @@ -225,6 +223,9 @@ struct _auth_obj authfile(const char *tokenid, ret.err = strerror(errno); } fprintf(fp, "\n"); + if (st.st_uid || st.st_gid) { + if (fchown(fileno(fp), st.st_uid, st.st_gid)) /*ign*/; + } if (fclose(fp) < 0) { ret.err = strerror(errno); }