1993-11-27 23:42:49 +00:00
|
|
|
/*
|
2004-01-05 17:15:32 +00:00
|
|
|
* Copyright (c) 1993-1996,1998-2004 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.
|
|
|
|
*
|
1999-07-22 12:56:28 +00:00
|
|
|
* $Sudo$
|
1993-03-02 23:28:50 +00:00
|
|
|
*/
|
|
|
|
|
1994-11-08 01:39:43 +00:00
|
|
|
#ifndef _SUDO_SUDO_H
|
|
|
|
#define _SUDO_SUDO_H
|
1994-05-25 01:25:40 +00:00
|
|
|
|
1995-11-13 05:16:38 +00:00
|
|
|
#include <pathnames.h>
|
2004-06-01 01:22:27 +00:00
|
|
|
#include <limits.h>
|
1995-01-16 21:35:34 +00:00
|
|
|
#include "compat.h"
|
1999-09-08 08:06:28 +00:00
|
|
|
#include "defaults.h"
|
1999-07-22 12:56:28 +00:00
|
|
|
#include "logging.h"
|
1994-01-27 19:07:34 +00:00
|
|
|
|
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;
|
2004-08-24 18:01:14 +00:00
|
|
|
struct stat *cmnd_stat;
|
2000-12-30 03:29:47 +00:00
|
|
|
char *path;
|
|
|
|
char *shell;
|
1999-07-22 12:56:28 +00:00
|
|
|
char *tty;
|
2004-06-01 01:22:27 +00:00
|
|
|
char cwd[PATH_MAX];
|
1999-07-22 12:56:28 +00:00
|
|
|
char *host;
|
|
|
|
char *shost;
|
1999-09-08 08:06:28 +00:00
|
|
|
char **runas;
|
1999-07-22 12:56:28 +00:00
|
|
|
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;
|
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
|
|
|
|
#define FLAG_NOPASS 0x020
|
|
|
|
#define FLAG_NO_USER 0x040
|
|
|
|
#define FLAG_NO_HOST 0x080
|
|
|
|
#define FLAG_NO_CHECK 0x100
|
2004-01-05 02:48:09 +00:00
|
|
|
#define FLAG_NOEXEC 0x200
|
2004-10-04 16:07:19 +00:00
|
|
|
#define FLAG_MONITOR 0x400
|
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
|
|
|
|
*/
|
|
|
|
#define FOUND 1
|
|
|
|
#define NOT_FOUND 0
|
|
|
|
#define NOT_FOUND_DOT -1
|
1993-03-02 23:28:50 +00:00
|
|
|
|
1995-04-09 21:35:00 +00:00
|
|
|
/*
|
1995-07-31 02:37:47 +00:00
|
|
|
* Various modes sudo can be in (based on arguments) in octal
|
1995-04-09 21:35:00 +00:00
|
|
|
*/
|
2001-12-15 00:24:27 +00:00
|
|
|
#define MODE_RUN 000001
|
|
|
|
#define MODE_VALIDATE 000002
|
|
|
|
#define MODE_INVALIDATE 000004
|
|
|
|
#define MODE_KILL 000010
|
|
|
|
#define MODE_VERSION 000020
|
|
|
|
#define MODE_HELP 000040
|
|
|
|
#define MODE_LIST 000100
|
|
|
|
#define MODE_LISTDEFS 000200
|
|
|
|
#define MODE_BACKGROUND 000400
|
|
|
|
#define MODE_SHELL 001000
|
2004-01-18 22:55:32 +00:00
|
|
|
#define MODE_LOGIN_SHELL 002000
|
|
|
|
#define MODE_IMPLIED_SHELL 004000
|
|
|
|
#define MODE_RESET_HOME 010000
|
|
|
|
#define MODE_PRESERVE_GROUPS 020000
|
2004-01-21 23:00:43 +00:00
|
|
|
#define MODE_EDIT 040000
|
1994-08-05 00:24:07 +00:00
|
|
|
|
1995-04-09 21:35:00 +00:00
|
|
|
/*
|
|
|
|
* Used with set_perms()
|
|
|
|
*/
|
1994-11-10 00:47:51 +00:00
|
|
|
#define PERM_ROOT 0x00
|
2002-01-13 18:28:09 +00:00
|
|
|
#define PERM_FULL_ROOT 0x01
|
|
|
|
#define PERM_USER 0x02
|
2002-01-16 21:27:09 +00:00
|
|
|
#define PERM_FULL_USER 0x03
|
|
|
|
#define PERM_SUDOERS 0x04
|
|
|
|
#define PERM_RUNAS 0x05
|
2004-01-16 23:05:47 +00:00
|
|
|
#define PERM_FULL_RUNAS 0x06
|
|
|
|
#define PERM_TIMESTAMP 0x07
|
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
|
|
|
*/
|
1999-07-22 12:56:28 +00:00
|
|
|
#define user_name (sudo_user.pw->pw_name)
|
|
|
|
#define user_passwd (sudo_user.pw->pw_passwd)
|
|
|
|
#define user_uid (sudo_user.pw->pw_uid)
|
|
|
|
#define user_gid (sudo_user.pw->pw_gid)
|
|
|
|
#define user_dir (sudo_user.pw->pw_dir)
|
2000-12-30 03:29:47 +00:00
|
|
|
#define user_shell (sudo_user.shell)
|
1999-07-22 12:56:28 +00:00
|
|
|
#define user_tty (sudo_user.tty)
|
|
|
|
#define user_cwd (sudo_user.cwd)
|
|
|
|
#define user_runas (sudo_user.runas)
|
|
|
|
#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)
|
|
|
|
#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)
|
1999-02-07 00:43:24 +00:00
|
|
|
|
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
|
|
|
|
|
1999-08-07 09:59:43 +00:00
|
|
|
/*
|
|
|
|
* Flags for lock_file()
|
|
|
|
*/
|
|
|
|
#define SUDO_LOCK 1 /* lock a file */
|
|
|
|
#define SUDO_TLOCK 2 /* test & lock a file (non-blocking) */
|
|
|
|
#define SUDO_UNLOCK 4 /* unlock a file */
|
|
|
|
|
2000-02-27 03:49:07 +00:00
|
|
|
/*
|
|
|
|
* Flags for tgetpass()
|
|
|
|
*/
|
|
|
|
#define TGP_ECHO 0x01 /* leave echo on when reading passwd */
|
|
|
|
#define TGP_STDIN 0x02 /* read from stdin, not /dev/tty */
|
|
|
|
|
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
|
|
|
*/
|
1996-06-20 04:41:55 +00:00
|
|
|
#define YY_DECL int yylex __P((void))
|
1994-05-28 19:13:44 +00:00
|
|
|
|
2004-01-12 19:03:54 +00:00
|
|
|
#ifndef HAVE_CLOSEFROM
|
|
|
|
void closefrom __P((int));
|
|
|
|
#endif
|
1998-09-07 02:51:05 +00:00
|
|
|
#ifndef HAVE_GETCWD
|
|
|
|
char *getcwd __P((char *, size_t size));
|
1994-06-06 00:04:27 +00:00
|
|
|
#endif
|
2004-09-07 17:14:52 +00:00
|
|
|
#ifndef HAVE_UTIMES
|
|
|
|
int utimes __P((const char *, const struct timeval *));
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_FUTIME
|
|
|
|
int futimes __P((int, const struct timeval *));
|
|
|
|
#endif
|
1999-08-12 16:24:10 +00:00
|
|
|
#ifndef HAVE_SNPRINTF
|
|
|
|
int snprintf __P((char *, size_t, const char *, ...));
|
|
|
|
#endif
|
|
|
|
#ifndef HAVE_VSNPRINTF
|
|
|
|
int vsnprintf __P((char *, size_t, const char *, va_list));
|
|
|
|
#endif
|
|
|
|
#ifndef HAVE_ASPRINTF
|
|
|
|
int asprintf __P((char **, const char *, ...));
|
|
|
|
#endif
|
|
|
|
#ifndef HAVE_VASPRINTF
|
|
|
|
int vasprintf __P((char **, const char *, va_list));
|
|
|
|
#endif
|
1999-08-28 09:59:18 +00:00
|
|
|
#ifndef HAVE_STRCASECMP
|
|
|
|
int strcasecmp __P((const char *, const char *));
|
|
|
|
#endif
|
2003-03-13 17:54:04 +00:00
|
|
|
#ifndef HAVE_STRLCAT
|
|
|
|
size_t strlcat __P((char *, const char *, size_t));
|
|
|
|
#endif
|
|
|
|
#ifndef HAVE_STRLCPY
|
|
|
|
size_t strlcpy __P((char *, const char *, size_t));
|
|
|
|
#endif
|
2004-08-24 18:01:14 +00:00
|
|
|
char *sudo_goodpath __P((const char *, struct stat *));
|
1999-07-05 20:14:21 +00:00
|
|
|
char *tgetpass __P((const char *, int, int));
|
2004-08-24 18:01:14 +00:00
|
|
|
int find_path __P((char *, char **, struct stat *, char *));
|
2003-12-30 22:31:30 +00:00
|
|
|
void check_user __P((int));
|
2000-05-09 15:42:38 +00:00
|
|
|
void verify_user __P((struct passwd *, char *));
|
1999-08-01 15:42:12 +00:00
|
|
|
int sudoers_lookup __P((int));
|
2004-10-26 22:23:29 +00:00
|
|
|
int parse_sudoers __P((const char *));
|
2004-02-13 02:08:27 +00:00
|
|
|
#ifdef HAVE_LDAP
|
2004-10-26 22:23:29 +00:00
|
|
|
int sudo_ldap_check __P((VOID *, int));
|
|
|
|
void sudo_ldap_display_privs __P((void));
|
|
|
|
void sudo_ldap_update_defaults __P((VOID *));
|
|
|
|
VOID *sudo_ldap_open __P((void));
|
2004-02-13 02:08:27 +00:00
|
|
|
#endif
|
2004-10-13 16:46:19 +00:00
|
|
|
void set_perms __P((int));
|
1999-07-22 12:56:28 +00:00
|
|
|
void remove_timestamp __P((int));
|
1998-10-18 22:16:10 +00:00
|
|
|
int check_secureware __P((char *));
|
1998-10-19 00:22:38 +00:00
|
|
|
void sia_attempt_auth __P((void));
|
1999-06-03 15:51:07 +00:00
|
|
|
void pam_attempt_auth __P((void));
|
1996-06-20 04:41:55 +00:00
|
|
|
int yyparse __P((void));
|
1998-10-24 23:28:04 +00:00
|
|
|
void pass_warn __P((FILE *));
|
1999-03-29 02:59:34 +00:00
|
|
|
VOID *emalloc __P((size_t));
|
2003-03-12 21:41:22 +00:00
|
|
|
VOID *emalloc2 __P((size_t, size_t));
|
1999-03-29 02:59:34 +00:00
|
|
|
VOID *erealloc __P((VOID *, size_t));
|
2003-03-12 21:51:39 +00:00
|
|
|
VOID *erealloc3 __P((VOID *, size_t, size_t));
|
1999-04-06 17:55:01 +00:00
|
|
|
char *estrdup __P((const char *));
|
2000-05-10 05:11:36 +00:00
|
|
|
int easprintf __P((char **, const char *, ...));
|
|
|
|
int evasprintf __P((char **, const char *, va_list));
|
1999-09-08 08:06:28 +00:00
|
|
|
void dump_defaults __P((void));
|
|
|
|
void dump_auth_methods __P((void));
|
2001-12-11 23:03:24 +00:00
|
|
|
void init_envtables __P((void));
|
1999-08-07 09:59:43 +00:00
|
|
|
int lock_file __P((int, int));
|
2004-09-08 15:48:23 +00:00
|
|
|
int touch __P((int, char *, struct timespec *));
|
2000-02-15 23:36:04 +00:00
|
|
|
int user_is_exempt __P((void));
|
1999-12-02 20:31:25 +00:00
|
|
|
void set_fqdn __P((void));
|
2004-01-16 23:12:03 +00:00
|
|
|
int set_runaspw __P((char *));
|
|
|
|
char *sudo_getepw __P((const struct passwd *));
|
2001-12-31 17:18:05 +00:00
|
|
|
int pam_prep_user __P((struct passwd *));
|
2003-12-31 22:46:08 +00:00
|
|
|
void zero_bytes __P((volatile VOID *, size_t));
|
2004-09-08 15:48:23 +00:00
|
|
|
int gettime __P((struct timespec *));
|
2004-09-29 18:36:33 +00:00
|
|
|
FILE *open_sudoers __P((const char *, int *));
|
2004-10-26 22:23:29 +00:00
|
|
|
void display_privs __P((struct passwd *));
|
2004-09-24 17:17:29 +00:00
|
|
|
#ifdef HAVE_SYSTRACE
|
|
|
|
void systrace_attach __P((pid_t));
|
|
|
|
#endif
|
2004-10-26 22:23:29 +00:00
|
|
|
YY_DECL;
|
1994-08-05 00:24:07 +00:00
|
|
|
|
1999-07-22 12:56:28 +00:00
|
|
|
/* Only provide extern declarations outside of sudo.c. */
|
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;
|
2004-11-11 17:12:20 +00:00
|
|
|
extern struct passwd *auth_pw, *list_pw;
|
1993-03-02 23:28:50 +00:00
|
|
|
|
2000-02-27 03:49:07 +00:00
|
|
|
extern int tgetpass_flags;
|
2002-11-22 19:09:49 +00:00
|
|
|
extern uid_t timestamp_uid;
|
1993-03-02 23:28:50 +00:00
|
|
|
#endif
|
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
|
|
|
|
1994-05-25 01:25:40 +00:00
|
|
|
#endif /* _SUDO_SUDO_H */
|