Commit graph

50 commits

Author SHA1 Message Date
Sebastian Pipping b884d88626 Fix compilation on Linux
Symptom with GCC 11:
> gcc-11 -std=c99 -Wextra -pedantic -Wall -O2 -DUSE_PAM -DDOAS_CONF=\"/etc/doas.conf\"  -D_GNU_SOURCE -include compat/compat.h -Icompat  -c -o env.o env.c
> env.c: In function ‘createenv’:
> env.c:139:37: error: conflicting types for ‘environ’; have ‘const char **’
>   139 |                 extern const char **environ;
>       |                                     ^~~~~~~

Symptom with Clang 17:
> clang-17 -std=c99 -Wextra -pedantic -Wall -O2 -DUSE_PAM -DDOAS_CONF=\"/etc/doas.conf\"  -D_GNU_SOURCE -include compat/compat.h -Icompat  -c -o env.o env.c
> env.c:139:23: error: redeclaration of 'environ' with a different type: 'const char **' vs 'char **'
>                 extern const char **environ;
>                                     ^

Related:
https://sourceforge.net/p/predef/wiki/OperatingSystems/#linux-kernel
2023-03-16 22:06:49 +01:00
helmat ad8690ae38
remove obsolete initialization
This initializer is obsolete as targetname is initialized just prior the while loop and not touched elsewhere within the loop.
2022-09-21 07:30:04 +02:00
Jesse 421af927d1 Merge branch 'master' of https://github.com/slicer69/doas 2022-09-14 10:09:45 -03:00
Jesse 065bafc49d Merge branch 'master' of https://github.com/slicer69/doas 2022-09-14 10:07:00 -03:00
helmat f121a2e063
Correct initializer - targetname[0] is access even when no 'u' option is given 2022-09-14 10:00:06 +02:00
Jesse 5d84815124 Adjust doas to look up target shell information basedon
on username instead of numeric UID. This makes using
doas smoother on systems like FreeBSD where it's common
to have multiple usernames for UID 0 (zero).
Thanks to helmat for the patch.
2022-09-12 17:15:40 -03:00
helmat 09570c7044
Update doas.c 2022-09-09 12:55:29 +02:00
Lucas Holt 5e7dab5420 Add MidnightBSD support. 2021-09-13 15:56:17 -04:00
Jesse Smith 557138f0a6 Minor code cleanup to avoid duplication of function call. 2021-06-05 13:06:17 -03:00
Jesse Smith 014d8655fe Revert keeping LANG variable of original user when switching to
another user. LANG is not kept unless explicitly passed in the doas.conf file.
2021-06-03 11:47:42 -03:00
Jesse Smith 3f2e8fc591 Made a small change to the way setusercontext is handled. Environment
variables (like LANG) are set from the target user when logins are simulated with the -S flag.
However, login.conf environment variables of the target user are not set
when -S is not specified so we keep the calling user's language/environment
for most things.
2021-06-01 22:54:57 -03:00
Jesse Smith c70338eefd When performing a login (-S flag) the target user's language settings are
applied from login.conf. Otherwise the original user's language is carried over.
2021-06-01 20:47:12 -03:00
Jesse Smith ab3ae5ad41 On FreeBSD limits set by the user's class (in /etc/login.conf) would
not be respected when running doas. The default class would always
be used, ignoring both the classing class and the target user's class.

This came about because FreeBSD has a "class" field in the password
structure, but other supported systems like Linux do not. doas.c and
env.c have been patched to support FreeBSD's class field in the password
structure. Login class limits are now respected.
2021-05-30 12:27:44 -03:00
Jesse Smith 91622fcbb1 Added the "nolog" configuration file flag which allows specified
users to perform commands without successful commands being
logged to syslogd.

Added documentation to doas.conf manual page and doas.conf.sample
files to include tips and and example of the "nolog" flag in action.

