2010-02-20 09:41:49 -05:00
|
|
|
/*
|
2013-01-11 14:34:09 -05:00
|
|
|
* Copyright (c) 1993-1996, 1998-2005, 2007-2013
|
2010-02-20 09:41:49 -05:00
|
|
|
* 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
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _SUDO_SUDO_H
|
|
|
|
#define _SUDO_SUDO_H
|
|
|
|
|
|
|
|
#include <limits.h>
|
2010-09-07 16:45:19 -04:00
|
|
|
#include <pathnames.h>
|
2011-12-02 11:27:33 -05:00
|
|
|
#ifdef HAVE_STDBOOL_H
|
|
|
|
# include <stdbool.h>
|
|
|
|
#else
|
|
|
|
# include "compat/stdbool.h"
|
|
|
|
#endif /* HAVE_STDBOOL_H */
|
2011-05-16 16:37:11 -04:00
|
|
|
|
2010-09-07 16:45:19 -04:00
|
|
|
#include "missing.h"
|
|
|
|
#include "alloc.h"
|
2013-08-15 14:24:29 -06:00
|
|
|
#include "fatal.h"
|
2010-09-07 16:45:19 -04:00
|
|
|
#include "fileops.h"
|
2011-12-20 13:39:19 -05:00
|
|
|
#include "sudo_conf.h"
|
2011-10-22 14:40:21 -04:00
|
|
|
#include "sudo_debug.h"
|
2013-12-12 18:29:07 -07:00
|
|
|
#include "sudo_util.h"
|
2011-05-20 11:48:17 -04:00
|
|
|
#include "gettext.h"
|
2010-02-20 09:41:49 -05:00
|
|
|
|
2012-07-26 13:49:21 -04:00
|
|
|
#ifdef HAVE_PRIV_SET
|
|
|
|
# include <priv.h>
|
|
|
|
#endif
|
|
|
|
|
2010-02-20 09:41:49 -05:00
|
|
|
#ifdef __TANDEM
|
2012-11-13 08:54:31 -05:00
|
|
|
# define ROOT_UID 65535
|
2010-02-20 09:41:49 -05:00
|
|
|
#else
|
2012-11-13 08:54:31 -05:00
|
|
|
# define ROOT_UID 0
|
2010-02-20 09:41:49 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Various modes sudo can be in (based on arguments) in hex
|
|
|
|
*/
|
|
|
|
#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_MASK 0x0000ffff
|
|
|
|
|
|
|
|
/* Mode flags */
|
|
|
|
/* XXX - prune this */
|
|
|
|
#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
|
|
|
|
#define MODE_LONG_LIST 0x01000000
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Flags for tgetpass()
|
|
|
|
*/
|
2010-06-10 15:02:32 -04:00
|
|
|
#define TGP_NOECHO 0x00 /* turn echo off reading pw (default) */
|
2010-02-20 09:41:49 -05:00
|
|
|
#define TGP_ECHO 0x01 /* leave echo on when reading passwd */
|
|
|
|
#define TGP_STDIN 0x02 /* read from stdin, not /dev/tty */
|
|
|
|
#define TGP_ASKPASS 0x04 /* read from askpass helper program */
|
2010-06-09 10:31:05 -04:00
|
|
|
#define TGP_MASK 0x08 /* mask user input when reading */
|
2010-06-10 15:02:32 -04:00
|
|
|
#define TGP_NOECHO_TRY 0x10 /* turn off echo if possible */
|
2010-02-20 09:41:49 -05:00
|
|
|
|
|
|
|
struct user_details {
|
2012-04-13 15:18:40 -04:00
|
|
|
pid_t pid;
|
|
|
|
pid_t ppid;
|
|
|
|
pid_t pgid;
|
|
|
|
pid_t tcpgid;
|
|
|
|
pid_t sid;
|
2010-02-20 09:41:49 -05:00
|
|
|
uid_t uid;
|
|
|
|
uid_t euid;
|
|
|
|
uid_t gid;
|
|
|
|
uid_t egid;
|
|
|
|
const char *username;
|
|
|
|
const char *cwd;
|
|
|
|
const char *tty;
|
|
|
|
const char *host;
|
2010-03-21 08:54:06 -04:00
|
|
|
const char *shell;
|
2010-02-20 09:41:49 -05:00
|
|
|
GETGROUPS_T *groups;
|
|
|
|
int ngroups;
|
2010-03-17 10:36:02 -04:00
|
|
|
int ts_cols;
|
|
|
|
int ts_lines;
|
2010-02-20 09:41:49 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#define CD_SET_UID 0x0001
|
|
|
|
#define CD_SET_EUID 0x0002
|
|
|
|
#define CD_SET_GID 0x0004
|
|
|
|
#define CD_SET_EGID 0x0008
|
|
|
|
#define CD_PRESERVE_GROUPS 0x0010
|
|
|
|
#define CD_NOEXEC 0x0020
|
|
|
|
#define CD_SET_PRIORITY 0x0040
|
|
|
|
#define CD_SET_UMASK 0x0080
|
|
|
|
#define CD_SET_TIMEOUT 0x0100
|
2010-05-16 19:27:04 -04:00
|
|
|
#define CD_SUDOEDIT 0x0200
|
2010-06-09 16:19:45 -04:00
|
|
|
#define CD_BACKGROUND 0x0400
|
2010-06-09 16:25:44 -04:00
|
|
|
#define CD_RBAC_ENABLED 0x0800
|
2010-12-20 16:27:46 -05:00
|
|
|
#define CD_USE_PTY 0x1000
|
2011-03-15 15:53:49 -04:00
|
|
|
#define CD_SET_UTMP 0x2000
|
2013-01-11 14:34:09 -05:00
|
|
|
#define CD_EXEC_BG 0x4000
|
2010-02-20 09:41:49 -05:00
|
|
|
|
|
|
|
struct command_details {
|
|
|
|
uid_t uid;
|
|
|
|
uid_t euid;
|
|
|
|
gid_t gid;
|
|
|
|
gid_t egid;
|
|
|
|
mode_t umask;
|
|
|
|
int priority;
|
|
|
|
int timeout;
|
|
|
|
int ngroups;
|
2010-05-24 15:40:36 -04:00
|
|
|
int closefrom;
|
2010-06-09 16:25:44 -04:00
|
|
|
int flags;
|
2012-04-21 13:37:46 -04:00
|
|
|
struct passwd *pw;
|
2010-02-20 09:41:49 -05:00
|
|
|
GETGROUPS_T *groups;
|
|
|
|
const char *command;
|
|
|
|
const char *cwd;
|
|
|
|
const char *login_class;
|
|
|
|
const char *chroot;
|
|
|
|
const char *selinux_role;
|
|
|
|
const char *selinux_type;
|
2011-03-15 15:53:49 -04:00
|
|
|
const char *utmp_user;
|
2011-03-10 14:24:10 -05:00
|
|
|
char **argv;
|
|
|
|
char **envp;
|
2012-07-26 13:49:21 -04:00
|
|
|
#ifdef HAVE_PRIV_SET
|
|
|
|
priv_set_t *privs;
|
|
|
|
priv_set_t *limitprivs;
|
|
|
|
#endif
|
2010-02-20 09:41:49 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Status passed between parent and child via socketpair */
|
|
|
|
struct command_status {
|
|
|
|
#define CMD_INVALID 0
|
|
|
|
#define CMD_ERRNO 1
|
|
|
|
#define CMD_WSTATUS 2
|
|
|
|
#define CMD_SIGNO 3
|
2012-08-06 14:38:35 -04:00
|
|
|
#define CMD_PID 4
|
2010-02-20 09:41:49 -05:00
|
|
|
int type;
|
|
|
|
int val;
|
|
|
|
};
|
|
|
|
|
2010-06-16 16:46:56 -04:00
|
|
|
struct timeval;
|
|
|
|
|
2013-04-26 16:06:05 -04:00
|
|
|
/* For fatal() and fatalx() (XXX - needed?) */
|
2010-02-20 09:41:49 -05:00
|
|
|
void cleanup(int);
|
|
|
|
|
|
|
|
/* tgetpass.c */
|
|
|
|
char *tgetpass(const char *, int, int);
|
|
|
|
int tty_present(void);
|
|
|
|
|
2010-05-27 16:46:31 -04:00
|
|
|
/* exec.c */
|
2013-01-17 09:20:45 -05:00
|
|
|
int pipe_nonblock(int fds[2]);
|
2012-01-25 14:58:02 -05:00
|
|
|
int sudo_execute(struct command_details *details, struct command_status *cstat);
|
2010-02-20 09:41:49 -05:00
|
|
|
|
|
|
|
/* parse_args.c */
|
|
|
|
int parse_args(int argc, char **argv, int *nargc, char ***nargv,
|
|
|
|
char ***settingsp, char ***env_addp);
|
2010-06-15 15:01:11 -04:00
|
|
|
extern int tgetpass_flags;
|
2010-02-20 09:41:49 -05:00
|
|
|
|
2010-06-07 18:06:22 -04:00
|
|
|
/* get_pty.c */
|
2010-02-20 09:41:49 -05:00
|
|
|
int get_pty(int *master, int *slave, char *name, size_t namesz, uid_t uid);
|
|
|
|
|
|
|
|
/* sudo.c */
|
2011-12-02 11:27:33 -05:00
|
|
|
bool exec_setup(struct command_details *details, const char *ptyname, int ptyfd);
|
2012-04-23 16:38:16 -04:00
|
|
|
int policy_init_session(struct command_details *details);
|
2011-03-10 14:24:10 -05:00
|
|
|
int run_command(struct command_details *details);
|
2012-11-11 07:11:22 -05:00
|
|
|
int os_init_common(int argc, char *argv[], char *envp[]);
|
2013-07-16 14:04:23 -06:00
|
|
|
extern const char *list_user;
|
2010-06-15 15:01:11 -04:00
|
|
|
extern struct user_details user_details;
|
2010-02-20 09:41:49 -05:00
|
|
|
|
2010-05-13 14:09:21 -04:00
|
|
|
/* sudo_edit.c */
|
2011-03-10 14:24:10 -05:00
|
|
|
int sudo_edit(struct command_details *details);
|
2010-05-13 14:09:21 -04:00
|
|
|
|
2010-03-21 08:54:06 -04:00
|
|
|
/* parse_args.c */
|
2011-02-21 11:33:36 -05:00
|
|
|
void usage(int);
|
2010-03-21 08:54:06 -04:00
|
|
|
|
2012-11-11 07:11:22 -05:00
|
|
|
/* openbsd.c */
|
|
|
|
int os_init_openbsd(int argc, char *argv[], char *envp[]);
|
|
|
|
|
2010-05-24 18:18:50 -04:00
|
|
|
/* selinux.c */
|
2010-05-25 11:00:39 -04:00
|
|
|
int selinux_restore_tty(void);
|
2010-06-08 17:59:18 -04:00
|
|
|
int selinux_setup(const char *role, const char *type, const char *ttyn,
|
|
|
|
int ttyfd);
|
2012-01-25 14:58:02 -05:00
|
|
|
void selinux_execve(const char *path, char *const argv[], char *const envp[],
|
|
|
|
int noexec);
|
2010-05-24 18:18:50 -04:00
|
|
|
|
2012-11-11 07:11:22 -05:00
|
|
|
/* solaris.c */
|
|
|
|
void set_project(struct passwd *);
|
|
|
|
int os_init_solaris(int argc, char *argv[], char *envp[]);
|
|
|
|
|
2012-03-07 16:35:42 -05:00
|
|
|
/* hooks.c */
|
|
|
|
/* XXX - move to sudo_plugin_int.h? */
|
|
|
|
struct sudo_hook;
|
|
|
|
int register_hook(struct sudo_hook *hook);
|
|
|
|
int deregister_hook(struct sudo_hook *hook);
|
|
|
|
int process_hooks_getenv(const char *name, char **val);
|
|
|
|
int process_hooks_setenv(const char *name, const char *value, int overwrite);
|
|
|
|
int process_hooks_putenv(char *string);
|
|
|
|
int process_hooks_unsetenv(const char *name);
|
|
|
|
|
2012-05-27 12:48:55 -04:00
|
|
|
/* env_hooks.c */
|
|
|
|
char *getenv_unhooked(const char *name);
|
|
|
|
|
2010-09-08 14:20:11 -04:00
|
|
|
/* interfaces.c */
|
|
|
|
int get_net_ifs(char **addrinfo);
|
|
|
|
|
2012-01-13 06:01:58 -05:00
|
|
|
/* ttyname.c */
|
|
|
|
char *get_process_ttyname(void);
|
|
|
|
|
2013-01-17 13:29:46 -05:00
|
|
|
/* signal.c */
|
|
|
|
struct sigaction;
|
|
|
|
extern int signal_pipe[2];
|
2013-01-19 15:10:01 -05:00
|
|
|
int sudo_sigaction(int signo, struct sigaction *sa, struct sigaction *osa);
|
2013-01-17 13:29:46 -05:00
|
|
|
void init_signals(void);
|
|
|
|
void restore_signals(void);
|
|
|
|
void save_signals(void);
|
|
|
|
|
2013-11-22 16:35:15 -07:00
|
|
|
/* preload.c */
|
|
|
|
void preload_static_symbols(void);
|
|
|
|
|
2010-02-20 09:41:49 -05:00
|
|
|
#endif /* _SUDO_SUDO_H */
|