Special case comment lines in lbufs.
This commit is contained in:
@@ -195,10 +195,18 @@ static void
|
|||||||
sudo_lbuf_println(struct sudo_lbuf *lbuf, char *line, int len)
|
sudo_lbuf_println(struct sudo_lbuf *lbuf, char *line, int len)
|
||||||
{
|
{
|
||||||
char *cp, save;
|
char *cp, save;
|
||||||
int i, have, contlen;
|
int i, have, contlen = 0;
|
||||||
|
int indent = lbuf->indent;
|
||||||
|
bool is_comment = false;
|
||||||
debug_decl(sudo_lbuf_println, SUDO_DEBUG_UTIL)
|
debug_decl(sudo_lbuf_println, SUDO_DEBUG_UTIL)
|
||||||
|
|
||||||
contlen = lbuf->continuation ? strlen(lbuf->continuation) : 0;
|
/* Comment lines don't use continuation and only indent is for "# " */
|
||||||
|
if (line[0] == '#' && isblank((unsigned char)line[1])) {
|
||||||
|
is_comment = true;
|
||||||
|
indent = 2;
|
||||||
|
}
|
||||||
|
if (lbuf->continuation != NULL && !is_comment)
|
||||||
|
contlen = strlen(lbuf->continuation);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Print the buffer, splitting the line as needed on a word
|
* Print the buffer, splitting the line as needed on a word
|
||||||
@@ -218,10 +226,14 @@ sudo_lbuf_println(struct sudo_lbuf *lbuf, char *line, int len)
|
|||||||
need = (int)(ep - cp);
|
need = (int)(ep - cp);
|
||||||
}
|
}
|
||||||
if (cp != line) {
|
if (cp != line) {
|
||||||
/* indent continued lines */
|
if (is_comment) {
|
||||||
/* XXX - build up string instead? */
|
lbuf->output("# ");
|
||||||
for (i = 0; i < lbuf->indent; i++)
|
} else {
|
||||||
lbuf->output(" ");
|
/* indent continued lines */
|
||||||
|
/* XXX - build up string instead? */
|
||||||
|
for (i = 0; i < indent; i++)
|
||||||
|
lbuf->output(" ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* NUL-terminate cp for the output function and restore afterwards */
|
/* NUL-terminate cp for the output function and restore afterwards */
|
||||||
save = cp[need];
|
save = cp[need];
|
||||||
@@ -235,7 +247,7 @@ sudo_lbuf_println(struct sudo_lbuf *lbuf, char *line, int len)
|
|||||||
* the whitespace, and print a line continuaton char if needed.
|
* the whitespace, and print a line continuaton char if needed.
|
||||||
*/
|
*/
|
||||||
if (cp != NULL) {
|
if (cp != NULL) {
|
||||||
have = lbuf->cols - lbuf->indent;
|
have = lbuf->cols - indent;
|
||||||
ep = line + len;
|
ep = line + len;
|
||||||
while (cp < ep && isblank((unsigned char)*cp)) {
|
while (cp < ep && isblank((unsigned char)*cp)) {
|
||||||
cp++;
|
cp++;
|
||||||
|
@@ -582,8 +582,8 @@ convert_sudoers_sudoers(const char *output_file, struct cvtsudoers_config *conf)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Print User_Specs */
|
/* Print User_Specs, separated by blank lines. */
|
||||||
if (!sudoers_format_userspecs(&lbuf, &userspecs, conf->expand_aliases, true))
|
if (!sudoers_format_userspecs(&lbuf, &userspecs, "\n", conf->expand_aliases, true))
|
||||||
goto done;
|
goto done;
|
||||||
if (lbuf.len > 1) {
|
if (lbuf.len > 1) {
|
||||||
sudo_lbuf_print(&lbuf);
|
sudo_lbuf_print(&lbuf);
|
||||||
|
@@ -285,7 +285,7 @@ sudoers_format_userspec(struct sudo_lbuf *lbuf, struct userspec *us,
|
|||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
sudoers_format_userspecs(struct sudo_lbuf *lbuf, struct userspec_list *usl,
|
sudoers_format_userspecs(struct sudo_lbuf *lbuf, struct userspec_list *usl,
|
||||||
bool expand_aliases, bool flush)
|
const char *sep, bool expand_aliases, bool flush)
|
||||||
{
|
{
|
||||||
struct userspec *us;
|
struct userspec *us;
|
||||||
debug_decl(sudoers_format_userspecs, SUDOERS_DEBUG_UTIL)
|
debug_decl(sudoers_format_userspecs, SUDOERS_DEBUG_UTIL)
|
||||||
@@ -293,6 +293,7 @@ sudoers_format_userspecs(struct sudo_lbuf *lbuf, struct userspec_list *usl,
|
|||||||
TAILQ_FOREACH(us, usl, entries) {
|
TAILQ_FOREACH(us, usl, entries) {
|
||||||
if (!sudoers_format_userspec(lbuf, us, expand_aliases))
|
if (!sudoers_format_userspec(lbuf, us, expand_aliases))
|
||||||
break;
|
break;
|
||||||
|
sudo_lbuf_append(lbuf, sep);
|
||||||
sudo_lbuf_print(lbuf);
|
sudo_lbuf_print(lbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -315,6 +315,6 @@ bool sudoers_format_default(struct sudo_lbuf *lbuf, struct defaults *d);
|
|||||||
bool sudoers_format_member(struct sudo_lbuf *lbuf, struct member *m, const char *separator, int alias_type);
|
bool sudoers_format_member(struct sudo_lbuf *lbuf, struct member *m, const char *separator, int alias_type);
|
||||||
bool sudoers_format_privilege(struct sudo_lbuf *lbuf, struct privilege *priv, bool expand_aliases);
|
bool sudoers_format_privilege(struct sudo_lbuf *lbuf, struct privilege *priv, bool expand_aliases);
|
||||||
bool sudoers_format_userspec(struct sudo_lbuf *lbuf, struct userspec *us, bool expand_aliases);
|
bool sudoers_format_userspec(struct sudo_lbuf *lbuf, struct userspec *us, bool expand_aliases);
|
||||||
bool sudoers_format_userspecs(struct sudo_lbuf *lbuf, struct userspec_list *usl, bool expand_aliases, bool flush);
|
bool sudoers_format_userspecs(struct sudo_lbuf *lbuf, struct userspec_list *usl, const char *sep, bool expand_aliases, bool flush);
|
||||||
|
|
||||||
#endif /* SUDOERS_PARSE_H */
|
#endif /* SUDOERS_PARSE_H */
|
||||||
|
Reference in New Issue
Block a user