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