2 * Copyright (c) 1996, 1998-2005 Todd C. Miller <Todd.Miller@courtesan.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
16 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
17 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19 * Sponsored in part by the Defense Advanced Research Projects
20 * Agency (DARPA) and Air Force Research Laboratory, Air Force
21 * Materiel Command, USAF, under agreement number F39502-99-1-0512.
24 * The code below basically comes from the examples supplied on
25 * the OSF DCE 1.0.3 manpages for the sec_login routines, with
26 * enough additional polishing to make the routine work with the
29 * This code is known to work on HP 700 and 800 series systems
30 * 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, OSF
37 #include <sys/types.h>
38 #include <sys/param.h>
47 #endif /* STDC_HEADERS */
51 # ifdef HAVE_STRINGS_H
54 #endif /* HAVE_STRING_H */
57 #endif /* HAVE_UNISTD_H */
61 #include <dce/sec_login.h>
62 #include <dce/dce_error.h> /* required to call dce_error_inq_text routine */
65 #include "sudo_auth.h"
68 __unused static const char rcsid[] = "$Sudo: dce.c,v 1.11.2.2 2007/06/12 01:28:42 millert Exp $";
71 static int check_dce_status __P((error_status_t, char *));
74 dce_verify(pw, plain_pw, auth)
79 struct passwd temp_pw;
80 sec_passwd_rec_t password_rec;
81 sec_login_handle_t login_context;
82 boolean32 reset_passwd;
83 sec_login_auth_src_t auth_src;
84 error_status_t status;
87 * Create the local context of the DCE principal necessary
88 * to perform authenticated network operations. The network
89 * identity set up by this operation cannot be used until it
90 * is validated via sec_login_validate_identity().
92 if (sec_login_setup_identity((unsigned_char_p_t) pw->pw_name,
93 sec_login_no_flags, &login_context, &status)) {
95 if (check_dce_status(status, "sec_login_setup_identity(1):"))
98 password_rec.key.key_type = sec_passwd_plain;
99 password_rec.key.tagged_union.plain = (idl_char *) plain_pw;
100 password_rec.pepper = NULL;
101 password_rec.version_number = sec_passwd_c_version_none;
103 /* Validate the login context with the password */
104 if (sec_login_validate_identity(login_context, &password_rec,
105 &reset_passwd, &auth_src, &status)) {
107 if (check_dce_status(status, "sec_login_validate_identity(1):"))
108 return(AUTH_FAILURE);
111 * Certify that the DCE Security Server used to set
112 * up and validate a login context is legitimate. Makes
113 * sure that we didn't get spoofed by another DCE server.
115 if (!sec_login_certify_identity(login_context, &status)) {
116 (void) fprintf(stderr, "Whoa! Bogus authentication server!\n");
117 (void) check_dce_status(status,"sec_login_certify_identity(1):");
118 return(AUTH_FAILURE);
120 if (check_dce_status(status, "sec_login_certify_identity(2):"))
121 return(AUTH_FAILURE);
124 * Sets the network credentials to those specified
125 * by the now validated login context.
127 sec_login_set_context(login_context, &status);
128 if (check_dce_status(status, "sec_login_set_context:"))
129 return(AUTH_FAILURE);
132 * Oops, your credentials were no good. Possibly
133 * caused by clock times out of adjustment between
134 * DCE client and DCE security server...
136 if (auth_src != sec_login_auth_src_network) {
137 (void) fprintf(stderr,
138 "You have no network credentials.\n");
139 return(AUTH_FAILURE);
141 /* Check if the password has aged and is thus no good */
143 (void) fprintf(stderr,
144 "Your DCE password needs resetting.\n");
145 return(AUTH_FAILURE);
149 * We should be a valid user by this point. Pull the
150 * user's password structure from the DCE security
151 * server just to make sure. If we get it with no
152 * problems, then we really are legitimate...
154 sec_login_get_pwent(login_context, (sec_login_passwd_t) &temp_pw,
156 if (check_dce_status(status, "sec_login_get_pwent:"))
157 return(AUTH_FAILURE);
160 * If we get to here, then the pwent above properly fetched
161 * the password structure from the DCE registry, so the user
162 * must be valid. We don't really care what the user's
163 * registry password is, just that the user could be
164 * validated. In fact, if we tried to compare the local
165 * password to the DCE entry at this point, the operation
166 * would fail if the hidden password feature is turned on,
167 * because the password field would contain an asterisk.
168 * Also go ahead and destroy the user's DCE login context
169 * before we leave here (and don't bother checking the
170 * status), in order to clean up credentials files in
171 * /opt/dcelocal/var/security/creds. By doing this, we are
172 * assuming that the user will not need DCE authentication
173 * later in the program, only local authentication. If this
174 * is not true, then the login_context will have to be
175 * returned to the calling program, and the context purged
176 * somewhere later in the program.
178 sec_login_purge_context(&login_context, &status);
179 return(AUTH_SUCCESS);
181 if(check_dce_status(status, "sec_login_validate_identity(2):"))
182 return(AUTH_FAILURE);
183 sec_login_purge_context(&login_context, &status);
184 if(check_dce_status(status, "sec_login_purge_context:"))
185 return(AUTH_FAILURE);
188 (void) check_dce_status(status, "sec_login_setup_identity(2):");
189 return(AUTH_FAILURE);
192 /* Returns 0 for DCE "ok" status, 1 otherwise */
194 check_dce_status(input_status, comment)
195 error_status_t input_status;
199 unsigned char error_string[dce_c_error_string_len];
201 if (input_status == rpc_s_ok)
203 dce_error_inq_text(input_status, error_string, &error_stat);
204 (void) fprintf(stderr, "%s %s\n", comment, error_string);