at the beginning of the line. Use the flag when parsing ldap.conf.
/*
- * 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.
*/
/* 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 *);
/*
- * 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
* 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;
/* 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;
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);
+}
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);
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;
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
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;
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 */
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 */
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;