2 * Copyright (c) 1996, 1998-2005, 2010
3 * Todd C. Miller <Todd.Miller@courtesan.com>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
17 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
18 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
20 * Sponsored in part by the Defense Advanced Research Projects
21 * Agency (DARPA) and Air Force Research Laboratory, Air Force
22 * Materiel Command, USAF, under agreement number F39502-99-1-0512.
25 * The code below basically comes from the examples supplied on
26 * the OSF DCE 1.0.3 manpages for the sec_login routines, with
27 * enough additional polishing to make the routine work with the
30 * This code is known to work on HP 700 and 800 series systems
31 * running HP-UX 9.X and 10.X, with either HP's version 1.2.1 of DCE.
32 * (aka, OSF DCE 1.0.3) or with HP's version 1.4 of DCE (aka, OSF
38 #include <sys/types.h>
39 #include <sys/param.h>
48 #endif /* STDC_HEADERS */
51 #endif /* HAVE_STRING_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"
67 static int check_dce_status __P((error_status_t, char *));
70 dce_verify(pw, plain_pw, auth)
75 struct passwd temp_pw;
76 sec_passwd_rec_t password_rec;
77 sec_login_handle_t login_context;
78 boolean32 reset_passwd;
79 sec_login_auth_src_t auth_src;
80 error_status_t status;
83 * Create the local context of the DCE principal necessary
84 * to perform authenticated network operations. The network
85 * identity set up by this operation cannot be used until it
86 * is validated via sec_login_validate_identity().
88 if (sec_login_setup_identity((unsigned_char_p_t) pw->pw_name,
89 sec_login_no_flags, &login_context, &status)) {
91 if (check_dce_status(status, "sec_login_setup_identity(1):"))
94 password_rec.key.key_type = sec_passwd_plain;
95 password_rec.key.tagged_union.plain = (idl_char *) plain_pw;
96 password_rec.pepper = NULL;
97 password_rec.version_number = sec_passwd_c_version_none;
99 /* Validate the login context with the password */
100 if (sec_login_validate_identity(login_context, &password_rec,
101 &reset_passwd, &auth_src, &status)) {
103 if (check_dce_status(status, "sec_login_validate_identity(1):"))
107 * Certify that the DCE Security Server used to set
108 * up and validate a login context is legitimate. Makes
109 * sure that we didn't get spoofed by another DCE server.
111 if (!sec_login_certify_identity(login_context, &status)) {
112 (void) fprintf(stderr, "Whoa! Bogus authentication server!\n");
113 (void) check_dce_status(status,"sec_login_certify_identity(1):");
116 if (check_dce_status(status, "sec_login_certify_identity(2):"))
120 * Sets the network credentials to those specified
121 * by the now validated login context.
123 sec_login_set_context(login_context, &status);
124 if (check_dce_status(status, "sec_login_set_context:"))
128 * Oops, your credentials were no good. Possibly
129 * caused by clock times out of adjustment between
130 * DCE client and DCE security server...
132 if (auth_src != sec_login_auth_src_network) {
133 (void) fprintf(stderr,
134 "You have no network credentials.\n");
137 /* Check if the password has aged and is thus no good */
139 (void) fprintf(stderr,
140 "Your DCE password needs resetting.\n");
145 * We should be a valid user by this point. Pull the
146 * user's password structure from the DCE security
147 * server just to make sure. If we get it with no
148 * problems, then we really are legitimate...
150 sec_login_get_pwent(login_context, (sec_login_passwd_t) &temp_pw,
152 if (check_dce_status(status, "sec_login_get_pwent:"))
156 * If we get to here, then the pwent above properly fetched
157 * the password structure from the DCE registry, so the user
158 * must be valid. We don't really care what the user's
159 * registry password is, just that the user could be
160 * validated. In fact, if we tried to compare the local
161 * password to the DCE entry at this point, the operation
162 * would fail if the hidden password feature is turned on,
163 * because the password field would contain an asterisk.
164 * Also go ahead and destroy the user's DCE login context
165 * before we leave here (and don't bother checking the
166 * status), in order to clean up credentials files in
167 * /opt/dcelocal/var/security/creds. By doing this, we are
168 * assuming that the user will not need DCE authentication
169 * later in the program, only local authentication. If this
170 * is not true, then the login_context will have to be
171 * returned to the calling program, and the context purged
172 * somewhere later in the program.
174 sec_login_purge_context(&login_context, &status);
177 if(check_dce_status(status, "sec_login_validate_identity(2):"))
179 sec_login_purge_context(&login_context, &status);
180 if(check_dce_status(status, "sec_login_purge_context:"))
184 (void) check_dce_status(status, "sec_login_setup_identity(2):");
188 /* Returns 0 for DCE "ok" status, 1 otherwise */
190 check_dce_status(input_status, comment)
191 error_status_t input_status;
195 unsigned char error_string[dce_c_error_string_len];
197 if (input_status == rpc_s_ok)
199 dce_error_inq_text(input_status, error_string, &error_stat);
200 (void) fprintf(stderr, "%s %s\n", comment, error_string);