]> granicus.if.org Git - sudo/commitdiff
Add a flags option to sudo_parseln() and a flag to only mach comments
authorTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 1 Sep 2016 15:19:20 +0000 (09:19 -0600)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 1 Sep 2016 15:19:20 +0000 (09:19 -0600)
at the beginning of the line.  Use the flag when parsing ldap.conf.

include/sudo_util.h
lib/util/parseln.c
lib/util/regress/sudo_parseln/parseln_test.c
lib/util/sudo_conf.c
lib/util/util.exp.in
plugins/sudoers/env.c
plugins/sudoers/ldap.c
plugins/sudoers/sudo_nss.c

index 78d4a2d5bf008f0015f4e5d949313c0772a10154..7495b84ab89a330470ccc70fef869f3f7af08d8f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2015 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 2013-2016 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
 #define sudo_isset(_a, _i)     ((_a)[(_i) / NBBY] & (1<<((_i) % NBBY)))
 #define sudo_isclr(_a, _i)     (((_a)[(_i) / NBBY] & (1<<((_i) % NBBY))) == 0)
 
+/* sudo_parseln() flags */
+#define PARSELN_COMM_BOL       1       /* comments only at begining of line */
+
 /*
  * Macros to quiet gcc's warn_unused_result attribute.
  */
@@ -190,7 +193,8 @@ __dso_public bool sudo_lock_region_v1(int fd, int action, off_t len);
 
 /* parseln.c */
 __dso_public ssize_t sudo_parseln_v1(char **buf, size_t *bufsize, unsigned int *lineno, FILE *fp);
-#define sudo_parseln(_a, _b, _c, _d) sudo_parseln_v1((_a), (_b), (_c), (_d))
+__dso_public ssize_t sudo_parseln_v2(char **buf, size_t *bufsize, unsigned int *lineno, FILE *fp, int flags);
+#define sudo_parseln(_a, _b, _c, _d, _e) sudo_parseln_v2((_a), (_b), (_c), (_d), (_e))
 
 /* progname.c */
 __dso_public void initprogname(const char *);
index a1aae0d89c62252af521389ded7261d862c7278d..6f3eac4cd28c1139633d9dbd7f453bd206bd6e41 100644 (file)
@@ -1,6 +1,5 @@
 /*
- * Copyright (c) 2007, 2013-2015
- *     Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 2007, 2013-2016 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
@@ -46,7 +45,7 @@
  *       could also make comment char and line continuation configurable
  */
 ssize_t
-sudo_parseln_v1(char **bufp, size_t *bufsizep, unsigned int *lineno, FILE *fp)
+sudo_parseln_v2(char **bufp, size_t *bufsizep, unsigned int *lineno, FILE *fp, int flags)
 {
     size_t linesize = 0, total = 0;
     ssize_t len;
@@ -68,8 +67,10 @@ sudo_parseln_v1(char **bufp, size_t *bufsizep, unsigned int *lineno, FILE *fp)
 
        /* Remove comments or check for line continuation (but not both) */
        if ((cp = strchr(line, '#')) != NULL) {
-           *cp = '\0';
-           len = (ssize_t)(cp - line);
+           if (cp == line || !ISSET(flags, PARSELN_COMM_BOL)) {
+               *cp = '\0';
+               len = (ssize_t)(cp - line);
+           }
        } else if (len > 0 && line[len - 1] == '\\' && (len == 1 || line[len - 2] != '\\')) {
            line[--len] = '\0';
            continued = true;
@@ -117,3 +118,9 @@ sudo_parseln_v1(char **bufp, size_t *bufsizep, unsigned int *lineno, FILE *fp)
        debug_return_ssize_t(-1);
     debug_return_ssize_t(total);
 }
+
+ssize_t
+sudo_parseln_v1(char **bufp, size_t *bufsizep, unsigned int *lineno, FILE *fp)
+{
+    return sudo_parseln_v2(bufp, bufsizep, lineno, fp, 0);
+}
index 9dac11ec2a16586b3fe2517432416e9b81863de3..32dc0ae75764643b2f2af75c55f3583a402c2d2f 100644 (file)
@@ -51,7 +51,7 @@ main(int argc, char *argv[])
 
     initprogname(argc > 0 ? argv[0] : "parseln_test");
 
-    while (sudo_parseln(&line, &linesize, &lineno, stdin) != -1)
+    while (sudo_parseln(&line, &linesize, &lineno, stdin, 0) != -1)
        printf("%6u\t%s\n", lineno, line);
     free(line);
     exit(0);
index 08556bb13361c17f3b20af75c68e46dac39dd259..399e70be3d1a108db51663cea1547140830f2356 100644 (file)
@@ -609,7 +609,7 @@ sudo_conf_read_v1(const char *conf_file, int conf_types)
        goto done;
     }
 
