X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=fileops.c;h=ca4903fe0987aef66da165e446573ebbcd0c67d3;hb=4caa124853fc7152ada5797144498078861086c2;hp=ff6444c96412ddb9d35154bf1cf76df8dfbcb329;hpb=c2b0b328d4a66431e671fb26b47997033feb5e29;p=debian%2Fsudo diff --git a/fileops.c b/fileops.c index ff6444c..ca4903f 100644 --- a/fileops.c +++ b/fileops.c @@ -1,5 +1,6 @@ /* - * Copyright (c) 1999, 2001 Todd C. Miller + * Copyright (c) 1999-2005, 2007, 2009, 2010 + * Todd C. Miller * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -18,7 +19,7 @@ * Materiel Command, USAF, under agreement number F39502-99-1-0512. */ -#include "config.h" +#include #include #include @@ -27,41 +28,54 @@ # include #endif /* HAVE_FLOCK */ #include +#ifdef HAVE_STRING_H +# include +#endif /* HAVE_STRING_H */ +#ifdef HAVE_STRINGS_H +# include +#endif /* HAVE_STRINGS_H */ +#include +#include #ifdef HAVE_UNISTD_H # include #endif /* HAVE_UNISTD_H */ #include -#include +#if TIME_WITH_SYS_TIME +# include +#endif +#ifndef HAVE_TIMESPEC +# include +#endif #include "sudo.h" -#ifndef lint -static const char rcsid[] = "$Sudo: fileops.c,v 1.9 2004/09/08 15:48:23 millert Exp $"; -#endif /* lint */ +#ifndef LINE_MAX +# define LINE_MAX 2048 +#endif /* * Update the access and modify times on an fd or file. */ int -touch(fd, path, tsp) +touch(fd, path, tvp) int fd; char *path; - struct timespec *tsp; + struct timeval *tvp; { struct timeval times[2]; - if (tsp != NULL) { - times[0].tv_sec = times[1].tv_sec = tsp->tv_sec; - times[0].tv_usec = times[1].tv_usec = tsp->tv_nsec / 1000; + if (tvp != NULL) { + times[0].tv_sec = times[1].tv_sec = tvp->tv_sec; + times[0].tv_usec = times[1].tv_usec = tvp->tv_usec; } #if defined(HAVE_FUTIME) || defined(HAVE_FUTIMES) if (fd != -1) - return(futimes(fd, tsp ? times : NULL)); + return(futimes(fd, tvp ? times : NULL)); else #endif if (path != NULL) - return(utimes(path, tsp ? times : NULL)); + return(utimes(path, tvp ? times : NULL)); else return(-1); } @@ -126,7 +140,7 @@ lock_file(fd, lockit) lock.l_pid = getpid(); lock.l_type = (lockit == SUDO_UNLOCK) ? F_UNLCK : F_WRLCK; lock.l_whence = SEEK_SET; - func = (lockit == SUDO_TLOCK) ? F_SETLK : F_SETLKW; + func = (lockit == SUDO_LOCK) ? F_SETLKW : F_SETLK; return(fcntl(fd, func, &lock) == 0); #else @@ -134,3 +148,30 @@ lock_file(fd, lockit) #endif } #endif + +/* + * Read a line of input, remove comments and strip off leading + * and trailing spaces. Returns static storage that is reused. + */ +char * +sudo_parseln(fp) + FILE *fp; +{ + size_t len; + char *cp = NULL; + static char buf[LINE_MAX]; + + if (fgets(buf, sizeof(buf), fp) != NULL) { + /* Remove comments */ + if ((cp = strchr(buf, '#')) != NULL) + *cp = '\0'; + + /* Trim leading and trailing whitespace/newline */ + len = strlen(buf); + while (len > 0 && isspace((unsigned char)buf[len - 1])) + buf[--len] = '\0'; + for (cp = buf; isblank(*cp); cp++) + continue; + } + return(cp); +}