1993-03-02 16:33:11 +00:00
|
|
|
%{
|
1993-11-27 23:42:49 +00:00
|
|
|
/*
|
2019-04-29 07:21:51 -06:00
|
|
|
* SPDX-License-Identifier: ISC
|
|
|
|
*
|
2020-03-11 11:17:38 -06:00
|
|
|
* Copyright (c) 1996, 1998-2005, 2007-2020
|
2017-12-03 17:53:40 -07:00
|
|
|
* Todd C. Miller <Todd.Miller@sudo.ws>
|
1995-03-29 04:12:17 +00:00
|
|
|
*
|
2004-02-13 21:36:43 +00:00
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
2003-04-16 00:42:10 +00:00
|
|
|
*
|
|
|
|
* Sponsored in part by the Defense Advanced Research Projects
|
|
|
|
* Agency (DARPA) and Air Force Research Laboratory, Air Force
|
|
|
|
* Materiel Command, USAF, under agreement number F39502-99-1-0512.
|
1993-03-02 16:33:11 +00:00
|
|
|
*/
|
1993-11-27 23:42:49 +00:00
|
|
|
|
2004-11-19 18:39:14 +00:00
|
|
|
#include <config.h>
|
1995-09-01 04:24:52 +00:00
|
|
|
|
2001-12-14 19:52:54 +00:00
|
|
|
#include <sys/types.h>
|
2009-04-18 23:25:08 +00:00
|
|
|
#include <sys/stat.h>
|
2001-12-14 19:52:54 +00:00
|
|
|
#include <stdio.h>
|
2015-06-19 14:29:27 -06:00
|
|
|
#include <stdlib.h>
|
2020-05-18 07:59:24 -06:00
|
|
|
#include <string.h>
|
2013-04-16 12:16:41 -04:00
|
|
|
#if defined(HAVE_STDINT_H)
|
|
|
|
# include <stdint.h>
|
|
|
|
#elif defined(HAVE_INTTYPES_H)
|
|
|
|
# include <inttypes.h>
|
|
|
|
#endif
|
2015-07-02 09:08:28 -06:00
|
|
|
#include <unistd.h>
|
2015-07-02 09:24:48 -06:00
|
|
|
#include <dirent.h>
|
2011-04-14 14:27:11 -04:00
|
|
|
#include <errno.h>
|
1995-03-24 03:32:53 +00:00
|
|
|
#include <ctype.h>
|
2010-03-17 19:56:27 -04:00
|
|
|
#include "sudoers.h"
|
2011-01-08 15:42:39 -05:00
|
|
|
#include "toke.h"
|
2011-11-12 12:18:44 -05:00
|
|
|
#include <gram.h>
|
2018-05-24 21:04:07 -06:00
|
|
|
#include "sudo_digest.h"
|
2014-06-26 15:51:15 -06:00
|
|
|
#include "sudo_lbuf.h"
|
1993-10-18 00:31:49 +00:00
|
|
|
|
2015-07-02 09:24:48 -06:00
|
|
|
#if defined(HAVE_STRUCT_DIRENT_D_NAMLEN) && HAVE_STRUCT_DIRENT_D_NAMLEN
|
|
|
|
# define NAMLEN(dirent) (dirent)->d_namlen
|
|
|
|
#else
|
|
|
|
# define NAMLEN(dirent) strlen((dirent)->d_name)
|
|
|
|
#endif
|
|
|
|
|
2013-12-16 14:18:42 -07:00
|
|
|
int sudolineno; /* current sudoers line number. */
|
|
|
|
char *sudoers; /* sudoers file being parsed. */
|
2020-08-06 21:16:35 -06:00
|
|
|
struct sudolinebuf sudolinebuf; /* sudoers line being parsed. */
|
2020-09-27 10:05:35 -06:00
|
|
|
extern int sudoerschar; /* last token that was parsed. */
|
2011-03-20 21:25:57 -04:00
|
|
|
|
2012-03-02 11:04:09 -05:00
|
|
|
/* Default sudoers path, mode and owner (may be set via sudo.conf) */
|
2012-02-29 15:50:48 -05:00
|
|
|
const char *sudoers_file = _PATH_SUDOERS;
|
|
|
|
mode_t sudoers_mode = SUDOERS_MODE;
|
|
|
|
uid_t sudoers_uid = SUDOERS_UID;
|
|
|
|
gid_t sudoers_gid = SUDOERS_GID;
|
|
|
|
|
2011-12-02 11:27:33 -05:00
|
|
|
static bool continued, sawspace;
|
|
|
|
static int prev_state;
|
2018-05-24 21:04:07 -06:00
|
|
|
static int digest_type = -1;
|
1995-03-24 03:32:53 +00:00
|
|
|
|
2011-12-02 11:27:33 -05:00
|
|
|
static bool pop_include(void);
|
2020-08-06 21:16:35 -06:00
|
|
|
static yy_size_t sudoers_input(char *buf, yy_size_t max_size);
|
2004-09-27 16:03:15 +00:00
|
|
|
|
2011-03-21 17:57:38 -04:00
|
|
|
int (*trace_print)(const char *msg) = sudoers_trace_print;
|
|
|
|
|
2012-09-14 16:19:25 -04:00
|
|
|
#define ECHO ignore_result(fwrite(sudoerstext, sudoersleng, 1, sudoersout))
|
2020-08-06 21:16:35 -06:00
|
|
|
|
|
|
|
#define YY_INPUT(buf, result, max_size) (result) = sudoers_input(buf, max_size)
|
|
|
|
|
2020-08-07 14:13:25 -06:00
|
|
|
#define YY_USER_ACTION do { \
|
|
|
|
sudolinebuf.toke_start = sudolinebuf.toke_end; \
|
|
|
|
sudolinebuf.toke_end += sudoersleng; \
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
#define sudoersless(n) do { \
|
|
|
|
sudolinebuf.toke_end = sudolinebuf.toke_start + (n); \
|
|
|
|
yyless(n); \
|
|
|
|
} while (0);
|
|
|
|
|
1993-03-02 16:33:11 +00:00
|
|
|
%}
|
|
|
|
|
2007-08-25 02:47:54 +00:00
|
|
|
HEX16 [0-9A-Fa-f]{1,4}
|
1999-08-28 08:22:27 +00:00
|
|
|
OCTET (1?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5])
|
2007-08-25 02:47:54 +00:00
|
|
|
IPV4ADDR {OCTET}(\.{OCTET}){3}
|
|
|
|
IPV6ADDR ({HEX16}?:){2,7}{HEX16}?|({HEX16}?:){2,6}:{IPV4ADDR}
|
2007-08-13 16:29:25 +00:00
|
|
|
|
1999-08-12 14:29:12 +00:00
|
|
|
HOSTNAME [[:alnum:]_-]+
|
2019-03-03 14:41:59 -07:00
|
|
|
WORD ([^#>!=:,\(\) \t\r\n\\\"]|\\[^\t\n])+
|
2007-08-22 22:23:59 +00:00
|
|
|
ID #-?[0-9]+
|
2019-03-03 14:41:59 -07:00
|
|
|
PATH \/(\\[\,:= \t#]|[^\,:=\\ \t\r\n#])+
|
|
|
|
ENVAR ([^#!=, \t\r\n\\\"]|\\[^\r\n])([^#=, \t\r\n\\\"]|\\[^\r\n])*
|
2001-12-11 23:05:44 +00:00
|
|
|
DEFVAR [a-z_]+
|
1995-03-24 03:32:53 +00:00
|
|
|
|
2010-08-02 18:17:51 -04:00
|
|
|
%option noinput
|
2004-09-29 18:29:40 +00:00
|
|
|
%option nounput
|
2004-10-26 22:12:47 +00:00
|
|
|
%option noyywrap
|
2012-09-14 16:19:25 -04:00
|
|
|
%option prefix="sudoers"
|
2004-09-29 18:29:40 +00:00
|
|
|
|
1999-09-08 08:06:28 +00:00
|
|
|
%s GOTDEFS
|
2001-12-11 23:05:44 +00:00
|
|
|
%x GOTCMND
|
|
|
|
%x STARTDEFS
|
|
|
|
%x INDEFS
|
2007-08-20 23:19:44 +00:00
|
|
|
%x INSTR
|
2013-04-15 15:12:00 -04:00
|
|
|
%s WANTDIGEST
|
2020-05-20 13:10:53 -06:00
|
|
|
%x GOTINC
|
2020-09-01 06:26:00 -06:00
|
|
|
%s EXPECTPATH
|
1995-08-14 04:07:15 +00:00
|
|
|
|
1993-03-02 16:33:11 +00:00
|
|
|
%%
|
2011-03-17 16:36:13 -04:00
|
|
|
<GOTDEFS>[[:blank:]]*,[[:blank:]]* {
|
|
|
|
LEXTRACE(", ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return ',';
|
2011-03-17 16:36:13 -04:00
|
|
|
} /* return ',' */
|
|
|
|
|
2001-12-11 23:05:44 +00:00
|
|
|
<GOTDEFS>[[:blank:]]+ BEGIN STARTDEFS;
|
|
|
|
|
|
|
|
<STARTDEFS>{DEFVAR} {
|
|
|
|
BEGIN INDEFS;
|
|
|
|
LEXTRACE("DEFVAR ");
|
2012-09-14 16:19:25 -04:00
|
|
|
if (!fill(sudoerstext, sudoersleng))
|
2004-09-28 00:47:30 +00:00
|
|
|
yyterminate();
|
2020-09-26 06:39:57 -06:00
|
|
|
return DEFVAR;
|
1995-09-09 22:34:40 +00:00
|
|
|
}
|
1995-08-14 04:07:15 +00:00
|
|
|
|
2001-12-11 23:05:44 +00:00
|
|
|
<INDEFS>{
|
|
|
|
, {
|
|
|
|
BEGIN STARTDEFS;
|
|
|
|
LEXTRACE(", ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return ',';
|
2001-12-11 23:05:44 +00:00
|
|
|
} /* return ',' */
|
1995-08-14 04:07:15 +00:00
|
|
|
|
2001-12-11 23:05:44 +00:00
|
|
|
= {
|
|
|
|
LEXTRACE("= ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return '=';
|
2001-12-11 23:05:44 +00:00
|
|
|
} /* return '=' */
|
1995-09-09 22:34:40 +00:00
|
|
|
|
2001-12-11 23:05:44 +00:00
|
|
|
\+= {
|
|
|
|
LEXTRACE("+= ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return '+';
|
2001-12-11 23:05:44 +00:00
|
|
|
} /* return '+' */
|
|
|
|
|
|
|
|
-= {
|
|
|
|
LEXTRACE("-= ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return '-';
|
2001-12-11 23:05:44 +00:00
|
|
|
} /* return '-' */
|
|
|
|
|
2007-08-20 23:19:44 +00:00
|
|
|
\" {
|
|
|
|
LEXTRACE("BEGINSTR ");
|
2012-09-14 16:19:25 -04:00
|
|
|
sudoerslval.string = NULL;
|
2011-01-31 15:13:51 -05:00
|
|
|
prev_state = YY_START;
|
2007-08-20 23:19:44 +00:00
|
|
|
BEGIN INSTR;
|
1999-09-08 08:06:28 +00:00
|
|
|
}
|
2001-12-30 22:12:06 +00:00
|
|
|
|
|
|
|
{ENVAR} {
|
|
|
|
LEXTRACE("WORD(2) ");
|
2012-09-14 16:19:25 -04:00
|
|
|
if (!fill(sudoerstext, sudoersleng))
|
2004-09-28 00:47:30 +00:00
|
|
|
yyterminate();
|
2020-09-26 06:39:57 -06:00
|
|
|
return WORD;
|
2001-12-30 22:12:06 +00:00
|
|
|
}
|
2001-12-11 23:05:44 +00:00
|
|
|
}
|
1999-09-08 08:06:28 +00:00
|
|
|
|
2007-08-20 23:19:44 +00:00
|
|
|
<INSTR>{
|
2019-03-03 14:41:59 -07:00
|
|
|
\\[[:blank:]]*\r?\n[[:blank:]]* {
|
2007-08-20 23:19:44 +00:00
|
|
|
/* Line continuation char followed by newline. */
|
2011-11-05 07:37:14 -04:00
|
|
|
sudolineno++;
|
2011-12-02 11:27:33 -05:00
|
|
|
continued = true;
|
2007-08-20 23:19:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
\" {
|
|
|
|
LEXTRACE("ENDSTR ");
|
2011-01-31 15:13:51 -05:00
|
|
|
BEGIN prev_state;
|
2011-03-23 18:51:57 -04:00
|
|
|
|
2012-09-14 16:19:25 -04:00
|
|
|
if (sudoerslval.string == NULL) {
|
2020-09-27 06:51:16 -06:00
|
|
|
sudoerserror(N_("empty string"));
|
2020-08-07 14:20:45 -06:00
|
|
|
LEXTRACE("ERROR ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return ERROR;
|
2011-03-23 18:51:57 -04:00
|
|
|
}
|
2019-08-20 10:25:38 -06:00
|
|
|
if (prev_state == INITIAL || prev_state == GOTDEFS) {
|
2012-09-14 16:19:25 -04:00
|
|
|
switch (sudoerslval.string[0]) {
|
2011-01-31 15:13:51 -05:00
|
|
|
case '%':
|
2012-09-14 16:19:25 -04:00
|
|
|
if (sudoerslval.string[1] == '\0' ||
|
|
|
|
(sudoerslval.string[1] == ':' &&
|
|
|
|
sudoerslval.string[2] == '\0')) {
|
2020-09-27 06:51:16 -06:00
|
|
|
sudoerserror(N_("empty group"));
|
2020-08-07 14:20:45 -06:00
|
|
|
LEXTRACE("ERROR ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return ERROR;
|
2011-03-24 11:00:30 -04:00
|
|
|
}
|
2011-01-31 15:13:51 -05:00
|
|
|
LEXTRACE("USERGROUP ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return USERGROUP;
|
2011-01-31 15:13:51 -05:00
|
|
|
case '+':
|
2012-09-14 16:19:25 -04:00
|
|
|
if (sudoerslval.string[1] == '\0') {
|
2020-09-27 06:51:16 -06:00
|
|
|
sudoerserror(N_("empty netgroup"));
|
2020-08-07 14:20:45 -06:00
|
|
|
LEXTRACE("ERROR ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return ERROR;
|
2011-03-24 11:00:30 -04:00
|
|
|
}
|
2011-01-31 15:13:51 -05:00
|
|
|
LEXTRACE("NETGROUP ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return NETGROUP;
|
2011-01-31 15:13:51 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
LEXTRACE("WORD(4) ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return WORD;
|
2007-08-20 23:19:44 +00:00
|
|
|
}
|
|
|
|
|
2008-06-26 11:49:16 +00:00
|
|
|
\\ {
|
|
|
|
LEXTRACE("BACKSLASH ");
|
2012-09-14 16:19:25 -04:00
|
|
|
if (!append(sudoerstext, sudoersleng))
|
2008-06-26 11:49:16 +00:00
|
|
|
yyterminate();
|
|
|
|
}
|
|
|
|
|
2019-03-03 14:41:59 -07:00
|
|
|
([^\"\r\n\\]|\\\")+ {
|
2007-08-20 23:19:44 +00:00
|
|
|
LEXTRACE("STRBODY ");
|
2012-09-14 16:19:25 -04:00
|
|
|
if (!append(sudoerstext, sudoersleng))
|
2007-08-20 23:19:44 +00:00
|
|
|
yyterminate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-11 23:05:44 +00:00
|
|
|
<GOTCMND>{
|
2004-05-17 20:51:13 +00:00
|
|
|
\\[\*\?\[\]\!] {
|
|
|
|
/* quoted fnmatch glob char, pass verbatim */
|
|
|
|
LEXTRACE("QUOTEDCHAR ");
|
2012-09-14 16:19:25 -04:00
|
|
|
if (!fill_args(sudoerstext, 2, sawspace))
|
2004-09-28 00:47:30 +00:00
|
|
|
yyterminate();
|
2011-12-02 11:27:33 -05:00
|
|
|
sawspace = false;
|
2004-05-17 20:51:13 +00:00
|
|
|
}
|
|
|
|
|
2002-01-15 18:16:31 +00:00
|
|
|
\\[:\\,= \t#] {
|
2004-05-17 20:51:13 +00:00
|
|
|
/* quoted sudoers special char, strip backslash */
|
2001-12-11 23:05:44 +00:00
|
|
|
LEXTRACE("QUOTEDCHAR ");
|
2012-09-14 16:19:25 -04:00
|
|
|
if (!fill_args(sudoerstext + 1, 1, sawspace))
|
2004-09-28 00:47:30 +00:00
|
|
|
yyterminate();
|
2011-12-02 11:27:33 -05:00
|
|
|
sawspace = false;
|
1999-09-08 08:06:28 +00:00
|
|
|
}
|
|
|
|
|
2019-03-03 14:41:59 -07:00
|
|
|
[#:\,=\r\n] {
|
1996-04-28 19:01:02 +00:00
|
|
|
BEGIN INITIAL;
|
2020-08-07 14:13:25 -06:00
|
|
|
sudoersless(0);
|
2020-08-05 09:13:09 -06:00
|
|
|
yy_set_bol(0);
|
2020-09-26 06:39:57 -06:00
|
|
|
return COMMAND;
|
1995-08-19 21:53:38 +00:00
|
|
|
} /* end of command line args */
|
|
|
|
|
2019-03-03 14:41:59 -07:00
|
|
|
[^#\\:, \t\r\n]+ {
|
1995-08-19 21:53:38 +00:00
|
|
|
LEXTRACE("ARG ");
|
2012-09-14 16:19:25 -04:00
|
|
|
if (!fill_args(sudoerstext, sudoersleng, sawspace))
|
2004-09-28 00:47:30 +00:00
|
|
|
yyterminate();
|
2011-12-02 11:27:33 -05:00
|
|
|
sawspace = false;
|
2001-12-11 23:05:44 +00:00
|
|
|
} /* a command line arg */
|
|
|
|
}
|
1995-08-14 04:07:15 +00:00
|
|
|
|
2013-04-15 15:12:00 -04:00
|
|
|
<WANTDIGEST>[[:xdigit:]]+ {
|
|
|
|
/* Only return DIGEST if the length is correct. */
|
2018-05-24 21:04:07 -06:00
|
|
|
yy_size_t digest_len =
|
|
|
|
sudo_digest_getlen(digest_type);
|
2015-11-22 09:19:12 -07:00
|
|
|
if ((yy_size_t)sudoersleng == digest_len * 2) {
|
2013-04-15 15:12:00 -04:00
|
|
|
if (!fill(sudoerstext, sudoersleng))
|
|
|
|
yyterminate();
|
|
|
|
BEGIN INITIAL;
|
|
|
|
LEXTRACE("DIGEST ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return DIGEST;
|
2013-04-15 15:12:00 -04:00
|
|
|
}
|
|
|
|
BEGIN INITIAL;
|
2020-08-07 14:13:25 -06:00
|
|
|
sudoersless(sudoersleng);
|
2013-04-15 15:12:00 -04:00
|
|
|
} /* hex digest */
|
|
|
|
|
|
|
|
<WANTDIGEST>[A-Za-z0-9\+/=]+ {
|
|
|
|
/* Only return DIGEST if the length is correct. */
|
2018-05-24 21:04:07 -06:00
|
|
|
yy_size_t len, digest_len =
|
|
|
|
sudo_digest_getlen(digest_type);
|
2013-04-15 15:12:00 -04:00
|
|
|
if (sudoerstext[sudoersleng - 1] == '=') {
|
|
|
|
/* use padding */
|
|
|
|
len = 4 * ((digest_len + 2) / 3);
|
|
|
|
} else {
|
|
|
|
/* no padding */
|
|
|
|
len = (4 * digest_len + 2) / 3;
|
|
|
|
}
|
2015-11-22 09:19:12 -07:00
|
|
|
if ((yy_size_t)sudoersleng == len) {
|
2013-04-15 15:12:00 -04:00
|
|
|
if (!fill(sudoerstext, sudoersleng))
|
|
|
|
yyterminate();
|
|
|
|
BEGIN INITIAL;
|
|
|
|
LEXTRACE("DIGEST ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return DIGEST;
|
2013-04-15 15:12:00 -04:00
|
|
|
}
|
|
|
|
BEGIN INITIAL;
|
2020-08-07 14:13:25 -06:00
|
|
|
sudoersless(sudoersleng);
|
2013-04-15 15:12:00 -04:00
|
|
|
} /* base64 digest */
|
|
|
|
|
2020-05-20 13:10:53 -06:00
|
|
|
<INITIAL>@include {
|
|
|
|
if (continued) {
|
2020-09-27 06:51:16 -06:00
|
|
|
sudoerserror(N_("invalid line continuation"));
|
2020-05-20 13:10:53 -06:00
|
|
|
LEXTRACE("ERROR ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return ERROR;
|
2020-05-20 13:10:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
BEGIN GOTINC;
|
|
|
|
LEXTRACE("INCLUDE ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return INCLUDE;
|
2020-05-20 13:10:53 -06:00
|
|
|
}
|
2007-08-23 11:47:08 +00:00
|
|
|
|
2020-05-20 13:10:53 -06:00
|
|
|
<INITIAL>@includedir {
|
2011-03-21 12:48:33 -04:00
|
|
|
if (continued) {
|
2020-09-27 06:51:16 -06:00
|
|
|
sudoerserror(N_("invalid line continuation"));
|
2011-03-21 12:48:33 -04:00
|
|
|
LEXTRACE("ERROR ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return ERROR;
|
2011-03-21 12:48:33 -04:00
|
|
|
}
|
|
|
|
|
2020-05-20 13:10:53 -06:00
|
|
|
BEGIN GOTINC;
|
|
|
|
LEXTRACE("INCLUDEDIR ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return INCLUDEDIR;
|
2020-05-20 13:10:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
<INITIAL>^#include[[:blank:]]+.*(\r\n|\n)? {
|
|
|
|
if (continued) {
|
2020-09-27 06:51:16 -06:00
|
|
|
sudoerserror(N_("invalid line continuation"));
|
2020-05-20 13:10:53 -06:00
|
|
|
LEXTRACE("ERROR ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return ERROR;
|
2020-05-20 13:10:53 -06:00
|
|
|
}
|
2007-08-23 11:47:08 +00:00
|
|
|
|
2020-05-20 13:10:53 -06:00
|
|
|
/* only consume #include */
|
2020-08-07 14:13:25 -06:00
|
|
|
sudoersless(sizeof("#include") - 1);
|
2020-08-05 09:13:09 -06:00
|
|
|
yy_set_bol(0);
|
2007-08-23 11:47:08 +00:00
|
|
|
|
2020-05-20 13:10:53 -06:00
|
|
|
BEGIN GOTINC;
|
|
|
|
LEXTRACE("INCLUDE ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return INCLUDE;
|
2004-09-27 16:03:15 +00:00
|
|
|
}
|
|
|
|
|
2020-02-14 14:06:45 -07:00
|
|
|
<INITIAL>^#includedir[[:blank:]]+.*(\r\n|\n)? {
|
2011-03-21 12:48:33 -04:00
|
|
|
if (continued) {
|
2020-09-27 06:51:16 -06:00
|
|
|
sudoerserror(N_("invalid line continuation"));
|
2011-03-21 12:48:33 -04:00
|
|
|
LEXTRACE("ERROR ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return ERROR;
|
2011-03-21 12:48:33 -04:00
|
|
|
}
|
|
|
|
|
2020-05-20 13:10:53 -06:00
|
|
|
/* only consume #includedir */
|
2020-08-07 14:13:25 -06:00
|
|
|
sudoersless(sizeof("#includedir") - 1);
|
2020-08-05 09:13:09 -06:00
|
|
|
yy_set_bol(0);
|
2009-04-18 23:25:08 +00:00
|
|
|
|
2020-05-20 13:10:53 -06:00
|
|
|
BEGIN GOTINC;
|
|
|
|
LEXTRACE("INCLUDEDIR ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return INCLUDEDIR;
|
2009-04-18 23:25:08 +00:00
|
|
|
}
|
|
|
|
|
2011-03-23 18:51:57 -04:00
|
|
|
<INITIAL>^[[:blank:]]*Defaults([:@>\!][[:blank:]]*\!*\"?({ID}|{WORD}))? {
|
2011-03-20 12:24:36 -04:00
|
|
|
char deftype;
|
2005-02-23 03:16:06 +00:00
|
|
|
int n;
|
2011-03-21 12:48:33 -04:00
|
|
|
|
|
|
|
if (continued) {
|
2020-09-27 06:51:16 -06:00
|
|
|
sudoerserror(N_("invalid line continuation"));
|
2011-03-21 12:48:33 -04:00
|
|
|
LEXTRACE("ERROR ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return ERROR;
|
2011-03-21 12:48:33 -04:00
|
|
|
}
|
|
|
|
|
2012-09-14 16:19:25 -04:00
|
|
|
for (n = 0; isblank((unsigned char)sudoerstext[n]); n++)
|
2005-02-23 03:16:06 +00:00
|
|
|
continue;
|
2011-03-20 12:24:36 -04:00
|
|
|
n += sizeof("Defaults") - 1;
|
2012-09-14 16:19:25 -04:00
|
|
|
if ((deftype = sudoerstext[n++]) != '\0') {
|
|
|
|
while (isblank((unsigned char)sudoerstext[n]))
|
2011-03-31 12:48:01 -04:00
|
|
|
n++;
|
2011-03-20 12:24:36 -04:00
|
|
|
}
|
2001-12-11 23:05:44 +00:00
|
|
|
BEGIN GOTDEFS;
|
2011-03-20 12:24:36 -04:00
|
|
|
switch (deftype) {
|
2001-12-11 23:05:44 +00:00
|
|
|
case ':':
|
2020-08-07 14:13:25 -06:00
|
|
|
sudoersless(n);
|
2001-12-11 23:05:44 +00:00
|
|
|
LEXTRACE("DEFAULTS_USER ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return DEFAULTS_USER;
|
2003-01-17 23:09:45 +00:00
|
|
|
case '>':
|
2020-08-07 14:13:25 -06:00
|
|
|
sudoersless(n);
|
2003-01-17 23:09:45 +00:00
|
|
|
LEXTRACE("DEFAULTS_RUNAS ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return DEFAULTS_RUNAS;
|
2001-12-11 23:05:44 +00:00
|
|
|
case '@':
|
2020-08-07 14:13:25 -06:00
|
|
|
sudoersless(n);
|
2001-12-11 23:05:44 +00:00
|
|
|
LEXTRACE("DEFAULTS_HOST ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return DEFAULTS_HOST;
|
2004-11-19 21:35:12 +00:00
|
|
|
case '!':
|
2020-08-07 14:13:25 -06:00
|
|
|
sudoersless(n);
|
2004-11-19 21:35:12 +00:00
|
|
|
LEXTRACE("DEFAULTS_CMND ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return DEFAULTS_CMND;
|
2001-12-11 23:05:44 +00:00
|
|
|
default:
|
|
|
|
LEXTRACE("DEFAULTS ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return DEFAULTS;
|
2001-12-11 23:05:44 +00:00
|
|
|
}
|
1995-09-09 22:34:40 +00:00
|
|
|
}
|
1995-08-14 04:07:15 +00:00
|
|
|
|
2020-03-11 11:17:38 -06:00
|
|
|
<INITIAL>^[[:blank:]]*(Host|Cmnd|Cmd|User|Runas)_Alias {
|
2005-02-23 03:16:06 +00:00
|
|
|
int n;
|
2011-03-21 12:48:33 -04:00
|
|
|
|
|
|
|
if (continued) {
|
2020-09-27 06:51:16 -06:00
|
|
|
sudoerserror(N_("invalid line continuation"));
|
2011-03-21 12:48:33 -04:00
|
|
|
LEXTRACE("ERROR ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return ERROR;
|
2011-03-21 12:48:33 -04:00
|
|
|
}
|
|
|
|
|
2012-09-14 16:19:25 -04:00
|
|
|
for (n = 0; isblank((unsigned char)sudoerstext[n]); n++)
|
2005-02-23 03:16:06 +00:00
|
|
|
continue;
|
2012-09-14 16:19:25 -04:00
|
|
|
switch (sudoerstext[n]) {
|
2001-12-11 23:05:44 +00:00
|
|
|
case 'H':
|
|
|
|
LEXTRACE("HOSTALIAS ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return HOSTALIAS;
|
2001-12-11 23:05:44 +00:00
|
|
|
case 'C':
|
|
|
|
LEXTRACE("CMNDALIAS ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return CMNDALIAS;
|
2001-12-11 23:05:44 +00:00
|
|
|
case 'U':
|
|
|
|
LEXTRACE("USERALIAS ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return USERALIAS;
|
2001-12-11 23:05:44 +00:00
|
|
|
case 'R':
|
|
|
|
LEXTRACE("RUNASALIAS ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return RUNASALIAS;
|
2001-12-11 23:05:44 +00:00
|
|
|
}
|
|
|
|
}
|
1995-08-14 04:07:15 +00:00
|
|
|
|
1999-09-08 08:06:28 +00:00
|
|
|
NOPASSWD[[:blank:]]*: {
|
1996-04-28 00:59:21 +00:00
|
|
|
/* cmnd does not require passwd for this user */
|
|
|
|
LEXTRACE("NOPASSWD ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return NOPASSWD;
|
1996-04-28 00:59:21 +00:00
|
|
|
}
|
|
|
|
|
1999-09-08 08:06:28 +00:00
|
|
|
PASSWD[[:blank:]]*: {
|
1999-04-05 20:28:16 +00:00
|
|
|
/* cmnd requires passwd for this user */
|
|
|
|
LEXTRACE("PASSWD ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return PASSWD;
|
1999-04-05 20:28:16 +00:00
|
|
|
}
|
|
|
|
|
2004-01-05 02:48:09 +00:00
|
|
|
NOEXEC[[:blank:]]*: {
|
|
|
|
LEXTRACE("NOEXEC ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return NOEXEC;
|
2004-01-05 02:48:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EXEC[[:blank:]]*: {
|
|
|
|
LEXTRACE("EXEC ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return EXEC;
|
2004-01-05 02:48:09 +00:00
|
|
|
}
|
|
|
|
|
2007-06-23 23:58:54 +00:00
|
|
|
SETENV[[:blank:]]*: {
|
|
|
|
LEXTRACE("SETENV ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return SETENV;
|
2007-06-23 23:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NOSETENV[[:blank:]]*: {
|
|
|
|
LEXTRACE("NOSETENV ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return NOSETENV;
|
2007-06-23 23:58:54 +00:00
|
|
|
}
|
|
|
|
|
2010-09-07 17:16:05 -04:00
|
|
|
LOG_OUTPUT[[:blank:]]*: {
|
|
|
|
LEXTRACE("LOG_OUTPUT ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return LOG_OUTPUT;
|
2010-09-07 17:16:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
NOLOG_OUTPUT[[:blank:]]*: {
|
|
|
|
LEXTRACE("NOLOG_OUTPUT ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return NOLOG_OUTPUT;
|
2010-09-07 17:16:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
LOG_INPUT[[:blank:]]*: {
|
|
|
|
LEXTRACE("LOG_INPUT ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return LOG_INPUT;
|
2010-09-07 17:16:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
NOLOG_INPUT[[:blank:]]*: {
|
|
|
|
LEXTRACE("NOLOG_INPUT ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return NOLOG_INPUT;
|
2010-09-07 17:16:05 -04:00
|
|
|
}
|
|
|
|
|
2015-02-19 10:02:20 -07:00
|
|
|
MAIL[[:blank:]]*: {
|
|
|
|
LEXTRACE("MAIL ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return MAIL;
|
2015-02-19 10:02:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NOMAIL[[:blank:]]*: {
|
|
|
|
LEXTRACE("NOMAIL ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return NOMAIL;
|
2015-02-19 10:02:20 -07:00
|
|
|
}
|
|
|
|
|
2015-08-06 13:20:01 -06:00
|
|
|
FOLLOW[[:blank:]]*: {
|
|
|
|
LEXTRACE("FOLLOW ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return FOLLOWLNK;
|
2015-08-06 13:20:01 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
NOFOLLOW[[:blank:]]*: {
|
|
|
|
LEXTRACE("NOFOLLOW ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return NOFOLLOWLNK;
|
2015-08-06 13:20:01 -06:00
|
|
|
}
|
|
|
|
|
2011-03-24 11:00:30 -04:00
|
|
|
<INITIAL,GOTDEFS>(\+|\%|\%:) {
|
2020-08-07 14:20:45 -06:00
|
|
|
if (sudoerstext[0] == '+')
|
2020-09-27 06:51:16 -06:00
|
|
|
sudoerserror(N_("empty netgroup"));
|
2020-08-07 14:20:45 -06:00
|
|
|
else
|
2020-09-27 06:51:16 -06:00
|
|
|
sudoerserror(N_("empty group"));
|
2011-03-24 11:00:30 -04:00
|
|
|
LEXTRACE("ERROR ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return ERROR;
|
2011-03-24 11:00:30 -04:00
|
|
|
}
|
|
|
|
|
1999-09-08 08:06:28 +00:00
|
|
|
\+{WORD} {
|
1996-04-28 19:01:02 +00:00
|
|
|
/* netgroup */
|
2012-09-14 16:19:25 -04:00
|
|
|
if (!fill(sudoerstext, sudoersleng))
|
2004-09-28 00:47:30 +00:00
|
|
|
yyterminate();
|
1999-09-08 08:06:28 +00:00
|
|
|
LEXTRACE("NETGROUP ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return NETGROUP;
|
1996-04-28 19:01:02 +00:00
|
|
|
}
|
1995-07-25 00:01:34 +00:00
|
|
|
|
2011-03-24 10:37:34 -04:00
|
|
|
\%:?({WORD}|{ID}) {
|
2011-03-23 18:51:57 -04:00
|
|
|
/* group */
|
2012-09-14 16:19:25 -04:00
|
|
|
if (!fill(sudoerstext, sudoersleng))
|
2004-09-28 00:47:30 +00:00
|
|
|
yyterminate();
|
2004-10-26 22:12:47 +00:00
|
|
|
LEXTRACE("USERGROUP ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return USERGROUP;
|
1996-04-28 19:01:02 +00:00
|
|
|
}
|
1995-12-18 02:51:30 +00:00
|
|
|
|
2007-08-25 02:47:54 +00:00
|
|
|
{IPV4ADDR}(\/{IPV4ADDR})? {
|
2012-09-14 16:19:25 -04:00
|
|
|
if (!fill(sudoerstext, sudoersleng))
|
2004-09-28 00:47:30 +00:00
|
|
|
yyterminate();
|
1996-03-19 22:00:22 +00:00
|
|
|
LEXTRACE("NTWKADDR ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return NTWKADDR;
|
1995-03-29 22:18:50 +00:00
|
|
|
}
|
1995-03-24 03:32:53 +00:00
|
|
|
|
2011-04-29 11:22:49 -04:00
|
|
|
{IPV4ADDR}\/([12]?[0-9]|3[0-2]) {
|
2012-09-14 16:19:25 -04:00
|
|
|
if (!fill(sudoerstext, sudoersleng))
|
2004-09-28 00:47:30 +00:00
|
|
|
yyterminate();
|
1999-08-24 16:42:28 +00:00
|
|
|
LEXTRACE("NTWKADDR ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return NTWKADDR;
|
1999-08-24 16:42:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-13 16:29:25 +00:00
|
|
|
{IPV6ADDR}(\/{IPV6ADDR})? {
|
2012-09-14 16:19:25 -04:00
|
|
|
if (!ipv6_valid(sudoerstext)) {
|
2020-09-27 06:51:16 -06:00
|
|
|
sudoerserror(N_("invalid IPv6 address"));
|
2007-08-25 02:47:54 +00:00
|
|
|
LEXTRACE("ERROR ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return ERROR;
|
2007-08-25 02:47:54 +00:00
|
|
|
}
|
2012-09-14 16:19:25 -04:00
|
|
|
if (!fill(sudoerstext, sudoersleng))
|
2007-08-13 16:29:25 +00:00
|
|
|
yyterminate();
|
|
|
|
LEXTRACE("NTWKADDR ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return NTWKADDR;
|
2007-08-13 16:29:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{IPV6ADDR}\/([0-9]|[1-9][0-9]|1[01][0-9]|12[0-8]) {
|
2012-09-14 16:19:25 -04:00
|
|
|
if (!ipv6_valid(sudoerstext)) {
|
2020-09-27 06:51:16 -06:00
|
|
|
sudoerserror(N_("invalid IPv6 address"));
|
2007-08-25 02:47:54 +00:00
|
|
|
LEXTRACE("ERROR ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return ERROR;
|
2007-08-25 02:47:54 +00:00
|
|
|
}
|
2012-09-14 16:19:25 -04:00
|
|
|
if (!fill(sudoerstext, sudoersleng))
|
2007-08-13 16:29:25 +00:00
|
|
|
yyterminate();
|
|
|
|
LEXTRACE("NTWKADDR ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return NTWKADDR;
|
2007-08-13 16:29:25 +00:00
|
|
|
}
|
|
|
|
|
2011-04-29 16:05:50 -04:00
|
|
|
ALL {
|
|
|
|
LEXTRACE("ALL ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return ALL;
|
2011-04-29 16:05:50 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-02-14 15:56:34 -07:00
|
|
|
<INITIAL>TIMEOUT {
|
|
|
|
LEXTRACE("CMND_TIMEOUT ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return CMND_TIMEOUT;
|
2017-02-14 15:56:34 -07:00
|
|
|
}
|
|
|
|
|
2017-02-18 15:35:48 -07:00
|
|
|
<INITIAL>NOTBEFORE {
|
|
|
|
LEXTRACE("NOTBEFORE ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return NOTBEFORE;
|
2017-02-18 15:35:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
<INITIAL>NOTAFTER {
|
|
|
|
LEXTRACE("NOTAFTER ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return NOTAFTER;
|
2017-02-18 15:35:48 -07:00
|
|
|
}
|
|
|
|
|
2020-09-01 06:26:00 -06:00
|
|
|
<INITIAL>CWD {
|
|
|
|
LEXTRACE("CWD ");
|
|
|
|
prev_state = YY_START;
|
|
|
|
BEGIN EXPECTPATH;
|
2020-09-26 06:39:57 -06:00
|
|
|
return CWD;
|
2020-09-01 06:26:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
<INITIAL>CHROOT {
|
|
|
|
LEXTRACE("CHROOT ");
|
|
|
|
prev_state = YY_START;
|
|
|
|
BEGIN EXPECTPATH;
|
2020-09-26 06:39:57 -06:00
|
|
|
return CHROOT;
|
2020-09-01 06:26:00 -06:00
|
|
|
}
|
|
|
|
|
2011-04-29 16:05:50 -04:00
|
|
|
<INITIAL>ROLE {
|
2008-02-09 14:30:07 +00:00
|
|
|
#ifdef HAVE_SELINUX
|
2011-04-29 16:05:50 -04:00
|
|
|
LEXTRACE("ROLE ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return ROLE;
|
2011-04-29 16:05:50 -04:00
|
|
|
#else
|
|
|
|
goto got_alias;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
<INITIAL>TYPE {
|
|
|
|
#ifdef HAVE_SELINUX
|
|
|
|
LEXTRACE("TYPE ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return TYPE;
|
2011-04-29 16:05:50 -04:00
|
|
|
#else
|
|
|
|
goto got_alias;
|
|
|
|
#endif
|
|
|
|
}
|
2012-07-26 13:49:21 -04:00
|
|
|
<INITIAL>PRIVS {
|
|
|
|
#ifdef HAVE_PRIV_SET
|
|
|
|
LEXTRACE("PRIVS ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return PRIVS;
|
2012-07-26 13:49:21 -04:00
|
|
|
#else
|
|
|
|
goto got_alias;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
<INITIAL>LIMITPRIVS {
|
|
|
|
#ifdef HAVE_PRIV_SET
|
|
|
|
LEXTRACE("LIMITPRIVS ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return LIMITPRIVS;
|
2012-07-26 13:49:21 -04:00
|
|
|
#else
|
|
|
|
goto got_alias;
|
|
|
|
#endif
|
|
|
|
}
|
2011-04-29 16:05:50 -04:00
|
|
|
|
|
|
|
[[:upper:]][[:upper:][:digit:]_]* {
|
|
|
|
got_alias:
|
2012-09-14 16:19:25 -04:00
|
|
|
if (!fill(sudoerstext, sudoersleng))
|
2008-02-09 14:30:07 +00:00
|
|
|
yyterminate();
|
|
|
|
LEXTRACE("ALIAS ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return ALIAS;
|
1996-04-28 00:59:21 +00:00
|
|
|
}
|
|
|
|
|
2004-11-19 23:04:14 +00:00
|
|
|
<GOTDEFS>({PATH}|sudoedit) {
|
2013-04-14 07:00:21 -04:00
|
|
|
/* XXX - no way to specify digest for command */
|
2004-11-19 21:35:12 +00:00
|
|
|
/* no command args allowed for Defaults!/path */
|
2012-09-14 16:19:25 -04:00
|
|
|
if (!fill_cmnd(sudoerstext, sudoersleng))
|
2004-11-19 21:35:12 +00:00
|
|
|
yyterminate();
|
|
|
|
LEXTRACE("COMMAND ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return COMMAND;
|
2004-11-19 21:35:12 +00:00
|
|
|
}
|
|
|
|
|
2013-04-14 07:00:21 -04:00
|
|
|
sha224 {
|
2018-05-24 21:04:07 -06:00
|
|
|
digest_type = SUDO_DIGEST_SHA224;
|
2013-04-15 15:12:00 -04:00
|
|
|
BEGIN WANTDIGEST;
|
2014-04-09 16:31:13 -06:00
|
|
|
LEXTRACE("SHA224_TOK ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return SHA224_TOK;
|
2013-04-14 07:00:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
sha256 {
|
2018-05-24 21:04:07 -06:00
|
|
|
digest_type = SUDO_DIGEST_SHA256;
|
2013-04-15 15:12:00 -04:00
|
|
|
BEGIN WANTDIGEST;
|
2014-04-09 16:31:13 -06:00
|
|
|
LEXTRACE("SHA256_TOK ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return SHA256_TOK;
|
2013-04-14 07:00:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
sha384 {
|
2018-05-24 21:04:07 -06:00
|
|
|
digest_type = SUDO_DIGEST_SHA384;
|
2013-04-15 15:12:00 -04:00
|
|
|
BEGIN WANTDIGEST;
|
2014-04-09 16:31:13 -06:00
|
|
|
LEXTRACE("SHA384_TOK ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return SHA384_TOK;
|
2013-04-14 07:00:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
sha512 {
|
2018-05-24 21:04:07 -06:00
|
|
|
digest_type = SUDO_DIGEST_SHA512;
|
2013-04-15 15:12:00 -04:00
|
|
|
BEGIN WANTDIGEST;
|
2014-04-09 16:31:13 -06:00
|
|
|
LEXTRACE("SHA512_TOK ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return SHA512_TOK;
|
2013-04-14 07:00:21 -04:00
|
|
|
}
|
|
|
|
|
2004-11-19 23:04:14 +00:00
|
|
|
sudoedit {
|
|
|
|
BEGIN GOTCMND;
|
|
|
|
LEXTRACE("COMMAND ");
|
2012-09-14 16:19:25 -04:00
|
|
|
if (!fill_cmnd(sudoerstext, sudoersleng))
|
2004-11-19 23:04:14 +00:00
|
|
|
yyterminate();
|
|
|
|
} /* sudo -e */
|
|
|
|
|
2020-09-01 06:26:00 -06:00
|
|
|
<EXPECTPATH>({PATH}|{WORD}) {
|
|
|
|
BEGIN prev_state;
|
|
|
|
if (!fill(sudoerstext, sudoersleng))
|
|
|
|
yyterminate();
|
|
|
|
LEXTRACE("WORD(5) ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return WORD;
|
2020-09-01 06:26:00 -06:00
|
|
|
}
|
|
|
|
|
2004-11-19 21:35:12 +00:00
|
|
|
{PATH} {
|
1999-09-08 08:06:28 +00:00
|
|
|
/* directories can't have args... */
|
2012-09-14 16:19:25 -04:00
|
|
|
if (sudoerstext[sudoersleng - 1] == '/') {
|
1999-09-08 08:06:28 +00:00
|
|
|
LEXTRACE("COMMAND ");
|
2012-09-14 16:19:25 -04:00
|
|
|
if (!fill_cmnd(sudoerstext, sudoersleng))
|
2004-09-28 00:47:30 +00:00
|
|
|
yyterminate();
|
2020-09-26 06:39:57 -06:00
|
|
|
return COMMAND;
|
1999-09-08 08:06:28 +00:00
|
|
|
}
|
2020-09-01 06:26:00 -06:00
|
|
|
BEGIN GOTCMND;
|
|
|
|
LEXTRACE("COMMAND ");
|
|
|
|
if (!fill_cmnd(sudoerstext, sudoersleng))
|
|
|
|
yyterminate();
|
1999-09-08 08:06:28 +00:00
|
|
|
} /* a pathname */
|
|
|
|
|
2020-05-20 13:10:53 -06:00
|
|
|
<INITIAL,GOTDEFS>\" {
|
2011-01-31 15:13:51 -05:00
|
|
|
LEXTRACE("BEGINSTR ");
|
2012-09-14 16:19:25 -04:00
|
|
|
sudoerslval.string = NULL;
|
2011-01-31 15:13:51 -05:00
|
|
|
prev_state = YY_START;
|
|
|
|
BEGIN INSTR;
|
2009-05-17 20:22:24 +00:00
|
|
|
}
|
|
|
|
|
2007-08-22 22:28:20 +00:00
|
|
|
<INITIAL,GOTDEFS>({ID}|{WORD}) {
|
1999-09-08 08:06:28 +00:00
|
|
|
/* a word */
|
2012-09-14 16:19:25 -04:00
|
|
|
if (!fill(sudoerstext, sudoersleng))
|
2004-09-28 00:47:30 +00:00
|
|
|
yyterminate();
|
2020-09-01 06:26:00 -06:00
|
|
|
LEXTRACE("WORD(6) ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return WORD;
|
1995-03-24 03:32:53 +00:00
|
|
|
}
|
|
|
|
|
2020-05-20 13:10:53 -06:00
|
|
|
<GOTINC>{
|
|
|
|
[^\"[:space:]]([^[:space:]]|\\[[:blank:]])* {
|
|
|
|
/* include file/directory */
|
|
|
|
if (!fill(sudoerstext, sudoersleng))
|
|
|
|
yyterminate();
|
|
|
|
BEGIN INITIAL;
|
2020-09-01 06:26:00 -06:00
|
|
|
LEXTRACE("WORD(7) ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return WORD;
|
2020-05-20 13:10:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
\" {
|
|
|
|
LEXTRACE("BEGINSTR ");
|
|
|
|
sudoerslval.string = NULL;
|
|
|
|
prev_state = INITIAL;
|
|
|
|
BEGIN INSTR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-22 22:28:20 +00:00
|
|
|
\( {
|
|
|
|
LEXTRACE("( ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return '(';
|
2007-08-22 22:28:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
\) {
|
|
|
|
LEXTRACE(") ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return ')';
|
2007-08-22 22:28:20 +00:00
|
|
|
}
|
|
|
|
|
2001-12-11 23:05:44 +00:00
|
|
|
, {
|
|
|
|
LEXTRACE(", ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return ',';
|
2001-12-11 23:05:44 +00:00
|
|
|
} /* return ',' */
|
|
|
|
|
|
|
|
= {
|
|
|
|
LEXTRACE("= ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return '=';
|
2001-12-11 23:05:44 +00:00
|
|
|
} /* return '=' */
|
|
|
|
|
|
|
|
: {
|
|
|
|
LEXTRACE(": ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return ':';
|
2001-12-11 23:05:44 +00:00
|
|
|
} /* return ':' */
|
|
|
|
|
|
|
|
<*>!+ {
|
2012-09-14 16:19:25 -04:00
|
|
|
if (sudoersleng & 1) {
|
2011-03-31 13:42:05 -04:00
|
|
|
LEXTRACE("!");
|
2020-09-26 06:39:57 -06:00
|
|
|
return '!'; /* return '!' */
|
2011-03-31 13:42:05 -04:00
|
|
|
}
|
2001-12-11 23:05:44 +00:00
|
|
|
}
|
|
|
|
|
2019-03-03 14:41:59 -07:00
|
|
|
<*>\r?\n {
|
2011-03-27 17:12:45 -04:00
|
|
|
if (YY_START == INSTR) {
|
2020-09-27 06:47:19 -06:00
|
|
|
/* re-scan after changing state */
|
|
|
|
BEGIN INITIAL;
|
|
|
|
sudoersless(0);
|
2020-09-27 06:51:16 -06:00
|
|
|
sudoerserror(N_("unexpected line break in string"));
|
2011-03-27 17:12:45 -04:00
|
|
|
LEXTRACE("ERROR ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return ERROR;
|
2011-03-27 17:12:45 -04:00
|
|
|
}
|
2001-12-11 23:05:44 +00:00
|
|
|
BEGIN INITIAL;
|
2011-11-05 07:37:14 -04:00
|
|
|
sudolineno++;
|
2011-12-02 11:27:33 -05:00
|
|
|
continued = false;
|
2001-12-11 23:05:44 +00:00
|
|
|
LEXTRACE("\n");
|
2020-09-26 06:39:57 -06:00
|
|
|
return '\n';
|
2001-12-11 23:05:44 +00:00
|
|
|
} /* return newline */
|
|
|
|
|
|
|
|
<*>[[:blank:]]+ { /* throw away space/tabs */
|
2011-12-02 11:27:33 -05:00
|
|
|
sawspace = true; /* but remember for fill_args */
|
2001-12-11 23:05:44 +00:00
|
|
|
}
|
|
|
|
|
2019-03-03 14:41:59 -07:00
|
|
|
<*>\\[[:blank:]]*\r?\n {
|
2011-12-02 11:27:33 -05:00
|
|
|
sawspace = true; /* remember for fill_args */
|
2011-11-05 07:37:14 -04:00
|
|
|
sudolineno++;
|
2011-12-02 11:27:33 -05:00
|
|
|
continued = true;
|
2001-12-11 23:05:44 +00:00
|
|
|
} /* throw away EOL after \ */
|
|
|
|
|
2019-03-03 14:41:59 -07:00
|
|
|
<INITIAL,STARTDEFS,INDEFS>#(-[^\r\n0-9].*|[^\r\n0-9-].*)?(\r\n|\n)? {
|
2013-11-12 09:36:39 -07:00
|
|
|
if (sudoerstext[sudoersleng - 1] == '\n') {
|
|
|
|
/* comment ending in a newline */
|
|
|
|
BEGIN INITIAL;
|
|
|
|
sudolineno++;
|
|
|
|
continued = false;
|
2020-08-06 21:16:35 -06:00
|
|
|
} else if (!feof(sudoersin)) {
|
2020-08-07 14:20:45 -06:00
|
|
|
sudoerserror(strerror(errno));
|
2013-11-12 09:36:39 -07:00
|
|
|
LEXTRACE("ERROR ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return ERROR;
|
2013-11-12 09:36:39 -07:00
|
|
|
}
|
2011-03-20 21:25:57 -04:00
|
|
|
LEXTRACE("#\n");
|
2020-09-26 06:39:57 -06:00
|
|
|
return '\n';
|
2009-01-17 22:36:09 +00:00
|
|
|
} /* comment, not uid/gid */
|
2001-12-11 23:05:44 +00:00
|
|
|
|
|
|
|
<*>. {
|
2020-08-16 06:42:15 -06:00
|
|
|
LEXTRACE("NOMATCH ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return NOMATCH;
|
2020-08-16 06:42:15 -06:00
|
|
|
} /* parse error, no matching token */
|
1995-03-29 22:18:50 +00:00
|
|
|
|
2003-01-07 00:02:33 +00:00
|
|
|
<*><<EOF>> {
|
2020-09-27 10:05:35 -06:00
|
|
|
int state = YY_START;
|
|
|
|
|
|
|
|
BEGIN INITIAL;
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case GOTCMND:
|
|
|
|
/* missing newline after command/args */
|
|
|
|
return COMMAND;
|
|
|
|
case INSTR:
|
|
|
|
sudoerserror(N_("unterminated string"));
|
2003-01-07 00:02:33 +00:00
|
|
|
LEXTRACE("ERROR ");
|
2020-09-26 06:39:57 -06:00
|
|
|
return ERROR;
|
2020-09-27 10:05:35 -06:00
|
|
|
default:
|
|
|
|
if (!pop_include())
|
|
|
|
yyterminate();
|
|
|
|
|
|
|
|
/* force a newline at EOF */
|
|
|
|
if (sudoerschar != '\n') {
|
|
|
|
LEXTRACE("\n");
|
|
|
|
return '\n';
|
|
|
|
}
|
|
|
|
break;
|
2003-01-07 00:02:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1993-03-02 16:33:11 +00:00
|
|
|
%%
|
2009-04-18 23:25:08 +00:00
|
|
|
struct path_list {
|
2013-10-22 09:08:09 -06:00
|
|
|
SLIST_ENTRY(path_list) entries;
|
2009-04-18 23:25:08 +00:00
|
|
|
char *path;
|
|
|
|
};
|
|
|
|
|
2013-10-22 09:08:09 -06:00
|
|
|
SLIST_HEAD(path_list_head, path_list);
|
|
|
|
|
2009-04-18 23:25:08 +00:00
|
|
|
struct include_stack {
|
2020-08-06 21:16:35 -06:00
|
|
|
struct sudolinebuf line;
|
2004-09-28 18:31:24 +00:00
|
|
|
YY_BUFFER_STATE bs;
|
|
|
|
char *path;
|
2013-10-22 09:08:09 -06:00
|
|
|
struct path_list_head more; /* more files in case of includedir */
|
2004-09-28 18:31:24 +00:00
|
|
|
int lineno;
|
2011-12-02 11:27:33 -05:00
|
|
|
bool keepopen;
|
2004-09-28 18:31:24 +00:00
|
|
|
};
|
|
|
|
|
2013-10-22 09:08:09 -06:00
|
|
|
/*
|
|
|
|
* Compare two struct path_list structs in reverse order.
|
|
|
|
*/
|
2009-04-18 23:25:08 +00:00
|
|
|
static int
|
2011-01-08 15:15:30 -05:00
|
|
|
pl_compare(const void *v1, const void *v2)
|
2009-04-18 23:25:08 +00:00
|
|
|
{
|
|
|
|
const struct path_list * const *p1 = v1;
|
|
|
|
const struct path_list * const *p2 = v2;
|
|
|
|
|
2013-10-22 09:08:09 -06:00
|
|
|
return strcmp((*p2)->path, (*p1)->path);
|
2009-04-18 23:25:08 +00:00
|
|
|
}
|
|
|
|
|
2014-05-02 07:14:06 -06:00
|
|
|
/*
|
|
|
|
* Open dirpath and fill in pathsp with an array of regular files
|
|
|
|
* that do not end in '~' or contain a '.'.
|
|
|
|
* Returns the number of files or -1 on error.
|
|
|
|
* If zero files are found, NULL is stored in pathsp.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
read_dir_files(const char *dirpath, struct path_list ***pathsp)
|
2009-04-18 23:25:08 +00:00
|
|
|
{
|
|
|
|
DIR *dir;
|
2014-05-02 07:14:06 -06:00
|
|
|
int i, count = 0;
|
|
|
|
int max_paths = 32;
|
2009-04-18 23:25:08 +00:00
|
|
|
struct dirent *dent;
|
2014-05-02 07:14:06 -06:00
|
|
|
struct path_list **paths = NULL;
|
2019-12-22 08:48:16 -07:00
|
|
|
debug_decl(read_dir_files, SUDOERS_DEBUG_PARSER);
|
2009-04-18 23:25:08 +00:00
|
|
|
|
2014-05-02 07:14:06 -06:00
|
|
|
dir = opendir(dirpath);
|
|
|
|
if (dir == NULL) {
|
2016-07-03 06:16:19 -06:00
|
|
|
if (errno == ENOENT)
|
|
|
|
goto done;
|
|
|
|
sudo_warn("%s", dirpath);
|
2014-05-02 07:14:06 -06:00
|
|
|
goto bad;
|
2009-04-18 23:25:08 +00:00
|
|
|
}
|
2015-07-14 14:50:36 -06:00
|
|
|
paths = reallocarray(NULL, max_paths, sizeof(*paths));
|
2016-07-03 06:16:19 -06:00
|
|
|
if (paths == NULL)
|
|
|
|
goto oom;
|
2014-05-02 07:14:06 -06:00
|
|
|
while ((dent = readdir(dir)) != NULL) {
|
|
|
|
struct path_list *pl;
|
|
|
|
struct stat sb;
|
2016-11-11 16:18:27 -07:00
|
|
|
size_t len;
|
2014-05-02 07:14:06 -06:00
|
|
|
char *path;
|
|
|
|
|
2009-04-19 12:56:42 +00:00
|
|
|
/* Ignore files that end in '~' or have a '.' in them. */
|
2009-04-22 20:32:08 +00:00
|
|
|
if (dent->d_name[0] == '\0' || dent->d_name[NAMLEN(dent) - 1] == '~'
|
2009-04-19 12:56:42 +00:00
|
|
|
|| strchr(dent->d_name, '.') != NULL) {
|
2009-04-18 23:25:08 +00:00
|
|
|
continue;
|
2009-04-19 12:56:42 +00:00
|
|
|
}
|
2016-11-11 16:18:27 -07:00
|
|
|
len = strlen(dirpath) + 1 + NAMLEN(dent);
|
|
|
|
if ((path = rcstr_alloc(len)) == NULL)
|
2016-07-03 06:16:19 -06:00
|
|
|
goto oom;
|
2016-11-11 16:18:27 -07:00
|
|
|
(void)snprintf(path, len + 1, "%s/%s", dirpath, dent->d_name);
|
2009-04-18 23:25:08 +00:00
|
|
|
if (stat(path, &sb) != 0 || !S_ISREG(sb.st_mode)) {
|
2016-11-11 16:18:27 -07:00
|
|
|
rcstr_delref(path);
|
2009-04-18 23:25:08 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
pl = malloc(sizeof(*pl));
|
2014-05-02 07:14:06 -06:00
|
|
|
if (pl == NULL) {
|
2016-11-11 16:18:27 -07:00
|
|
|
rcstr_delref(path);
|
2016-07-03 06:16:19 -06:00
|
|
|
goto oom;
|
2014-05-02 07:14:06 -06:00
|
|
|
}
|
2009-04-18 23:25:08 +00:00
|
|
|
pl->path = path;
|
2013-10-22 09:08:09 -06:00
|
|
|
if (count >= max_paths) {
|
|
|
|
struct path_list **tmp;
|
|
|
|
max_paths <<= 1;
|
2015-05-14 10:21:58 -06:00
|
|
|
tmp = reallocarray(paths, max_paths, sizeof(*paths));
|
2013-10-22 09:08:09 -06:00
|
|
|
if (tmp == NULL) {
|
2016-11-11 16:18:27 -07:00
|
|
|
rcstr_delref(path);
|
2015-05-27 10:36:03 -06:00
|
|
|
free(pl);
|
2016-07-03 06:16:19 -06:00
|
|
|
goto oom;
|
2013-10-22 09:08:09 -06:00
|
|
|
}
|
|
|
|
paths = tmp;
|
|
|
|
}
|
|
|
|
paths[count++] = pl;
|
2009-04-18 23:25:08 +00:00
|
|
|
}
|
|
|
|
closedir(dir);
|
2014-05-02 07:14:06 -06:00
|
|
|
if (count == 0) {
|
2015-05-27 10:36:03 -06:00
|
|
|
free(paths);
|
2014-05-02 07:14:06 -06:00
|
|
|
paths = NULL;
|
|
|
|
}
|
2016-07-03 06:16:19 -06:00
|
|
|
done:
|
2014-05-02 07:14:06 -06:00
|
|
|
*pathsp = paths;
|
|
|
|
debug_return_int(count);
|
2016-07-03 06:16:19 -06:00
|
|
|
oom:
|
|
|
|
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
|
2014-05-02 07:14:06 -06:00
|
|
|
bad:
|
2016-07-03 06:16:19 -06:00
|
|
|
sudoerserror(NULL);
|
2014-05-02 07:14:06 -06:00
|
|
|
if (dir != NULL)
|
|
|
|
closedir(dir);
|
|
|
|
for (i = 0; i < count; i++) {
|
2016-11-11 16:18:27 -07:00
|
|
|
rcstr_delref(paths[i]->path);
|
2015-05-27 10:36:03 -06:00
|
|
|
free(paths[i]);
|
2014-05-02 07:14:06 -06:00
|
|
|
}
|
2015-05-27 10:36:03 -06:00
|
|
|
free(paths);
|
2014-05-02 07:14:06 -06:00
|
|
|
debug_return_int(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-05-02 07:57:29 -06:00
|
|
|
* Push a list of all files in dirpath onto stack.
|
|
|
|
* Returns the number of files or -1 on error.
|
2014-05-02 07:14:06 -06:00
|
|
|
*/
|
2014-05-02 07:57:29 -06:00
|
|
|
static int
|
2014-05-02 07:14:06 -06:00
|
|
|
switch_dir(struct include_stack *stack, char *dirpath)
|
|
|
|
{
|
2014-05-02 07:57:29 -06:00
|
|
|
struct path_list **paths = NULL;
|
|
|
|
int count, i;
|
2019-12-22 08:48:16 -07:00
|
|
|
debug_decl(switch_dir, SUDOERS_DEBUG_PARSER);
|
2009-04-18 23:25:08 +00:00
|
|
|
|
2014-05-02 07:14:06 -06:00
|
|
|
count = read_dir_files(dirpath, &paths);
|
2014-05-02 07:57:29 -06:00
|
|
|
if (count > 0) {
|
|
|
|
/* Sort the list as an array in reverse order. */
|
|
|
|
qsort(paths, count, sizeof(*paths), pl_compare);
|
2009-04-18 23:25:08 +00:00
|
|
|
|
2014-05-02 07:57:29 -06:00
|
|
|
/* Build up the list in sorted order. */
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
SLIST_INSERT_HEAD(&stack->more, paths[i], entries);
|
|
|
|
}
|
2015-05-27 10:36:03 -06:00
|
|
|
free(paths);
|
2009-04-18 23:25:08 +00:00
|
|
|
}
|
2014-05-02 07:14:06 -06:00
|
|
|
|
2014-05-02 07:57:29 -06:00
|
|
|
debug_return_int(count);
|
2009-04-18 23:25:08 +00:00
|
|
|
}
|
|
|
|
|
2004-09-28 18:31:24 +00:00
|
|
|
#define MAX_SUDOERS_DEPTH 128
|
2004-10-26 22:12:47 +00:00
|
|
|
#define SUDOERS_STACK_INCREMENT 16
|
2004-09-28 18:31:24 +00:00
|
|
|
|
2009-04-18 23:25:08 +00:00
|
|
|
static size_t istacksize, idepth;
|
|
|
|
static struct include_stack *istack;
|
2011-12-02 11:27:33 -05:00
|
|
|
static bool keepopen;
|
2009-04-18 23:25:08 +00:00
|
|
|
|
|
|
|
void
|
2011-01-08 15:15:30 -05:00
|
|
|
init_lexer(void)
|
2009-04-18 23:25:08 +00:00
|
|
|
{
|
|
|
|
struct path_list *pl;
|
2019-12-22 08:48:16 -07:00
|
|
|
debug_decl(init_lexer, SUDOERS_DEBUG_PARSER);
|
2009-04-18 23:25:08 +00:00
|
|
|
|
|
|
|
while (idepth) {
|
|
|
|
idepth--;
|
2013-10-22 09:08:09 -06:00
|
|
|
while ((pl = SLIST_FIRST(&istack[idepth].more)) != NULL) {
|
|
|
|
SLIST_REMOVE_HEAD(&istack[idepth].more, entries);
|
2016-11-11 16:18:27 -07:00
|
|
|
rcstr_delref(pl->path);
|
2015-05-27 10:36:03 -06:00
|
|
|
free(pl);
|
2009-04-18 23:25:08 +00:00
|
|
|
}
|
2016-11-11 16:18:27 -07:00
|
|
|
rcstr_delref(istack[idepth].path);
|
2010-02-09 10:43:20 -05:00
|
|
|
if (idepth && !istack[idepth].keepopen)
|
2009-04-18 23:25:08 +00:00
|
|
|
fclose(istack[idepth].bs->yy_input_file);
|
2012-09-14 16:19:25 -04:00
|
|
|
sudoers_delete_buffer(istack[idepth].bs);
|
2020-08-06 21:16:35 -06:00
|
|
|
free(istack[idepth].line.buf);
|
2009-04-18 23:25:08 +00:00
|
|
|
}
|
2015-05-27 10:36:03 -06:00
|
|
|
free(istack);
|
2009-04-18 23:25:08 +00:00
|
|
|
istack = NULL;
|
|
|
|
istacksize = idepth = 0;
|
2020-08-06 21:16:35 -06:00
|
|
|
free(sudolinebuf.buf);
|
|
|
|
memset(&sudolinebuf, 0, sizeof(sudolinebuf));
|
2011-03-27 09:45:42 -04:00
|
|
|
sudolineno = 1;
|
2011-12-02 11:27:33 -05:00
|
|
|
keepopen = false;
|
|
|
|
sawspace = false;
|
|
|
|
continued = false;
|
2018-05-24 21:04:07 -06:00
|
|
|
digest_type = -1;
|
2011-03-27 09:45:42 -04:00
|
|
|
prev_state = INITIAL;
|
2011-10-22 14:40:21 -04:00
|
|
|
|
|
|
|
debug_return;
|
2009-04-18 23:25:08 +00:00
|
|
|
}
|
|
|
|
|
2020-05-20 13:10:53 -06:00
|
|
|
/*
|
|
|
|
* Expand any embedded %h (host) escapes in the given path and makes
|
|
|
|
* a relative path fully-qualified based on the current sudoers file.
|
|
|
|
* Returns a reference-counted string.
|
|
|
|
*/
|
|
|
|
static char *
|
|
|
|
expand_include(const char *opath, size_t olen)
|
|
|
|
{
|
|
|
|
const char *cp, *ep;
|
|
|
|
char *path, *pp;
|
|
|
|
int dirlen = 0, len;
|
|
|
|
size_t shost_len = 0;
|
|
|
|
bool subst = false;
|
|
|
|
debug_decl(expand_include, SUDOERS_DEBUG_PARSER);
|
|
|
|
|
|
|
|
/* Strip double quotes if present. */
|
|
|
|
if (*opath == '"') {
|
|
|
|
opath++;
|
|
|
|
olen -= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Relative paths are located in the same dir as the sudoers file. */
|
|
|
|
if (*opath != '/') {
|
|
|
|
char *dirend = strrchr(sudoers, '/');
|
|
|
|
if (dirend != NULL)
|
|
|
|
dirlen = (int)(dirend - sudoers) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = olen;
|
|
|
|
for (cp = opath, ep = opath + olen; cp < ep; cp++) {
|
|
|
|
if (cp[0] == '%' && cp[1] == 'h') {
|
|
|
|
shost_len = strlen(user_shost);
|
|
|
|
len += shost_len - 2;
|
|
|
|
subst = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make a copy of the fully-qualified path and return it. */
|
|
|
|
path = pp = rcstr_alloc(len + dirlen);
|
|
|
|
if (path == NULL) {
|
|
|
|
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
|
|
|
|
sudoerserror(NULL);
|
|
|
|
debug_return_str(NULL);
|
|
|
|
}
|
|
|
|
if (dirlen) {
|
|
|
|
memcpy(path, sudoers, dirlen);
|
|
|
|
pp += dirlen;
|
|
|
|
}
|
|
|
|
if (subst) {
|
|
|
|
/* substitute for %h */
|
|
|
|
cp = opath;
|
|
|
|
while (cp < ep) {
|
|
|
|
if (cp[0] == '%' && cp[1] == 'h') {
|
|
|
|
memcpy(pp, user_shost, shost_len);
|
|
|
|
pp += shost_len;
|
|
|
|
cp += 2;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
*pp++ = *cp++;
|
|
|
|
}
|
|
|
|
*pp = '\0';
|
|
|
|
} else {
|
|
|
|
memcpy(pp, opath, len);
|
|
|
|
pp[len] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
debug_return_str(path);
|
|
|
|
}
|
|
|
|
|
2016-07-03 06:19:43 -06:00
|
|
|
/*
|
|
|
|
* Open an include file (or file from a directory), push the old
|
|
|
|
* sudoers file buffer and switch to the new one.
|
|
|
|
* A missing or insecure include dir is simply ignored.
|
|
|
|
* Returns false on error, else true.
|
|
|
|
*/
|
2020-05-20 13:10:53 -06:00
|
|
|
bool
|
|
|
|
push_include(const char *opath, bool isdir)
|
2004-09-27 16:03:15 +00:00
|
|
|
{
|
2010-06-08 16:53:38 -04:00
|
|
|
struct path_list *pl;
|
2020-05-20 13:10:53 -06:00
|
|
|
char *path;
|
2004-09-27 16:03:15 +00:00
|
|
|
FILE *fp;
|
2020-05-20 13:10:53 -06:00
|
|
|
debug_decl(push_include, SUDOERS_DEBUG_PARSER);
|
|
|
|
|
|
|
|
if ((path = expand_include(opath, strlen(opath))) == NULL)
|
|
|
|
debug_return_bool(false);
|
2004-09-27 16:03:15 +00:00
|
|
|
|
2009-04-18 23:25:08 +00:00
|
|
|
/* push current state onto stack */
|
|
|
|
if (idepth >= istacksize) {
|
2014-01-13 09:52:41 -07:00
|
|
|
struct include_stack *new_istack;
|
|
|
|
|
2009-04-18 23:25:08 +00:00
|
|
|
if (idepth > MAX_SUDOERS_DEPTH) {
|
2012-11-25 09:33:58 -05:00
|
|
|
sudoerserror(N_("too many levels of includes"));
|
2020-05-19 10:09:34 -06:00
|
|
|
rcstr_delref(path);
|
2011-12-02 11:27:33 -05:00
|
|
|
debug_return_bool(false);
|
2009-04-18 23:25:08 +00:00
|
|
|
}
|
|
|
|
istacksize += SUDOERS_STACK_INCREMENT;
|
2015-05-14 10:21:58 -06:00
|
|
|
new_istack = reallocarray(istack, istacksize, sizeof(*istack));
|
2014-01-13 09:52:41 -07:00
|
|
|
if (new_istack == NULL) {
|
2015-07-14 14:50:36 -06:00
|
|
|
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
|
2012-11-25 09:33:58 -05:00
|
|
|
sudoerserror(NULL);
|
2020-05-19 10:09:34 -06:00
|
|
|
rcstr_delref(path);
|
2011-12-02 11:27:33 -05:00
|
|
|
debug_return_bool(false);
|
2004-09-27 16:03:15 +00:00
|
|
|
}
|
2014-01-13 09:52:41 -07:00
|
|
|
istack = new_istack;
|
2009-04-18 23:25:08 +00:00
|
|
|
}
|
2013-10-22 09:08:09 -06:00
|
|
|
SLIST_INIT(&istack[idepth].more);
|
2009-04-18 23:25:08 +00:00
|
|
|
if (isdir) {
|
2012-02-29 15:50:48 -05:00
|
|
|
struct stat sb;
|
2016-07-03 06:19:43 -06:00
|
|
|
int count, status;
|
|
|
|
|
|
|
|
status = sudo_secure_dir(path, sudoers_uid, sudoers_gid, &sb);
|
|
|
|
if (status != SUDO_PATH_SECURE) {
|
|
|
|
if (sudoers_warnings) {
|
|
|
|
switch (status) {
|
|
|
|
case SUDO_PATH_BAD_TYPE:
|
|
|
|
errno = ENOTDIR;
|
2014-06-27 09:30:52 -06:00
|
|
|
sudo_warn("%s", path);
|
2016-07-03 06:19:43 -06:00
|
|
|
break;
|
|
|
|
case SUDO_PATH_WRONG_OWNER:
|
2014-06-27 09:30:52 -06:00
|
|
|
sudo_warnx(U_("%s is owned by uid %u, should be %u"),
|
2012-02-29 15:50:48 -05:00
|
|
|
path, (unsigned int) sb.st_uid,
|
|
|
|
(unsigned int) sudoers_uid);
|
2016-07-03 06:19:43 -06:00
|
|
|
break;
|
|
|
|
case SUDO_PATH_WORLD_WRITABLE:
|
2014-06-27 09:30:52 -06:00
|
|
|
sudo_warnx(U_("%s is world writable"), path);
|
2016-07-03 06:19:43 -06:00
|
|
|
break;
|
|
|
|
case SUDO_PATH_GROUP_WRITABLE:
|
2014-06-27 09:30:52 -06:00
|
|
|
sudo_warnx(U_("%s is owned by gid %u, should be %u"),
|
2012-02-29 15:50:48 -05:00
|
|
|
path, (unsigned int) sb.st_gid,
|
|
|
|
(unsigned int) sudoers_gid);
|
2016-07-03 06:19:43 -06:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2012-02-29 15:50:48 -05:00
|
|
|
}
|
2016-07-03 06:19:43 -06:00
|
|
|
}
|
|
|
|
/* A missing or insecure include dir is not a fatal error. */
|
2020-05-19 10:09:34 -06:00
|
|
|
rcstr_delref(path);
|
2016-07-03 06:19:43 -06:00
|
|
|
debug_return_bool(true);
|
2012-02-29 15:50:48 -05:00
|
|
|
}
|
2014-05-02 07:57:29 -06:00
|
|
|
count = switch_dir(&istack[idepth], path);
|
|
|
|
if (count <= 0) {
|
2012-09-14 16:19:25 -04:00
|
|
|
/* switch_dir() called sudoerserror() for us */
|
2016-11-11 16:18:27 -07:00
|
|
|
rcstr_delref(path);
|
2014-05-02 07:57:29 -06:00
|
|
|
debug_return_bool(count ? false : true);
|
2004-09-28 00:47:30 +00:00
|
|
|
}
|
2014-05-02 07:57:29 -06:00
|
|
|
|
|
|
|
/* Parse the first dir entry we can open, leave the rest for later. */
|
|
|
|
do {
|
2016-11-11 16:18:27 -07:00
|
|
|
rcstr_delref(path);
|
2014-05-02 07:57:29 -06:00
|
|
|
if ((pl = SLIST_FIRST(&istack[idepth].more)) == NULL) {
|
|
|
|
/* Unable to open any files in include dir, not an error. */
|
|
|
|
debug_return_bool(true);
|
|
|
|
}
|
2013-10-22 09:08:09 -06:00
|
|
|
SLIST_REMOVE_HEAD(&istack[idepth].more, entries);
|
2010-06-08 16:53:38 -04:00
|
|
|
path = pl->path;
|
2015-05-27 10:36:03 -06:00
|
|
|
free(pl);
|
2014-05-02 07:57:29 -06:00
|
|
|
} while ((fp = open_sudoers(path, false, &keepopen)) == NULL);
|
2009-04-18 23:25:08 +00:00
|
|
|
} else {
|
2011-12-02 11:27:33 -05:00
|
|
|
if ((fp = open_sudoers(path, true, &keepopen)) == NULL) {
|
2012-08-23 14:02:02 -04:00
|
|
|
/* The error was already printed by open_sudoers() */
|
2012-09-14 16:19:25 -04:00
|
|
|
sudoerserror(NULL);
|
2020-05-19 10:09:34 -06:00
|
|
|
rcstr_delref(path);
|
2011-12-02 11:27:33 -05:00
|
|
|
debug_return_bool(false);
|
2009-04-18 23:25:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Push the old (current) file and open the new one. */
|
2016-11-11 16:18:27 -07:00
|
|
|
istack[idepth].path = sudoers; /* push old path (and its ref) */
|
2020-08-06 21:16:35 -06:00
|
|
|
istack[idepth].line = sudolinebuf;
|
2009-04-18 23:25:08 +00:00
|
|
|
istack[idepth].bs = YY_CURRENT_BUFFER;
|
|
|
|
istack[idepth].lineno = sudolineno;
|
|
|
|
istack[idepth].keepopen = keepopen;
|
|
|
|
idepth++;
|
|
|
|
sudolineno = 1;
|
|
|
|
sudoers = path;
|
2012-09-14 16:19:25 -04:00
|
|
|
sudoers_switch_to_buffer(sudoers_create_buffer(fp, YY_BUF_SIZE));
|
2020-08-06 21:16:35 -06:00
|
|
|
memset(&sudolinebuf, 0, sizeof(sudolinebuf));
|
2009-04-18 23:25:08 +00:00
|
|
|
|
2011-12-02 11:27:33 -05:00
|
|
|
debug_return_bool(true);
|
2009-04-18 23:25:08 +00:00
|
|
|
}
|
|
|
|
|
2016-07-03 06:19:43 -06:00
|
|
|
/*
|
|
|
|
* Restore the previous sudoers file and buffer, or, in the case
|
|
|
|
* of an includedir, switch to the next file in the dir.
|
|
|
|
* Returns false if there is nothing to pop, else true.
|
|
|
|
*/
|
2011-12-02 11:27:33 -05:00
|
|
|
static bool
|
2011-01-08 15:15:30 -05:00
|
|
|
pop_include(void)
|
2009-04-18 23:25:08 +00:00
|
|
|
{
|
|
|
|
struct path_list *pl;
|
|
|
|
FILE *fp;
|
2019-12-22 08:48:16 -07:00
|
|
|
debug_decl(pop_include, SUDOERS_DEBUG_PARSER);
|
2009-04-18 23:25:08 +00:00
|
|
|
|
2018-05-28 08:30:57 -06:00
|
|
|
if (idepth == 0 || YY_CURRENT_BUFFER == NULL)
|
2011-12-02 11:27:33 -05:00
|
|
|
debug_return_bool(false);
|
2009-04-18 23:25:08 +00:00
|
|
|
|
|
|
|
if (!keepopen)
|
|
|
|
fclose(YY_CURRENT_BUFFER->yy_input_file);
|
2012-09-14 16:19:25 -04:00
|
|
|
sudoers_delete_buffer(YY_CURRENT_BUFFER);
|
2010-06-08 16:53:38 -04:00
|
|
|
/* If we are in an include dir, move to the next file. */
|
2013-10-22 09:08:09 -06:00
|
|
|
while ((pl = SLIST_FIRST(&istack[idepth - 1].more)) != NULL) {
|
|
|
|
SLIST_REMOVE_HEAD(&istack[idepth - 1].more, entries);
|
2011-12-02 11:27:33 -05:00
|
|
|
fp = open_sudoers(pl->path, false, &keepopen);
|
2010-06-08 16:53:38 -04:00
|
|
|
if (fp != NULL) {
|
2020-08-06 21:16:35 -06:00
|
|
|
sudolinebuf.len = sudolinebuf.off = 0;
|
2020-08-07 14:20:45 -06:00
|
|
|
sudolinebuf.toke_start = sudolinebuf.toke_end = 0;
|
2016-11-11 16:18:27 -07:00
|
|
|
rcstr_delref(sudoers);
|
2010-06-08 16:53:38 -04:00
|
|
|
sudoers = pl->path;
|
|
|
|
sudolineno = 1;
|
2012-09-14 16:19:25 -04:00
|
|
|
sudoers_switch_to_buffer(sudoers_create_buffer(fp, YY_BUF_SIZE));
|
2015-05-27 10:36:03 -06:00
|
|
|
free(pl);
|
2010-06-08 16:53:38 -04:00
|
|
|
break;
|
2009-04-18 23:25:08 +00:00
|
|
|
}
|
2010-06-08 16:53:38 -04:00
|
|
|
/* Unable to open path in include dir, go to next one. */
|
2016-11-11 16:18:27 -07:00
|
|
|
rcstr_delref(pl->path);
|
2015-05-27 10:36:03 -06:00
|
|
|
free(pl);
|
2010-06-08 16:53:38 -04:00
|
|
|
}
|
|
|
|
/* If no path list, just pop the last dir on the stack. */
|
|
|
|
if (pl == NULL) {
|
2009-04-18 23:25:08 +00:00
|
|
|
idepth--;
|
2012-09-14 16:19:25 -04:00
|
|
|
sudoers_switch_to_buffer(istack[idepth].bs);
|
2020-08-06 21:16:35 -06:00
|
|
|
free(sudolinebuf.buf);
|
|
|
|
sudolinebuf = istack[idepth].line;
|
2016-11-11 16:18:27 -07:00
|
|
|
rcstr_delref(sudoers);
|
2009-04-18 23:25:08 +00:00
|
|
|
sudoers = istack[idepth].path;
|
|
|
|
sudolineno = istack[idepth].lineno;
|
2010-06-10 16:36:41 -04:00
|
|
|
keepopen = istack[idepth].keepopen;
|
2004-09-27 16:03:15 +00:00
|
|
|
}
|
2011-12-02 11:27:33 -05:00
|
|
|
debug_return_bool(true);
|
2004-09-27 16:03:15 +00:00
|
|
|
}
|
2007-08-23 11:47:08 +00:00
|
|
|
|
2011-03-21 17:57:38 -04:00
|
|
|
#ifdef TRACELEXER
|
2012-08-23 11:28:44 -04:00
|
|
|
int
|
2011-03-21 17:57:38 -04:00
|
|
|
sudoers_trace_print(const char *msg)
|
|
|
|
{
|
|
|
|
return fputs(msg, stderr);
|
|
|
|
}
|
2011-11-12 12:41:44 -05:00
|
|
|
#else
|
2012-08-23 11:28:44 -04:00
|
|
|
int
|
2011-11-12 12:41:44 -05:00
|
|
|
sudoers_trace_print(const char *msg)
|
|
|
|
{
|
2011-12-02 11:27:33 -05:00
|
|
|
static bool initialized;
|
2014-06-26 15:51:15 -06:00
|
|
|
static struct sudo_lbuf lbuf;
|
2011-11-12 12:41:44 -05:00
|
|
|
|
|
|
|
if (!initialized) {
|
2011-12-02 11:27:33 -05:00
|
|
|
initialized = true;
|
2014-06-26 15:51:15 -06:00
|
|
|
sudo_lbuf_init(&lbuf, NULL, 0, NULL, 0);
|
2011-11-12 12:41:44 -05:00
|
|
|
}
|
|
|
|
|
2014-06-26 15:51:15 -06:00
|
|
|
sudo_lbuf_append(&lbuf, "%s", msg);
|
2011-11-12 12:41:44 -05:00
|
|
|
/* XXX - assumes a final newline */
|
|
|
|
if (strchr(msg, '\n') != NULL)
|
|
|
|
{
|
2014-10-22 13:30:52 -06:00
|
|
|
sudo_debug_printf2(NULL, NULL, 0, SUDOERS_DEBUG_PARSER|SUDO_DEBUG_DEBUG,
|
2020-08-07 14:20:45 -06:00
|
|
|
"%s:%d: %s", sudoers, sudolineno, lbuf.buf);
|
2011-11-12 12:41:44 -05:00
|
|
|
lbuf.len = 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2011-03-21 17:57:38 -04:00
|
|
|
#endif /* TRACELEXER */
|
2020-08-06 21:16:35 -06:00
|
|
|
|
|
|
|
static yy_size_t
|
|
|
|
sudoers_input(char *buf, yy_size_t max_size)
|
|
|
|
{
|
|
|
|
size_t avail = sudolinebuf.len - sudolinebuf.off;
|
|
|
|
|
|
|
|
/* Refill line buffer if needed. */
|
|
|
|
if (avail == 0) {
|
2020-08-07 14:20:45 -06:00
|
|
|
avail = getdelim(&sudolinebuf.buf, &sudolinebuf.size, '\n', sudoersin);
|
|
|
|
if (avail == (size_t)-1) {
|
|
|
|
/* EOF or error. */
|
2020-08-06 21:16:35 -06:00
|
|
|
if (ferror(sudoersin) && errno != EINTR)
|
|
|
|
YY_FATAL_ERROR("input in flex scanner failed");
|
|
|
|
return 0;
|
|
|
|
}
|
2020-08-07 14:20:45 -06:00
|
|
|
sudolinebuf.len = avail;
|
|
|
|
sudolinebuf.off = 0;
|
|
|
|
sudolinebuf.toke_start = sudolinebuf.toke_end = 0;
|
2020-08-06 21:16:35 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (avail > max_size)
|
|
|
|
avail = max_size;
|
|
|
|
memcpy(buf, sudolinebuf.buf + sudolinebuf.off, avail);
|
|
|
|
sudolinebuf.off += avail;
|
|
|
|
|
|
|
|
return avail;
|
|
|
|
}
|