annotate src/osdep/unix/ckp_dce.c @ 0:ada5e610ab86

imap-2007e
author yuuji@gentei.org
date Mon, 14 Sep 2009 15:17:45 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1 /* ========================================================================
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
2 * Copyright 1988-2006 University of Washington
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
3 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
4 * Licensed under the Apache License, Version 2.0 (the "License");
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
5 * you may not use this file except in compliance with the License.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
6 * You may obtain a copy of the License at
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
7 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
8 * http://www.apache.org/licenses/LICENSE-2.0
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
9 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
10 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
11 * ========================================================================
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
12 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
13
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
14 /*
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
15 * Program: DCE check password
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
16 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
17 * Author: Mark Crispin
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
18 * Networks and Distributed Computing
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
19 * Computing & Communications
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
20 * University of Washington
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
21 * Administration Building, AG-44
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
22 * Seattle, WA 98195
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
23 * Internet: MRC@CAC.Washington.EDU
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
24 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
25 * Date: 1 August 1988
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
26 * Last Edited: 30 August 2006
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
27 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
28
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
29 /* Check password
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
30 * Accepts: login passwd struct
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
31 * password string
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
32 * argument count
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
33 * argument vector
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
34 * Returns: passwd struct if password validated, NIL otherwise
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
35 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
36
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
37 #include <dce/rpc.h>
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
38 #include <dce/sec_login.h>
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
39
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
40 struct passwd *checkpw (struct passwd *pw,char *pass,int argc,char *argv[])
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
41 {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
42 sec_passwd_rec_t pwr;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
43 sec_login_handle_t lhdl;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
44 boolean32 rstpwd;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
45 sec_login_auth_src_t asrc;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
46 error_status_t status;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
47 FILE *fd;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
48 /* easy case */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
49 if (pw->pw_passwd && pw->pw_passwd[0] && pw->pw_passwd[1] &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
50 !strcmp (pw->pw_passwd,(char *) crypt (pass,pw->pw_passwd))) return pw;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
51 /* try DCE password cache file */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
52 if (fd = fopen (PASSWD_OVERRIDE,"r")) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
53 char *usr = cpystr (pw->pw_name);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
54 while ((pw = fgetpwent (fd)) && strcmp (usr,pw->pw_name));
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
55 fclose (fd); /* finished with cache file */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
56 /* validate cached password */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
57 if (pw && pw->pw_passwd && pw->pw_passwd[0] && pw->pw_passwd[1] &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
58 !strcmp (pw->pw_passwd,(char *) crypt (pass,pw->pw_passwd))) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
59 fs_give ((void **) &usr);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
60 return pw;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
61 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
62 if (!pw) pw = getpwnam (usr);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
63 fs_give ((void **) &usr);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
64 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
65 if (pw) { /* try S-L-O-W DCE... */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
66 sec_login_setup_identity ((unsigned_char_p_t) pw->pw_name,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
67 sec_login_no_flags,&lhdl,&status);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
68 if (status == error_status_ok) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
69 pwr.key.tagged_union.plain = (idl_char *) pass;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
70 pwr.key.key_type = sec_passwd_plain;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
71 pwr.pepper = NIL;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
72 pwr.version_number = sec_passwd_c_version_none;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
73 /* validate password with login context */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
74 sec_login_validate_identity (lhdl,&pwr,&rstpwd,&asrc,&status);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
75 if (!rstpwd && (asrc == sec_login_auth_src_network) &&
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
76 (status == error_status_ok)) {
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
77 sec_login_purge_context (&lhdl,&status);
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
78 if (status == error_status_ok) return pw;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
79 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
80 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
81 }
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
82 return NIL; /* password validation failed */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
83 }

yatex.org