The "nolog" flag is a feature of OpenBSD's doas command and has
been introduced for compatibility and as an optional way to avoid
filling up system logs with successful doas calls.
2021-01-27 22:43:22 -04:00
Jesse Smith 04b377f6fd On Linux doas no longer requires the user to specify the double-dash (--)
prior to a command that accepts arguments. Patch provided by Martijn
van Duren.
2020-08-06 15:17:09 -03:00
helmat 93a56843e4
Update doas.c 2020-06-21 15:29:37 +02:00
Jesse Smith a006f46031 On some platforms (seemingly Linux and macOS) it is possible for
repeated calls to getpwuid() can over-write the original struct passwd
strucuture. This can lead to the original user's environment data
being overwritten by the target user's, even when "keepenv" is
specified in the doas.conf file.

We now do a deep copy of the original and target users' struct passwd
information to avoid over-writting the original on platforms where libc
uses a static area for all calls.
2019-12-27 22:10:57 -04:00
Jesse Smith 705dd9ce24 Reorganized compatibility code and Makefile.
- amalleo25
Provided cleaner fix for crash when user/command has
no valid match in the doas.conf file.
- amalleo25
Removed option to match UID with -u flag. Provided
usernames must now match a username, not UID. This was
ambigious if a user had a numeric username.
- Jesse
2019-09-10 13:56:32 -03:00
Jesse Smith 7007ce8ebd Fixed potential crash on Linux when target user is not
one of the valid users listed in doas.conf.
2019-09-03 17:36:04 -03:00
Jesse Smith 1c2858c681 Removed unused login_style variable on Linux. Is only
used when using BSD authorization.
2019-09-03 11:52:15 -03:00
Jesse Smith 2f83222829 Added optimization to Makefile (can be set/overruled using OPT).
Added flag to display all warnings during compiling.
Added status checks when parsing user/group IDs for Linux.
Make sure Linux drops original user's groups when running as another user.
2019-09-03 11:42:27 -03:00
Duncan Overbruck 6cf0236184 fix the setusercontext(3) workaround
Seeing this being used on even more system like Illumos with this ugly
and security critical bug open makes me cringe every time I check if it
was finally fixed.

I reported it directly to the maintainer in 2017. I reported it to
pkgsrc-security@netbsd.org without a response.
2019-09-03 02:45:20 +02:00
Adam Malleo 9c53fdeb0b Add support for illumos 2019-09-02 12:37:58 -04:00
Jesse Smith 8e9c2bde06 Removed the transfer of most environment variables, such as USER, HOME,
and PATH from the original user to the target user. This could cause
files in the wrogn path or home directory to be read (or written to),
which resulted in potential security problems.

This has been changed so that only DISPLAY and TERM are passed to the
new environment. This is fine for running command line programs. When
GUI programs need to be run, "keepenv" can be added to the user's
doas.conf entry. This results in variables like HOME being copied
to the target user, allowing GUI programs to run.

Many thanks to Sander Bos for reporting this issue and explaining
how it can be exploited.

This commit also adds the ability to pass a customized PATH to
target users. The new PATH can be set at compile time in the
Makefile. The default path is provided in the Makefile and commented
out.
2019-08-03 17:39:15 -03:00
Jesse Smith b96ddd6c3f Fix format warning from Clang compiler. 2019-07-06 14:23:38 -03:00
Jesse Smith 1f76dd9515 Enabled doas to compile and run on NetBSD 8.1. 2019-06-24 19:15:03 -03:00
Jesse Smith fd79e385d7 Minor fixes to avoid compiling error on FreeBSD following Linux fixes. 2019-03-10 19:22:09 -03:00
Jesse Smith c8cb4d999e Avoid echoing stdin when output is piped to doas.
Fix asprintf() compile warning when building on Linux.
2019-03-10 19:11:40 -03:00
Jesse Smith fe6d3a342b Updated doas.c with patch from arthepsy. Fixes -n flag
so if a password prompt is required, doas will automatically fail.
2017-10-11 10:32:20 -03:00
Jesse Smith 4bd6c1c178 Fixed issue with port of doas searching the user's full path for
commands matching the "cmd" parameter in doas.conf. The path
should be shortened to system-standard paths. This prevents
the user from injecting their own application with a familiar
name in their PATH variable and tricking doas into running it.
2017-09-05 21:40:47 -03:00
Jesse Smith 261c216449 Updated license file.
Fixes potential buffer overflow on Linux systems. (Thanks to Duncaen for pointing out the issue.)
2017-02-24 10:46:46 -04:00
katakk 453102110a Merge, update from OpenBSD 2017-01-24 01:12:56 +09:00
Tobias Kortkamp 7ab94a448a Restore old behavior on Linux which was broken by the last commit
Small change in the Makefile so doas compiles on Ubuntu 16.04
2016-11-03 21:28:20 +01:00
Tobias Kortkamp dbfba4e976 Workaround for issue #3: hide stdin from openpam_ttyconv
openpam_ttyconv checks if stdin is a terminal and if it is then does
not bother to open /dev/tty.  The result is that PAM writes the
password prompt directly to stdout.  In scenarios where stdin is a
terminal, but stdout is redirected to a file e.g. by running doas ls
&> ls.out interactively, the password prompt gets written to ls.out as
well.  By closing stdin first we forces PAM to read/write to/from the
terminal directly.  We restore stdin after authenticating.

