More error checking in in.tokend

This commit is contained in:
Neale Pickett 2010-09-03 15:59:08 -06:00
parent 074da9af7d
commit abe8591569
1 changed files with 23 additions and 8 deletions

View File

@ -1,4 +1,5 @@
#include <sys/types.h> #include <sys/types.h>
#include <errno.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
@ -139,16 +140,30 @@ main(int argc, char *argv[])
int ret; int ret;
struct flock lock; struct flock lock;
fd = open(tokenlog, O_WRONLY | O_CREAT, 0644); do {
if (-1 == fd) { fd = open(tokenlog, O_WRONLY | O_CREAT, 0644);
write(1, "!write", 6); if (-1 == fd) break;
ret = lockf(fd, F_LOCK, 0);
if (-1 == ret) break;
ret = lseek(fd, 0, SEEK_END);
if (-1 == ret) break;
ret = write(fd, token, tokenlen);
if (-1 == ret) break;
ret = write(fd, "\n", 1);
if (-1 == ret) break;
ret = close(fd);
if (-1 == ret) break;
} while (0);
if (-1 == ret) {
printf("!%s", strerror(errno));
return 0; return 0;
} }
lockf(fd, F_LOCK, 0);
lseek(fd, 0, SEEK_END);
write(fd, token, tokenlen);
write(fd, "\n", 1);
close(fd);
} }
/* Encrypt the token. Note that now tokenlen is in uint32_ts, not /* Encrypt the token. Note that now tokenlen is in uint32_ts, not