-    while (sudo_parseln(&line, &linesize, &conf_lineno, fp) != -1) {
+    while (sudo_parseln(&line, &linesize, &conf_lineno, fp, 0) != -1) {
        struct sudo_conf_table *cur;
        unsigned int i;
        char *cp;
index a7e0efb3c89c782efb04779ab9a39cb04bbe7e7a..d29a00669e94887aa4f7a0bf78316243d335e8f1 100644 (file)
@@ -71,6 +71,7 @@ sudo_lock_region_v1
 sudo_new_key_val_v1
 sudo_parse_gids_v1
 sudo_parseln_v1
+sudo_parseln_v2
 sudo_secure_dir_v1
 sudo_secure_file_v1
 sudo_setgroups_v1
index 238d9124840a82ce4e4a39468857e83fcb35db48..daecd55b5f769393e2d5b1459d4085aab712a9ca 100644 (file)
@@ -1184,7 +1184,7 @@ read_env_file(const char *path, int overwrite)
        debug_return_bool(rval);
     }
 
-    while (sudo_parseln(&line, &linesize, NULL, fp) != -1) {
+    while (sudo_parseln(&line, &linesize, NULL, fp, 0) != -1) {
        /* Skip blank or comment lines */
        if (*(var = line) == '\0')
            continue;
index 5130bcd69dc81b2f1f1a4af225441b5cb9b68cb8..552e15a72a0363c608ba73754eea066a628aa984 100644 (file)
@@ -2024,7 +2024,7 @@ sudo_ldap_read_config(void)
     if ((fp = fopen(path_ldap_conf, "r")) == NULL)
        debug_return_bool(false);
 
-    while (sudo_parseln(&line, &linesize, NULL, fp) != -1) {
+    while (sudo_parseln(&line, &linesize, NULL, fp, PARSELN_COMM_BOL) != -1) {
        if (*line == '\0')
            continue;           /* skip empty line */
 
index 77e095f4258b2b90cfcaae66159e231533c3e29c..18f4de0020692ecd6495962b5c06323a04e378d0 100644 (file)
@@ -76,7 +76,7 @@ sudo_read_nss(void)
     if ((fp = fopen(_PATH_NSSWITCH_CONF, "r")) == NULL)
        goto nomatch;
 
-    while (sudo_parseln(&line, &linesize, NULL, fp) != -1) {
+    while (sudo_parseln(&line, &linesize, NULL, fp, 0) != -1) {
        char *cp, *last;
 
        /* Skip blank or comment lines */
@@ -156,7 +156,7 @@ sudo_read_nss(void)
     if ((fp = fopen(_PATH_NETSVC_CONF, "r")) == NULL)
        goto nomatch;
 
-    while (sudo_parseln(&line, &linesize, NULL, fp) != -1) {
+    while (sudo_parseln(&line, &linesize, NULL, fp, 0) != -1) {
        /* Skip blank or comment lines */
        if (*(cp = line) == '\0')
            continue;