Also see https://github.com/freebsd/freebsd/blob/master/contrib/openpam/lib/libpam/openpam_ttyconv.c#L293
2016-11-03 12:04:18 +01:00
Tobias Kortkamp 08dab0cd9c Use setusercontext on FreeBSD and get rid of the geteuid/setuid workaround 2016-09-17 02:15:40 +02:00
Jesse Smith 8bec4dcaa6 Fixed bug which prevented the -u flag from switching to
the specified user on FreeBSD when the option was permitted
in the doas.conf file.
2016-08-06 17:31:52 -03:00
Jesse dc0fb3212d When the user is allowed to run commands without a password (ie nopass has
been set in the doas.conf file) then we do not need to redirect a password
prompt to stderr. This patch makes sure output is displayed properly
when the user authenticates with "nopass" set.
2016-07-05 19:45:40 +00:00
Jesse Smith 1a3589f137 Minor clean up of pre-compiler directive that was broken by merge. 2016-06-26 16:40:31 -03:00
Jesse Smith 76f082bed7 cleared up merge errors in doas.c 2016-06-26 16:38:44 -03:00
Jesse Smith 24705b6558 Merge work from branch 'linux' 2016-06-26 16:37:25 -03:00
Jesse Smith 4b32171218 Made sure when running as the effective user root (euid is zero) we actually become
uid 0 in order to avoid file system permission errors/restrictions.
2016-06-26 16:24:42 -03:00
Jesse Smith 47b4ab919a Linux port now compiles and runs. Properly authenticates. 2016-06-26 14:34:33 -03:00
Jesse Smith 304ddb0f5a Minor update to Linux port. 2016-06-26 14:07:06 -03:00
Jesse Smith 14ea837825 Imported hiding password prompt into Linux branch. 2016-06-26 11:45:58 -03:00
Jesse Smith cdf69cb5f5 This commit allows doas to compile on Linux. Does not authenticate yet. 2016-06-26 11:41:31 -03:00
Jesse cef2929df3 Force PAM to display password prompt on stderr instead of stdout. This makes
it possible to redirect command output to a file/pipe without including the doas
password prompt in the output.
2016-06-25 18:32:20 +00:00
Jesse Smith 720db72121 Try to bail out if permitted user suppleis incorrect password. 2016-06-24 16:01:35 -03:00
Tobias Kortkamp aea70ce4ea Apply patches from security/doas port 2016-06-24 13:42:00 +02:00
Jesse Smith d55af6cdf4 This is the initial port of doas to FreeBSD. It compiles, installs and works.
Could probably use a clean-up, but this code is functional on FreeBSD 10.3.
2016-06-22 12:21:34 -03:00
Jesse Smith cb8d475985 Initial upload from OpenBSD
This is the initial upload from OpenBSD. Kept for history and comparision with future releases.
2016-06-22 12:17:53 -03:00