1993-11-27 23:42:49 +00:00
|
|
|
/*
|
2010-06-14 12:19:49 -04:00
|
|
|
* Copyright (c) 1993-1996, 1998-2005, 2007-2010
|
2007-06-23 23:58:54 +00:00
|
|
|
* Todd C. Miller <Todd.Miller@courtesan.com>
|
1993-11-27 23:42:49 +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.
|
1999-07-31 16:19:50 +00:00
|
|
|
*
|
2004-02-13 21:36:43 +00:00
|
|
|
* 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.
|
1993-03-02 23:28:50 +00:00
|
|
|
*
|
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 23:28:50 +00:00
|
|
|
*/
|
|
|
|
|
2010-03-14 19:58:47 -04:00
|
|
|
#ifndef _SUDO_SUDOERS_H
|
|
|
|
#define _SUDO_SUDOERS_H
|
1994-05-25 01:25:40 +00:00
|
|
|
|
2004-06-01 01:22:27 +00:00
|
|
|
#include <limits.h>
|
2010-09-07 18:28:22 -04:00
|
|
|
|
|
|
|
#include <pathnames.h>
|
|
|
|
#include "missing.h"
|
|
|
|
#include "error.h"
|
|
|
|
#include "alloc.h"
|
|
|
|
#include "list.h"
|
|
|
|
#include "fileops.h"
|
1999-09-08 08:06:28 +00:00
|
|
|
#include "defaults.h"
|
1999-07-22 12:56:28 +00:00
|
|
|
#include "logging.h"
|
2007-12-28 16:20:45 +00:00
|
|
|
#include "sudo_nss.h"
|
2010-03-14 19:58:47 -04:00
|
|
|
#include "sudo_plugin.h"
|
1994-01-27 19:07:34 +00:00
|
|
|
|
2009-12-12 15:37:52 +00:00
|
|
|
#ifdef HAVE_MBR_CHECK_MEMBERSHIP
|
|
|
|
# include <membership.h>
|
|
|
|
#endif
|
|
|
|
|
1995-03-24 03:32:53 +00:00
|
|
|
/*
|
1999-07-22 12:56:28 +00:00
|
|
|
* Info pertaining to the invoking user.
|
1995-03-24 03:32:53 +00:00
|
|
|
*/
|
1999-07-22 12:56:28 +00:00
|
|
|
struct sudo_user {
|
|
|
|
struct passwd *pw;
|
2000-12-30 03:29:47 +00:00
|
|
|
struct passwd *_runas_pw;
|
2007-11-21 20:12:00 +00:00
|
|
|
struct group *_runas_gr;
|
2004-08-24 18:01:14 +00:00
|
|
|
struct stat *cmnd_stat;
|
2010-03-14 19:58:47 -04:00
|
|
|
char *name;
|
2000-12-30 03:29:47 +00:00
|
|
|
char *path;
|
1999-07-22 12:56:28 +00:00
|
|
|
char *tty;
|
2007-09-13 23:05:34 +00:00
|
|
|
char *ttypath;
|
1999-07-22 12:56:28 +00:00
|
|
|
char *host;
|
|
|
|
char *shost;
|
|
|
|
char *prompt;
|
1996-08-09 22:06:40 +00:00
|
|
|
char *cmnd;
|
1999-07-22 12:56:28 +00:00
|
|
|
char *cmnd_args;
|
2004-08-24 18:01:14 +00:00
|
|
|
char *cmnd_base;
|
|
|
|
char *cmnd_safe;
|
2000-03-07 04:29:46 +00:00
|
|
|
char *class_name;
|
2007-07-15 19:44:46 +00:00
|
|
|
char *krb5_ccname;
|
2010-05-24 15:40:36 -04:00
|
|
|
int closefrom;
|
2004-11-16 04:24:11 +00:00
|
|
|
int ngroups;
|
2010-03-14 19:58:47 -04:00
|
|
|
uid_t uid;
|
|
|
|
uid_t gid;
|
2010-03-17 21:25:32 -04:00
|
|
|
int lines;
|
|
|
|
int cols;
|
2007-11-27 23:40:50 +00:00
|
|
|
GETGROUPS_T *groups;
|
2010-04-26 17:14:11 -04:00
|
|
|
char * const * env_vars;
|
2008-02-09 14:30:07 +00:00
|
|
|
#ifdef HAVE_SELINUX
|
|
|
|
char *role;
|
|
|
|
char *type;
|
|
|
|
#endif
|
2010-03-14 19:58:47 -04:00
|
|
|
char *cwd;
|
2009-08-30 15:18:50 +00:00
|
|
|
char sessid[7];
|
2009-12-12 15:37:52 +00:00
|
|
|
#ifdef HAVE_MBR_CHECK_MEMBERSHIP
|
|
|
|
uuid_t uuid;
|
|
|
|
#endif
|
1996-08-17 17:22:02 +00:00
|
|
|
};
|
|
|
|
|
1994-02-27 22:18:51 +00:00
|
|
|
/*
|
1999-08-19 16:30:09 +00:00
|
|
|
* Return values for sudoers_lookup(), also used as arguments for log_auth()
|
|
|
|
* Note: cannot use '0' as a value here.
|
1998-10-18 23:10:18 +00:00
|
|
|
*/
|
1999-08-19 16:30:09 +00:00
|
|
|
/* XXX - VALIDATE_SUCCESS and VALIDATE_FAILURE instead? */
|
2003-12-30 22:31:30 +00:00
|
|
|
#define VALIDATE_ERROR 0x001
|
|
|
|
#define VALIDATE_OK 0x002
|
|
|
|
#define VALIDATE_NOT_OK 0x004
|
|
|
|
#define FLAG_CHECK_USER 0x010
|
2004-11-19 23:00:28 +00:00
|
|
|
#define FLAG_NO_USER 0x020
|
|
|
|
#define FLAG_NO_HOST 0x040
|
|
|
|
#define FLAG_NO_CHECK 0x080
|
1993-03-02 23:28:50 +00:00
|
|
|
|
1995-04-09 21:35:00 +00:00
|
|
|
/*
|
2004-06-05 17:42:04 +00:00
|
|
|
* Pseudo-boolean values
|
1995-04-09 21:35:00 +00:00
|
|
|
*/
|
1993-03-02 23:28:50 +00:00
|
|
|
#undef TRUE
|
1998-11-08 20:56:52 +00:00
|
|
|
#define TRUE 1
|
1993-03-02 23:28:50 +00:00
|
|
|
#undef FALSE
|
1998-11-08 20:56:52 +00:00
|
|
|
#define FALSE 0
|
|
|
|
|
|
|
|
/*
|
|
|
|
* find_path()/load_cmnd() return values
|
|
|
|
*/
|
2010-03-14 19:58:47 -04:00
|
|
|
#define FOUND 0
|
|
|
|
#define NOT_FOUND 1
|
|
|
|
#define NOT_FOUND_DOT 2
|
1993-03-02 23:28:50 +00:00
|
|
|
|
1995-04-09 21:35:00 +00:00
|
|
|
/*
|
2004-11-24 21:31:51 +00:00
|
|
|
* Various modes sudo can be in (based on arguments) in hex
|
1995-04-09 21:35:00 +00:00
|
|
|
*/
|
2008-03-27 23:01:04 +00:00
|
|
|
#define MODE_RUN 0x00000001
|
|
|
|
#define MODE_EDIT 0x00000002
|
|
|
|
#define MODE_VALIDATE 0x00000004
|
|
|
|
#define MODE_INVALIDATE 0x00000008
|
|
|
|
#define MODE_KILL 0x00000010
|
|
|
|
#define MODE_VERSION 0x00000020
|
|
|
|
#define MODE_HELP 0x00000040
|
|
|
|
#define MODE_LIST 0x00000080
|
|
|
|
#define MODE_CHECK 0x00000100
|
|
|
|
#define MODE_LISTDEFS 0x00000200
|
|
|
|
#define MODE_MASK 0x0000ffff
|
|
|
|
|
|
|
|
/* Mode flags */
|
|
|
|
#define MODE_BACKGROUND 0x00010000
|
|
|
|
#define MODE_SHELL 0x00020000
|
|
|
|
#define MODE_LOGIN_SHELL 0x00040000
|
|
|
|
#define MODE_IMPLIED_SHELL 0x00080000
|
|
|
|
#define MODE_RESET_HOME 0x00100000
|
|
|
|
#define MODE_PRESERVE_GROUPS 0x00200000
|
|
|
|
#define MODE_PRESERVE_ENV 0x00400000
|
|
|
|
#define MODE_NONINTERACTIVE 0x00800000
|
2010-03-15 19:41:15 -04:00
|
|
|
#define MODE_IGNORE_TICKET 0x01000000
|
1994-08-05 00:24:07 +00:00
|
|
|
|
1995-04-09 21:35:00 +00:00
|
|
|
/*
|
|
|
|
* Used with set_perms()
|
|
|
|
*/
|
2010-04-10 10:34:37 -04:00
|
|
|
#define PERM_INITIAL 0x00
|
|
|
|
#define PERM_ROOT 0x01
|
|
|
|
#define PERM_USER 0x02
|
|
|
|
#define PERM_FULL_USER 0x03
|
|
|
|
#define PERM_SUDOERS 0x04
|
|
|
|
#define PERM_RUNAS 0x05
|
2010-04-22 17:40:01 -04:00
|
|
|
#define PERM_TIMESTAMP 0x06
|
2009-05-10 11:52:13 +00:00
|
|
|
#define PERM_NOEXIT 0x10 /* flag */
|
|
|
|
#define PERM_MASK 0xf0
|
1994-11-08 01:39:43 +00:00
|
|
|
|
1995-11-24 02:27:27 +00:00
|
|
|
/*
|
1999-07-22 12:56:28 +00:00
|
|
|
* Shortcuts for sudo_user contents.
|
1999-02-07 00:43:24 +00:00
|
|
|
*/
|
2010-03-14 19:58:47 -04:00
|
|
|
#define user_name (sudo_user.name)
|
|
|
|
#define user_uid (sudo_user.uid)
|
|
|
|
#define user_gid (sudo_user.gid)
|
1999-07-22 12:56:28 +00:00
|
|
|
#define user_passwd (sudo_user.pw->pw_passwd)
|
2009-12-12 15:37:52 +00:00
|
|
|
#define user_uuid (sudo_user.uuid)
|
1999-07-22 12:56:28 +00:00
|
|
|
#define user_dir (sudo_user.pw->pw_dir)
|
2004-11-16 04:24:11 +00:00
|
|
|
#define user_ngroups (sudo_user.ngroups)
|
|
|
|
#define user_groups (sudo_user.groups)
|
1999-07-22 12:56:28 +00:00
|
|
|
#define user_tty (sudo_user.tty)
|
2007-09-13 23:05:34 +00:00
|
|
|
#define user_ttypath (sudo_user.ttypath)
|
1999-07-22 12:56:28 +00:00
|
|
|
#define user_cwd (sudo_user.cwd)
|
|
|
|
#define user_cmnd (sudo_user.cmnd)
|
|
|
|
#define user_args (sudo_user.cmnd_args)
|
2004-08-24 18:01:14 +00:00
|
|
|
#define user_base (sudo_user.cmnd_base)
|
|
|
|
#define user_stat (sudo_user.cmnd_stat)
|
2000-12-30 03:29:47 +00:00
|
|
|
#define user_path (sudo_user.path)
|
1999-07-22 12:56:28 +00:00
|
|
|
#define user_prompt (sudo_user.prompt)
|
|
|
|
#define user_host (sudo_user.host)
|
|
|
|
#define user_shost (sudo_user.shost)
|
2007-07-15 19:44:46 +00:00
|
|
|
#define user_ccname (sudo_user.krb5_ccname)
|
1999-07-22 12:56:28 +00:00
|
|
|
#define safe_cmnd (sudo_user.cmnd_safe)
|
2000-03-07 04:29:46 +00:00
|
|
|
#define login_class (sudo_user.class_name)
|
2000-12-30 03:29:47 +00:00
|
|
|
#define runas_pw (sudo_user._runas_pw)
|
2007-11-21 20:12:00 +00:00
|
|
|
#define runas_gr (sudo_user._runas_gr)
|
2008-02-09 14:30:07 +00:00
|
|
|
#define user_role (sudo_user.role)
|
|
|
|
#define user_type (sudo_user.type)
|
2010-05-24 15:40:36 -04:00
|
|
|
#define user_closefrom (sudo_user.closefrom)
|
1999-02-07 00:43:24 +00:00
|
|
|
|
2010-07-02 11:11:25 -04:00
|
|
|
#ifdef __TANDEM
|
|
|
|
# define ROOT_UID 65535
|
|
|
|
#else
|
|
|
|
# define ROOT_UID 0
|
|
|
|
#endif
|
|
|
|
|
1999-05-17 01:36:30 +00:00
|
|
|
/*
|
|
|
|
* We used to use the system definition of PASS_MAX or _PASSWD_LEN,
|
|
|
|
* but that caused problems with various alternate authentication
|
|
|
|
* methods. So, we just define our own and assume that it is >= the
|
|
|
|
* system max.
|
|
|
|
*/
|
|
|
|
#define SUDO_PASS_MAX 256
|
|
|
|
|
2008-02-03 15:43:38 +00:00
|
|
|
struct lbuf;
|
2004-11-25 17:20:57 +00:00
|
|
|
struct passwd;
|
2010-06-16 17:10:04 -04:00
|
|
|
struct stat;
|
|
|
|
struct timeval;
|
2004-11-25 17:20:57 +00:00
|
|
|
|
1994-05-28 19:13:44 +00:00
|
|
|
/*
|
1996-06-20 04:41:55 +00:00
|
|
|
* Function prototypes
|
1994-05-28 19:13:44 +00:00
|
|
|
*/
|
2010-03-17 19:56:27 -04:00
|
|
|
#define YY_DECL int yylex(void)
|
1994-05-28 19:13:44 +00:00
|
|
|
|
2010-04-22 17:40:01 -04:00
|
|
|
/* goodpath.c */
|
2010-03-17 19:56:27 -04:00
|
|
|
char *sudo_goodpath(const char *, struct stat *);
|
2010-04-22 17:40:01 -04:00
|
|
|
|
|
|
|
/* findpath.c */
|
2010-05-13 10:27:03 -04:00
|
|
|
int find_path(char *, char **, struct stat *, char *, int);
|
2010-04-22 17:40:01 -04:00
|
|
|
|
|
|
|
/* check.c */
|
2010-03-17 19:56:27 -04:00
|
|
|
int check_user(int, int);
|
2010-04-22 17:40:01 -04:00
|
|
|
void remove_timestamp(int);
|
|
|
|
int user_is_exempt(void);
|
|
|
|
|
|
|
|
/* sudo_auth.c */
|
2010-03-17 19:56:27 -04:00
|
|
|
int verify_user(struct passwd *, char *);
|
2010-05-27 14:46:39 -04:00
|
|
|
int auth_begin_session(struct passwd *);
|
|
|
|
int auth_end_session();
|
2010-04-22 17:40:01 -04:00
|
|
|
|
|
|
|
/* parse.c */
|
2010-03-17 19:56:27 -04:00
|
|
|
int sudo_file_open(struct sudo_nss *);
|
|
|
|
int sudo_file_close(struct sudo_nss *);
|
|
|
|
int sudo_file_setdefs(struct sudo_nss *);
|
|
|
|
int sudo_file_lookup(struct sudo_nss *, int, int);
|
|
|
|
int sudo_file_parse(struct sudo_nss *);
|
|
|
|
int sudo_file_display_cmnd(struct sudo_nss *, struct passwd *);
|
|
|
|
int sudo_file_display_defaults(struct sudo_nss *, struct passwd *, struct lbuf *);
|
|
|
|
int sudo_file_display_bound_defaults(struct sudo_nss *, struct passwd *, struct lbuf *);
|
|
|
|
int sudo_file_display_privs(struct sudo_nss *, struct passwd *, struct lbuf *);
|
2010-04-22 17:40:01 -04:00
|
|
|
|
|
|
|
/* set_perms.c */
|
2010-04-20 17:00:31 -04:00
|
|
|
void rewind_perms(void);
|
2010-03-17 19:56:27 -04:00
|
|
|
int set_perms(int);
|
2010-04-20 17:00:31 -04:00
|
|
|
void restore_perms(void);
|
2010-04-22 17:40:01 -04:00
|
|
|
int pam_prep_user(struct passwd *);
|
|
|
|
|
|
|
|
/* gram.y */
|
2010-03-17 19:56:27 -04:00
|
|
|
int yyparse(void);
|
2010-04-22 17:40:01 -04:00
|
|
|
|
|
|
|
/* toke.l */
|
|
|
|
YY_DECL;
|
|
|
|
|
|
|
|
/* defaults.c */
|
2010-03-17 19:56:27 -04:00
|
|
|
void dump_defaults(void);
|
|
|
|
void dump_auth_methods(void);
|
2010-04-22 17:40:01 -04:00
|
|
|
|
|
|
|
/* getspwuid.c */
|
2010-03-17 19:56:27 -04:00
|
|
|
char *sudo_getepw(const struct passwd *);
|
2010-04-22 17:40:01 -04:00
|
|
|
|
|
|
|
/* zero_bytes.c */
|
2010-03-17 19:56:27 -04:00
|
|
|
void zero_bytes(volatile void *, size_t);
|
2010-04-22 17:40:01 -04:00
|
|
|
|
|
|
|
/* sudo_nss.c */
|
2010-03-17 19:56:27 -04:00
|
|
|
void display_privs(struct sudo_nss_list *, struct passwd *);
|
|
|
|
int display_cmnd(struct sudo_nss_list *, struct passwd *);
|
2010-04-22 17:40:01 -04:00
|
|
|
|
|
|
|
/* pwutil.c */
|
2010-03-17 19:56:27 -04:00
|
|
|
void sudo_setgrent(void);
|
|
|
|
void sudo_endgrent(void);
|
|
|
|
void sudo_setpwent(void);
|
|
|
|
void sudo_endpwent(void);
|
|
|
|
void sudo_setspent(void);
|
|
|
|
void sudo_endspent(void);
|
|
|
|
struct passwd *sudo_getpwnam(const char *);
|
|
|
|
struct passwd *sudo_fakepwnam(const char *, gid_t);
|
|
|
|
struct passwd *sudo_getpwuid(uid_t);
|
|
|
|
struct group *sudo_getgrnam(const char *);
|
|
|
|
struct group *sudo_fakegrnam(const char *);
|
|
|
|
struct group *sudo_getgrgid(gid_t);
|
2010-08-04 09:58:50 -04:00
|
|
|
void gr_addref(struct group *);
|
|
|
|
void gr_delref(struct group *);
|
|
|
|
void pw_addref(struct passwd *);
|
|
|
|
void pw_delref(struct passwd *);
|
2010-03-17 19:56:27 -04:00
|
|
|
int user_in_group(struct passwd *, const char *);
|
2010-04-22 17:40:01 -04:00
|
|
|
|
|
|
|
/* timestr.c */
|
|
|
|
char *get_timestr(time_t, int);
|
1994-08-05 00:24:07 +00:00
|
|
|
|
2010-03-14 19:58:47 -04:00
|
|
|
/* atobool.c */
|
|
|
|
int atobool(const char *str);
|
|
|
|
|
2010-04-22 10:33:16 -04:00
|
|
|
/* boottime.c */
|
|
|
|
int get_boottime(struct timeval *);
|
|
|
|
|
2010-03-27 20:19:40 -04:00
|
|
|
/* iolog.c */
|
2010-05-24 14:30:54 -04:00
|
|
|
void io_nextid(void);
|
2010-03-27 20:19:40 -04:00
|
|
|
|
2010-12-27 12:18:32 -05:00
|
|
|
/* iolog_path.c */
|
|
|
|
char *expand_iolog_path(const char *prefix, const char *opath);
|
|
|
|
|
2010-04-17 13:26:03 -04:00
|
|
|
/* env.c */
|
|
|
|
char **env_get(void);
|
2010-06-08 10:23:35 -04:00
|
|
|
void env_init(char * const envp[]);
|
2010-04-17 13:28:36 -04:00
|
|
|
void init_envtables(void);
|
2010-04-26 17:14:11 -04:00
|
|
|
void insert_env_vars(char * const envp[]);
|
2010-04-17 13:28:36 -04:00
|
|
|
void read_env_file(const char *, int);
|
2010-07-12 17:57:53 -04:00
|
|
|
void rebuild_env(int);
|
2010-04-26 17:14:11 -04:00
|
|
|
void validate_env_vars(char * const envp[]);
|
2010-04-17 13:26:03 -04:00
|
|
|
|
|
|
|
/* fmt_string.c */
|
|
|
|
char *fmt_string(const char *, const char *);
|
|
|
|
|
2010-04-22 17:40:01 -04:00
|
|
|
/* sudoers.c */
|
2010-11-12 13:03:28 -05:00
|
|
|
void plugin_cleanup(int);
|
2010-04-22 17:40:01 -04:00
|
|
|
void set_fqdn(void);
|
|
|
|
FILE *open_sudoers(const char *, int, int *);
|
|
|
|
|
2010-06-29 13:08:05 -04:00
|
|
|
/* aix.c */
|
|
|
|
void aix_restoreauthdb(void);
|
|
|
|
void aix_setauthdb(char *user);
|
|
|
|
|
2010-07-02 11:11:25 -04:00
|
|
|
/* group_plugin.c */
|
|
|
|
int group_plugin_load(char *plugin_info);
|
|
|
|
void group_plugin_unload(void);
|
|
|
|
int group_plugin_query(const char *user, const char *group,
|
|
|
|
const struct passwd *pwd);
|
|
|
|
|
2003-04-02 18:25:30 +00:00
|
|
|
#ifndef _SUDO_MAIN
|
1999-07-22 12:56:28 +00:00
|
|
|
extern struct sudo_user sudo_user;
|
2010-08-21 10:02:50 -04:00
|
|
|
extern struct passwd *list_pw;
|
2008-02-08 13:18:12 +00:00
|
|
|
extern int long_list;
|
2010-07-12 17:57:53 -04:00
|
|
|
extern int sudo_mode;
|
2002-11-22 19:09:49 +00:00
|
|
|
extern uid_t timestamp_uid;
|
2010-03-18 06:42:17 -04:00
|
|
|
extern sudo_conv_t sudo_conv;
|
2010-05-04 19:17:31 -04:00
|
|
|
extern sudo_printf_t sudo_printf;
|
1993-03-02 23:28:50 +00:00
|
|
|
#endif
|
2010-04-22 17:40:01 -04:00
|
|
|
|
|
|
|
/* Some systems don't declare errno in errno.h */
|
2004-02-08 20:53:55 +00:00
|
|
|
#ifndef errno
|
1993-03-02 23:28:50 +00:00
|
|
|
extern int errno;
|
2004-02-08 20:53:55 +00:00
|
|
|
#endif
|
1993-03-02 23:28:50 +00:00
|
|
|
|
2010-03-14 19:58:47 -04:00
|
|
|
#endif /* _SUDO_SUDOERS_H */
|