1 --- sudo-1.6.7p5/sesh.c.selinux 2004-07-08 13:18:28.000000000 -0400
2 +++ sudo-1.6.7p5/sesh.c 2004-07-08 13:18:28.000000000 -0400
7 +#include <sys/types.h>
11 +main (int argc, char **argv) {
15 + fprintf(stderr,"%s: Requires at least one argument\n", argv[0]);
18 + if ( argv[1][0] != '/' ) {
19 + fprintf(stderr,"%s: First argument must have a full path\n", argv[0]);
23 + if ((pid = fork()) < 0) {
24 + snprintf(buf, sizeof(buf), "%s: Couldn't fork");
27 + } else if (pid > 0) {
33 + if ((ret = waitpid(pid, &status, 0)) < 0 && errno == EINTR)
36 + perror("waitpid failed");
41 + if (WIFEXITED(status))
42 + exit(WEXITSTATUS(status));
47 + execv(argv[1], &argv[1]);
49 + snprintf(buf, sizeof(buf), "%s: Error execing %s", argv[0], argv[1]);
54 --- sudo-1.6.9p3/configure.in.orig 2007-07-30 15:30:15.000000000 +0200
55 +++ sudo-1.6.9p3/configure.in 2007-08-04 22:13:39.950053015 +0200
57 dnl Initial values for Makefile variables listed above
58 dnl May be overridden by environment variables..
61 +PROGS="sudo visudo sesh"
64 : ${SUDOERS_MODE='0440'}
65 --- sudo-1.6.9p3/sudo.c.orig 2007-07-22 21:21:01.000000000 +0200
66 +++ sudo-1.6.9p3/sudo.c 2007-08-04 22:15:26.464122906 +0200
68 #include "interfaces.h"
72 +#include <selinux/flask.h> /* for SECCLASS_CHR_FILE */
73 +#include <selinux/selinux.h> /* for is_selinux_enabled() */
74 +#include <selinux/context.h> /* for context-mangling functions */
75 +#include <selinux/get_default_type.h>
76 +char *role_s = NULL; /* role spec'd by user in argv[] */
77 +char *type_s = NULL; /* type spec'd by user in argv[] */
78 +security_context_t new_tty_context=NULL; /* security context to change to while running command*/
79 +security_context_t tty_context=NULL; /* current security context of tty */
83 __unused __unused static const char rcsid[] = "$Sudo: sudo.c,v 1.369.2.26 2007/07/22 19:21:01 millert Exp $";
86 #endif /* HAVE_BSD_AUTH_H */
87 sigaction_t saved_sa_int, saved_sa_quit, saved_sa_tstp, saved_sa_chld;
90 +security_context_t setup_tty_context(int fd, char *ttyn, security_context_t new_context) {
91 + security_context_t tty_context=NULL; /* current sid of tty */
94 + if (fgetfilecon(fd,&tty_context) <0 )
95 + fprintf(stderr, "Warning! Could not get current context for %s, not relabeling.\n", ttyn);
99 + printf("Your tty %s was labeled with context %s\n", ttyn, tty_context);
102 + new_tty_context = NULL;
103 + if (tty_context && security_compute_relabel(new_context,tty_context,SECCLASS_CHR_FILE,&new_tty_context) < 0)
104 + fprintf(stderr, "Warning! Could not get new context for %s, not relabeling.\n", ttyn);
107 + if (new_tty_context)
108 + printf("Relabeling tty %s to context %s\n", ttyn, new_tty_context);
111 + if (new_tty_context) {
112 + if( fsetfilecon(fd,new_tty_context)!=0 ) {
113 + fprintf(stderr,"sudo: error: setfilecon on %s to %s",ttyn,new_tty_context);
116 + return tty_context;
118 +security_context_t get_exec_context(char *role_s, char *type_s) {
120 + security_context_t old_context=NULL; /* our original securiy ID ("old_context") */
121 + security_context_t new_context=NULL; /* our target security ID ("sid") */
125 + * Step 1: Handle command-line arguments.
129 + security_context_t context_s; /* our security context as a string */
130 + int context_length;
131 + context_t context; /* manipulatable form of context_s */
135 + * Get the SID and context of the caller, and extract
136 + * the username from the context. Don't rely on the Linux
137 + * uid information - it isn't trustworthy.
140 + /* Put the caller's SID into `old_context'. */
141 + if( 0!=(getprevcon(&old_context)) ) {
142 + fprintf(stderr,"failed to get old_context.\n");
147 + printf( "Your old context was %s\n", old_context );
150 + * Create a context structure so that we extract and modify
151 + * components easily.
153 + context=context_new(old_context);
157 + * Step 3: Construct a new SID based on our old SID and the
158 + * arguments specified on the command line.
162 + /* The first step in constructing a new SID for the new shell we *
163 + * plan to exec is to take our old context in `context' as a *
164 + * starting point, and modify it according to the options the user *
165 + * specified on the command line. */
167 + /* Set the SELinux user identity to root */
168 + context_user_set(context, "root");
170 + /* If the user specified a new role on the command line (if `role_s' *
171 + * is set), then replace the old role in `context' with this new role. */
174 + if( get_default_type(role_s,&type_s) )
176 + fprintf(stderr,"Couldn't get default type.\n");
180 + printf( "Your type will be %s.\n", type_s );
184 + if( context_role_set(context,role_s)) {
185 + fprintf(stderr,"failed to set new role %s\n",role_s);
189 + printf("Your new role is %s\n",context_role_get(context));
192 + /* If the user specified a new type on the command line (if `type_s' *
193 + * is set), then replace the old type in `context' with this new type. */
195 + if( context_type_set(context,type_s)) {
196 + fprintf(stderr,"failed to set new type %s\n",type_s);
200 + printf("Your new type is %s\n",context_type_get(context));
202 + } /* if user specified new type */
204 + /* The second step in creating the new SID is to convert our modified *
205 + * `context' structure back to a context string and then to a SID. */
207 + /* Make `context_s' point to a string version of the new `context'. */
208 + if( !(new_context=strdup(context_str(context)))) {
209 + fprintf(stderr,"failed to convert new context to string\n" );
213 + } /* if user specified new role */
215 + if (get_default_context(context_user_get(context),
218 + fprintf(stderr,"failed to get default context\n" );
222 + context_free(context);
223 + freecon(old_context);
225 + if (security_check_context(new_context) < 0) {
226 + fprintf(stderr, "%s is not a valid context\n", new_context);
230 + return new_context;
235 main(argc, argv, envp)
238 /* Setup defaults data structures. */
241 - /* Load the list of local ip addresses and netmasks. */
245 if (ISSET(sudo_mode, MODE_SHELL))
248 (void) printf("Sudoers path: %s\n", _PATH_SUDOERS);
251 + /* Load the list of local ip addresses and netmasks. */
258 if (ISSET(sudo_mode, MODE_BACKGROUND) && fork() > 0)
262 + if(is_selinux_enabled() > 0) {
264 + char *ttyn = NULL; /* tty path */
265 + security_context_t new_context=NULL; /* our target security ID ("sid") */
266 + security_context_t chk_tty_context= NULL;
268 + new_context=get_exec_context(role_s,type_s);
270 + printf("Your new context is %s\n",new_context);
273 + if (setexeccon(new_context) < 0) {
274 + fprintf(stderr, "Could not set exec context to %s.\n", new_context);
277 + freecon(new_context);
280 + SELinux will only not transition properly with the following
281 + code. Basically if the user chooses to use a different security
282 + context. We need to start the selinux shell, before executing
283 + the command. This way the process transition will happen
284 + correctly. For example if they user wants to run rpm from
285 + sysadm_r. Sudo will exec the /usr/sbin/sesh followed by the
286 + specified command.*/
287 + char **dst, **src = NewArgv+1;
288 + NewArgv = (char **) emalloc2((++NewArgc + 1), sizeof(char *));
289 + NewArgv[0] = estrdup("sesh");
290 + NewArgv[1] = safe_cmnd;
291 + safe_cmnd = estrdup("/usr/sbin/sesh");
292 + /* copy the args from Argv */
293 + for (dst = NewArgv + 2; (*dst = *src) != NULL; ++src, ++dst)
298 execve(safe_cmnd, NewArgv, environ);
307 + /* Must have an associated SELinux role. */
308 + if (NewArgv[1] == NULL)
311 + role_s = NewArgv[1];
313 + /* Shift Argv over and adjust Argc. */
318 + /* Must have an associated SELinux type. */
319 + if (NewArgv[1] == NULL)
322 + type_s = NewArgv[1];
324 + /* Shift Argv over and adjust Argc. */
329 #ifdef HAVE_LOGIN_CAP_H
331 /* Must have an associated login class. */
332 @@ -1247,6 +1461,9 @@
333 #ifdef HAVE_LOGIN_CAP_H
337 + " [-r role] [-t type]",
340 " [-u username|#uid]",
342 --- sudo-1.6.9p3/sudo.man.in.orig 2007-08-02 17:51:59.000000000 +0200
343 +++ sudo-1.6.9p3/sudo.man.in 2007-08-04 22:17:59.880865627 +0200
345 \&\fBsudo\fR \fB\-h\fR | \fB\-K\fR | \fB\-k\fR | \fB\-L\fR | \fB\-l\fR | \fB\-V\fR | \fB\-v\fR
347 \&\fBsudo\fR [\fB\-bEHPS\fR] [\fB\-a\fR\ \fIauth_type\fR]
348 -[\fB\-c\fR\ \fIclass\fR|\fI\-\fR] [\fB\-p\fR\ \fIprompt\fR] [\fB\-u\fR\ \fIusername\fR|\fI#uid\fR]
349 +[\fB\-c\fR\ \fIclass\fR|\fI\-\fR] [\fB\-r\fR \fIrole\fR ] [\fB\-t\fR \fItype\fR ]
350 +[\fB\-p\fR\ \fIprompt\fR] [\fB\-u\fR\ \fIusername\fR|\fI#uid\fR]
351 [\fB\s-1VAR\s0\fR=\fIvalue\fR] {\fB\-i\fR\ |\ \fB\-s\fR\ |\ \fIcommand\fR}
353 \&\fBsudoedit\fR [\fB\-S\fR] [\fB\-a\fR\ \fIauth_type\fR] [\fB\-c\fR\ \fIclass\fR|\fI\-\fR]
360 +The \fB\-r\fR (\fRrole\fR) option causes the new (SELinux) security context to have the role specified by
364 +The \fB\-t\fR (\fRtype\fR) option causes the new (SELinux) security context to have the have the type (domain)
367 +If no type is specified, the default type is derived from the specified role.
370 The \fB\-S\fR (\fIstdin\fR) option causes \fBsudo\fR to read the password from
371 --- sudo-1.6.9p3/Makefile.in.orig 2007-08-02 17:51:59.000000000 +0200
372 +++ sudo-1.6.9p3/Makefile.in 2007-08-04 22:18:17.657878682 +0200
376 NET_LIBS = @NET_LIBS@
377 -SUDO_LIBS = @SUDO_LIBS@ @AFS_LIBS@ $(LIBS) $(NET_LIBS)
378 +SELINUX_LIBS = -lselinux
379 +SUDO_LIBS = @SUDO_LIBS@ @AFS_LIBS@ $(LIBS) $(NET_LIBS) $(SELINUX_LIBS)
381 # C preprocessor flags
382 CPPFLAGS = -I. -I$(srcdir) @CPPFLAGS@
384 sudoers_mode = @SUDOERS_MODE@
386 # Pass in paths and uid/gid + OS dependent defined
387 -DEFS = @OSDEFS@ -D_PATH_SUDOERS=\"$(sudoersdir)/sudoers\" -D_PATH_SUDOERS_TMP=\"$(sudoersdir)/sudoers.tmp\" -DSUDOERS_UID=$(sudoers_uid) -DSUDOERS_GID=$(sudoers_gid) -DSUDOERS_MODE=$(sudoers_mode)
388 +DEFS = @OSDEFS@ -D_PATH_SUDOERS=\"$(sudoersdir)/sudoers\" -D_PATH_SUDOERS_TMP=\"$(sudoersdir)/sudoers.tmp\" -DSUDOERS_UID=$(sudoers_uid) -DSUDOERS_GID=$(sudoers_gid) -DSUDOERS_MODE=$(sudoers_mode) -DWITH_SELINUX
390 #### End of system configuration section. ####
393 logging.c memrchr.c mkstemp.c parse.c parse.lex parse.yacc set_perms.c \
394 sigaction.c snprintf.c strcasecmp.c strerror.c strlcat.c strlcpy.c \
395 sudo.c sudo_noexec.c sudo.tab.c sudo_edit.c testsudoers.c tgetpass.c \
396 - utimes.c visudo.c zero_bytes.c $(AUTH_SRCS)
397 + utimes.c visudo.c zero_bytes.c $(AUTH_SRCS) sesh.c
399 AUTH_SRCS = auth/afs.c auth/aix_auth.c auth/bsdauth.c auth/dce.c auth/fwtk.c \
400 auth/kerb4.c auth/kerb5.c auth/pam.c auth/passwd.c auth/rfc1938.c \
403 VISUDOBJS = visudo.o fileops.o gettime.o goodpath.o find_path.o $(PARSEOBJS)
407 TESTOBJS = interfaces.o testsudoers.o $(PARSEOBJS)
409 LIBOBJS = @LIBOBJS@ @ALLOCA@
411 BINFILES= BUGS CHANGES HISTORY LICENSE README TODO TROUBLESHOOTING \
412 UPGRADE install-sh mkinstalldirs sample.syslog.conf sample.sudoers \
413 sudo sudo.cat sudo.man sudo.pod sudoers sudoers.cat sudoers.man \
414 - sudoers.pod visudo visudo.cat visudo.man visudo.pod
415 + sudoers.pod visudo visudo.cat visudo.man visudo.pod sesh
417 BINSPECIAL= INSTALL.binary Makefile.binary libtool
420 visudo: $(VISUDOBJS) $(LIBOBJS)
421 $(CC) -o $@ $(VISUDOBJS) $(LIBOBJS) $(LDFLAGS) $(LIBS) $(NET_LIBS)
424 + $(CC) -o $@ $(SESH_OBJS) $(LDFLAGS) $(LIBS)
426 testsudoers: $(TESTOBJS) $(LIBOBJS)
427 $(CC) -o $@ $(TESTOBJS) $(LIBOBJS) $(LDFLAGS) $(LIBS) $(NET_LIBS)
430 set_perms.o: set_perms.c $(SUDODEP)
431 tgetpass.o: tgetpass.c $(SUDODEP)
432 visudo.o: visudo.c $(SUDODEP) version.h
434 sudo.o: sudo.c $(SUDODEP) interfaces.h version.h
435 interfaces.o: interfaces.c $(SUDODEP) interfaces.h
436 testsudoers.o: testsudoers.c $(SUDODEP) parse.h interfaces.h
438 ln $(DESTDIR)$(sudodir)/sudo $(DESTDIR)$(sudodir)/sudoedit
440 $(INSTALL) -O $(install_uid) -G $(install_gid) -M 0111 -s visudo $(DESTDIR)$(visudodir)/visudo
441 + $(INSTALL) -O $(install_uid) -G $(install_gid) -M 0111 -s sesh $(DESTDIR)$(visudodir)/sesh
443 install-noexec: sudo_noexec.la
444 $(LIBTOOL) --mode=install $(INSTALL) sudo_noexec.la $(DESTDIR)$(noexecdir)