From abe859156972211c534e4af51541ac298a0c50c7 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Fri, 3 Sep 2010 15:59:08 -0600 Subject: [PATCH] More error checking in in.tokend --- src/in.tokend.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/in.tokend.c b/src/in.tokend.c index 486bb8f..c0353ec 100644 --- a/src/in.tokend.c +++ b/src/in.tokend.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -139,16 +140,30 @@ main(int argc, char *argv[]) int ret; struct flock lock; - fd = open(tokenlog, O_WRONLY | O_CREAT, 0644); - if (-1 == fd) { - write(1, "!write", 6); + do { + fd = open(tokenlog, O_WRONLY | O_CREAT, 0644); + 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; } - 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