Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sudo-project
GitHub Repository: sudo-project/sudo
Path: blob/main/plugins/sudoers/check_util.c
1532 views
1
/*
2
* SPDX-License-Identifier: ISC
3
*
4
* Copyright (c) 2019-2020, 2023 Todd C. Miller <[email protected]>
5
*
6
* Permission to use, copy, modify, and distribute this software for any
7
* purpose with or without fee is hereby granted, provided that the above
8
* copyright notice and this permission notice appear in all copies.
9
*
10
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
*/
18
19
#include <config.h>
20
21
#include <stdio.h>
22
#include <stdlib.h>
23
#include <string.h>
24
#include <unistd.h>
25
#include <pwd.h>
26
27
#include <sudoers.h>
28
29
/*
30
* Check whether specified runchroot matches def_runchroot.
31
* Returns true if matched, false if not matched and -1 on error.
32
*/
33
int
34
check_user_runchroot(const char *runchroot)
35
{
36
debug_decl(check_user_runchroot, SUDOERS_DEBUG_AUTH);
37
38
if (runchroot == NULL)
39
debug_return_bool(true);
40
41
sudo_debug_printf(SUDO_DEBUG_INFO|SUDO_DEBUG_LINENO,
42
"def_runchroot %s, runchroot %s",
43
def_runchroot ? def_runchroot : "none", runchroot ? runchroot : "none");
44
45
/* User may only specify a root dir if runchroot is "*" */
46
if (def_runchroot == NULL || strcmp(def_runchroot, "*") != 0)
47
debug_return_bool(false);
48
49
free(def_runchroot);
50
if ((def_runchroot = strdup(runchroot)) == NULL) {
51
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
52
debug_return_int(-1);
53
}
54
debug_return_bool(true);
55
}
56
57
/*
58
* Check whether specified runcwd matches def_runcwd.
59
* Returns true if matched, false if not matched and -1 on error.
60
*/
61
int
62
check_user_runcwd(const char *runcwd)
63
{
64
debug_decl(check_user_runcwd, SUDOERS_DEBUG_AUTH);
65
66
if (runcwd == NULL)
67
debug_return_bool(true);
68
69
sudo_debug_printf(SUDO_DEBUG_INFO|SUDO_DEBUG_LINENO,
70
"def_runcwd %s, runcwd %s", def_runcwd ? def_runcwd : "none",
71
runcwd ? runcwd : "none");
72
73
/* User may only specify a cwd if runcwd is "*" */
74
if (def_runcwd == NULL || strcmp(def_runcwd, "*") != 0)
75
debug_return_bool(false);
76
77
free(def_runcwd);
78
if ((def_runcwd = strdup(runcwd)) == NULL) {
79
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
80
debug_return_int(-1);
81
}
82
debug_return_bool(true);
83
}
84
85