1a2a17c5dff2e2d114f6445afcf2976634a08edc
[openafs.git] / src / dauth / dpass.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /*
11  * dpass
12  *
13  * This program allows a user to discover the password generated for him
14  * by the migration toolkit when migrating his password information
15  * to the DCE.
16  */
17
18 #include <afsconfig.h>
19 #include <afs/param.h>
20
21 RCSID
22     ("$Header$");
23
24 #include <afs/stds.h>
25 #include <sys/types.h>
26 #include <rx/xdr.h>
27 #ifdef  AFS_AIX32_ENV
28 #include <signal.h>
29 #endif
30 #ifdef HAVE_STRING_H
31 #include <string.h>
32 #else
33 #ifdef HAVE_STRINGS_H
34 #include <strings.h>
35 #endif
36 #endif
37
38 #include <ubik.h>
39
40 #include <stdio.h>
41 #include <pwd.h>
42 #include <afs/com_err.h>
43 #include <afs/auth.h>
44 #include <afs/cellconfig.h>
45 #include <afs/afsutil.h>
46 #include <afs/cmd.h>
47 #include "adkint.h"
48 #include "assert.h"
49 #include <des.h>
50
51
52 char *msg[] = {
53     "",
54     "Please read the following message before entering your password.",
55     "",
56     "This program will display your new, temporary DCE password on your",
57     "terminal, and you should change the assigned password as soon as",
58     "possible (from a DCE client). The program assumes that your site uses",
59     "the standard AFS authentication service provided by Transarc and that",
60     "your initial account was created from the AFS authentication",
61     "information by Transarc-supplied migration software.  If this is not",
62     "the case, you should consult your system administrator.  The password",
63     "you enter should be the AFS password that was in effect when your DCE",
64     "account was created; this is not necessarily the same password you",
65     "have at the moment. The cell name (which you may override with a",
66     "command line option), must be the name of the AFS cell from which the",
67     "authentication information was taken.",
68     0
69 };
70
71 CommandProc(as, arock)
72      char *arock;
73      struct cmd_syndesc *as;
74 {
75     int i;
76     afs_int32 code;
77     struct ktc_encryptionKey key;
78     char cell[MAXKTCREALMLEN];
79     char *cell_p;
80     char prompt[1000];
81
82     /*
83      * We suppress the message, above, if this environment variable
84      * is set. This allows the administrator to wrap dpass in a shell
85      * script, if desired, in order to display more information
86      * about registry conversion dates, etc.
87      */
88     if (!getenv("DPASS_NO_MESSAGE")) {
89         for (i = 0; msg[i]; i++)
90             printf("%s\n", msg[i]);
91     }
92
93     if (as->parms[0].items) {
94         struct afsconf_cell cellinfo;
95         struct afsconf_dir *cdir;
96
97         cell_p = as->parms[0].items->data;
98         cdir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH);
99         if (!cdir) {
100             fprintf(stderr,
101                     "\nUnable to verify that \"%s\" is a valid cell name\nProceeding on the assumption that it is correct.\n",
102                     cell_p);
103             exit(1);
104         }
105         code = afsconf_GetCellInfo(cdir, cell_p, 0, &cellinfo);
106         if (code) {
107             fprintf(stderr,
108                     "\nUnable to find information about cell \"%s\"\nProceeding on the assumption that this is a valid cell name.\n",
109                     cell_p);
110         } else {
111             strncpy(cell, cellinfo.name, sizeof(cell) - 1);
112             cell[sizeof(cell)] = '\0';
113             cell_p = cell;
114         }
115     } else {
116         struct afsconf_dir *cdir;
117
118         cdir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH);
119         if (!cdir) {
120             fprintf(stderr,
121                     "\nUnable to read the AFS client configuration file to get local cell name.\nTry specifying the cell with the -cell switch.\n");
122             exit(1);
123         }
124         afsconf_GetLocalCell(cdir, cell, sizeof(cell));
125         cell_p = cell;
126     }
127
128     printf("\n");
129     sprintf(prompt, "Original password for AFS cell %s: ", cell_p);
130     code = ka_ReadPassword(prompt, 1, cell_p, &key);
131     if (code) {
132         fprintf(stderr, "Error reading password\n");
133         exit(1);
134     }
135 #define k(i) (key.data[i] & 0xff)
136 #define s(n) ((k(n) << 8) | k(n+1))
137     printf("\nThe new DCE password is: %0.4x-%0.4x-%0.4x-%0.4x\n", s(0), s(2),
138            s(4), s(6));
139 }
140
141 main(argc, argv)
142      int argc;
143      char *argv[];
144 {
145     struct cmd_syndesc *ts;
146     afs_int32 code;
147 #ifdef  AFS_AIX32_ENV
148     /*
149      * The following signal action for AIX is necessary so that in case of a 
150      * crash (i.e. core is generated) we can include the user's data section 
151      * in the core dump. Unfortunately, by default, only a partial core is
152      * generated which, in many cases, isn't too useful.
153      */
154     struct sigaction nsa;
155
156     sigemptyset(&nsa.sa_mask);
157     nsa.sa_handler = SIG_DFL;
158     nsa.sa_flags = SA_FULLDUMP;
159     sigaction(SIGSEGV, &nsa, NULL);
160 #endif
161     ts = cmd_CreateSyntax(NULL, CommandProc, 0, "show new DCE passord");
162     cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL,
163                 "original AFS cell name");
164     code = cmd_Dispatch(argc, argv);
165     exit(code);
166 }