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