/*1* SPDX-License-Identifier: ISC2*3* Copyright (c) 1996, 1998-2005, 2010-2012, 2014-20154* Todd C. Miller <[email protected]>5*6* Permission to use, copy, modify, and distribute this software for any7* purpose with or without fee is hereby granted, provided that the above8* copyright notice and this permission notice appear in all copies.9*10* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES11* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF12* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR13* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES14* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN15* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF16* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.17*18* Sponsored in part by the Defense Advanced Research Projects19* Agency (DARPA) and Air Force Research Laboratory, Air Force20* Materiel Command, USAF, under agreement number F39502-99-1-0512.21*/2223/*24* The code below basically comes from the examples supplied on25* the OSF DCE 1.0.3 manpages for the sec_login routines, with26* enough additional polishing to make the routine work with the27* rest of sudo.28*29* This code is known to work on HP 700 and 800 series systems30* running HP-UX 9.X and 10.X, with either HP's version 1.2.1 of DCE.31* (aka, OSF DCE 1.0.3) or with HP's version 1.4 of DCE (aka, OSF32* DCE 1.1).33*/3435#include <config.h>3637#ifdef HAVE_DCE3839#include <sys/types.h>40#include <stdio.h>41#include <stdlib.h>42#include <string.h>43#include <unistd.h>44#include <pwd.h>4546#include <dce/rpc.h>47#include <dce/sec_login.h>48#include <dce/dce_error.h> /* required to call dce_error_inq_text routine */4950#include <sudoers.h>51#include "sudo_auth.h"52#include <timestamp.h>5354static int check_dce_status(error_status_t, char *);5556int57sudo_dce_verify(const struct sudoers_context *ctx, struct passwd *pw,58const char *plain_pw, sudo_auth *auth, struct sudo_conv_callback *callback)59{60struct passwd temp_pw;61sec_passwd_rec_t password_rec;62sec_login_handle_t login_context;63boolean32 reset_passwd;64sec_login_auth_src_t auth_src;65error_status_t status;66debug_decl(sudo_dce_verify, SUDOERS_DEBUG_AUTH);6768if (IS_NONINTERACTIVE(auth))69debug_return_int(AUTH_NONINTERACTIVE);7071/* Display lecture if needed and we haven't already done so. */72display_lecture(callback);7374/*75* Create the local context of the DCE principal necessary76* to perform authenticated network operations. The network77* identity set up by this operation cannot be used until it78* is validated via sec_login_validate_identity().79*/80if (sec_login_setup_identity((unsigned_char_p_t) pw->pw_name,81sec_login_no_flags, &login_context, &status)) {8283if (check_dce_status(status, "sec_login_setup_identity(1):"))84debug_return_int(AUTH_FAILURE);8586password_rec.key.key_type = sec_passwd_plain;87password_rec.key.tagged_union.plain = (idl_char *) plain_pw;88password_rec.pepper = NULL;89password_rec.version_number = sec_passwd_c_version_none;9091/* Validate the login context with the password */92if (sec_login_validate_identity(login_context, &password_rec,93&reset_passwd, &auth_src, &status)) {9495if (check_dce_status(status, "sec_login_validate_identity(1):"))96debug_return_int(AUTH_FAILURE);9798/*99* Certify that the DCE Security Server used to set100* up and validate a login context is legitimate. Makes101* sure that we didn't get spoofed by another DCE server.102*/103if (!sec_login_certify_identity(login_context, &status)) {104sudo_printf(SUDO_CONV_ERROR_MSG|SUDO_CONV_PREFER_TTY,105"Whoa! Bogus authentication server!\n");106(void) check_dce_status(status,"sec_login_certify_identity(1):");107debug_return_int(AUTH_FAILURE);108}109if (check_dce_status(status, "sec_login_certify_identity(2):"))110debug_return_int(AUTH_FAILURE);111112/*113* Sets the network credentials to those specified114* by the now validated login context.115*/116sec_login_set_context(login_context, &status);117if (check_dce_status(status, "sec_login_set_context:"))118debug_return_int(AUTH_FAILURE);119120/*121* Oops, your credentials were no good. Possibly122* caused by clock times out of adjustment between123* DCE client and DCE security server...124*/125if (auth_src != sec_login_auth_src_network) {126sudo_printf(SUDO_CONV_ERROR_MSG|SUDO_CONV_PREFER_TTY,127"You have no network credentials.\n");128debug_return_int(AUTH_FAILURE);129}130/* Check if the password has aged and is thus no good */131if (reset_passwd) {132sudo_printf(SUDO_CONV_ERROR_MSG|SUDO_CONV_PREFER_TTY,133"Your DCE password needs resetting.\n");134debug_return_int(AUTH_FAILURE);135}136137/*138* We should be a valid user by this point. Pull the139* user's password structure from the DCE security140* server just to make sure. If we get it with no141* problems, then we really are legitimate...142*/143sec_login_get_pwent(login_context, (sec_login_passwd_t) &temp_pw,144&status);145if (check_dce_status(status, "sec_login_get_pwent:"))146debug_return_int(AUTH_FAILURE);147148/*149* If we get to here, then the pwent above properly fetched150* the password structure from the DCE registry, so the user151* must be valid. We don't really care what the user's152* registry password is, just that the user could be153* validated. In fact, if we tried to compare the local154* password to the DCE entry at this point, the operation155* would fail if the hidden password feature is turned on,156* because the password field would contain an asterisk.157* Also go ahead and destroy the user's DCE login context158* before we leave here (and don't bother checking the159* status), in order to clean up credentials files in160* /opt/dcelocal/var/security/creds. By doing this, we are161* assuming that the user will not need DCE authentication162* later in the program, only local authentication. If this163* is not true, then the login_context will have to be164* returned to the calling program, and the context purged165* somewhere later in the program.166*/167sec_login_purge_context(&login_context, &status);168debug_return_int(AUTH_SUCCESS);169} else {170if(check_dce_status(status, "sec_login_validate_identity(2):"))171debug_return_int(AUTH_FAILURE);172sec_login_purge_context(&login_context, &status);173if(check_dce_status(status, "sec_login_purge_context:"))174debug_return_int(AUTH_FAILURE);175}176}177(void) check_dce_status(status, "sec_login_setup_identity(2):");178debug_return_int(AUTH_FAILURE);179}180181/* Returns 0 for DCE "ok" status, 1 otherwise */182static int183check_dce_status(error_status_t input_status, char *comment)184{185int error_stat;186unsigned char error_string[dce_c_error_string_len];187debug_decl(check_dce_status, SUDOERS_DEBUG_AUTH);188189if (input_status == rpc_s_ok)190debug_return_int(0);191dce_error_inq_text(input_status, error_string, &error_stat);192sudo_printf(SUDO_CONV_ERROR_MSG|SUDO_CONV_PREFER_TTY,193"%s %s\n", comment, error_string);194debug_return_int(1);195}196197#endif /* HAVE_DCE */198199200