/*1* SPDX-License-Identifier: ISC2*3* Copyright (c) 2019-2020, 2023 Todd C. Miller <[email protected]>4*5* Permission to use, copy, modify, and distribute this software for any6* purpose with or without fee is hereby granted, provided that the above7* copyright notice and this permission notice appear in all copies.8*9* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES10* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF11* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR12* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES13* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN14* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF15* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.16*/1718#include <config.h>1920#include <stdio.h>21#include <stdlib.h>22#include <string.h>23#include <unistd.h>24#include <pwd.h>2526#include <sudoers.h>2728/*29* Check whether specified runchroot matches def_runchroot.30* Returns true if matched, false if not matched and -1 on error.31*/32int33check_user_runchroot(const char *runchroot)34{35debug_decl(check_user_runchroot, SUDOERS_DEBUG_AUTH);3637if (runchroot == NULL)38debug_return_bool(true);3940sudo_debug_printf(SUDO_DEBUG_INFO|SUDO_DEBUG_LINENO,41"def_runchroot %s, runchroot %s",42def_runchroot ? def_runchroot : "none", runchroot ? runchroot : "none");4344/* User may only specify a root dir if runchroot is "*" */45if (def_runchroot == NULL || strcmp(def_runchroot, "*") != 0)46debug_return_bool(false);4748free(def_runchroot);49if ((def_runchroot = strdup(runchroot)) == NULL) {50sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));51debug_return_int(-1);52}53debug_return_bool(true);54}5556/*57* Check whether specified runcwd matches def_runcwd.58* Returns true if matched, false if not matched and -1 on error.59*/60int61check_user_runcwd(const char *runcwd)62{63debug_decl(check_user_runcwd, SUDOERS_DEBUG_AUTH);6465if (runcwd == NULL)66debug_return_bool(true);6768sudo_debug_printf(SUDO_DEBUG_INFO|SUDO_DEBUG_LINENO,69"def_runcwd %s, runcwd %s", def_runcwd ? def_runcwd : "none",70runcwd ? runcwd : "none");7172/* User may only specify a cwd if runcwd is "*" */73if (def_runcwd == NULL || strcmp(def_runcwd, "*") != 0)74debug_return_bool(false);7576free(def_runcwd);77if ((def_runcwd = strdup(runcwd)) == NULL) {78sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));79debug_return_int(-1);80}81debug_return_bool(true);82}838485