summaryrefslogtreecommitdiff
path: root/usr.bin/sudo/fileops.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2008-11-14 11:58:09 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2008-11-14 11:58:09 +0000
commit4dcc6f61d2ac432522cb0d8249ced4b2437da0a5 (patch)
tree7b176ffeeb7bda768ae52a14198616c2982e1231 /usr.bin/sudo/fileops.c
parentb947682bc3ae9dc4a24d5a2c48e88d01ecd53b63 (diff)
Upgrade to sudo 1.7. See the WHATSNEW files for details.
Diffstat (limited to 'usr.bin/sudo/fileops.c')
-rw-r--r--usr.bin/sudo/fileops.c44
1 files changed, 42 insertions, 2 deletions
diff --git a/usr.bin/sudo/fileops.c b/usr.bin/sudo/fileops.c
index e15c5127888..9f176bd4064 100644
--- a/usr.bin/sudo/fileops.c
+++ b/usr.bin/sudo/fileops.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999-2005 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 1999-2005, 2007 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -27,6 +27,15 @@
# include <sys/file.h>
#endif /* HAVE_FLOCK */
#include <stdio.h>
+#ifdef HAVE_STRING_H
+# include <string.h>
+#else
+# ifdef HAVE_STRINGS_H
+# include <strings.h>
+# endif
+#endif /* HAVE_STRING_H */
+#include <ctype.h>
+#include <limits.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif /* HAVE_UNISTD_H */
@@ -40,8 +49,12 @@
#include "sudo.h"
+#ifndef LINE_MAX
+# define LINE_MAX 2048
+#endif
+
#ifndef lint
-__unused static const char rcsid[] = "$Sudo: fileops.c,v 1.5.2.5 2007/06/12 01:28:41 millert Exp $";
+__unused static const char rcsid[] = "$Sudo: fileops.c,v 1.16 2008/11/09 14:13:12 millert Exp $";
#endif /* lint */
/*
@@ -139,3 +152,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(buf[len - 1]))
+ buf[--len] = '\0';
+ for (cp = buf; isblank(*cp); cp++)
+ continue;
+ }
+ return(cp);
+}