Windows global stuff:
[krb5.git] / src / lib / des425 / read_passwd.c
1 /*
2  * lib/des425/read_passwd.c
3  *
4  * Copyright 1985,1986,1987,1988,1991 by the Massachusetts Institute
5  * of Technology.
6  * All Rights Reserved.
7  *
8  * Export of this software from the United States of America may
9  *   require a specific license from the United States Government.
10  *   It is the responsibility of any person or organization contemplating
11  *   export to obtain such a license before exporting.
12  * 
13  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
14  * distribute this software and its documentation for any purpose and
15  * without fee is hereby granted, provided that the above copyright
16  * notice appear in all copies and that both that copyright notice and
17  * this permission notice appear in supporting documentation, and that
18  * the name of M.I.T. not be used in advertising or publicity pertaining
19  * to distribution of the software without specific, written prior
20  * permission.  M.I.T. makes no representations about the suitability of
21  * this software for any purpose.  It is provided "as is" without express
22  * or implied warranty.
23  * 
24  *
25  * This routine prints the supplied string to standard
26  * output as a prompt, and reads a password string without
27  * echoing.
28  */
29
30 #include "des.h"
31
32 static krb5_context krb4_global_context = 0;
33
34 /*** Routines ****************************************************** */
35 krb5_error_code
36 des_read_password/*_v4_compat_crock*/(k,prompt,verify)
37     mit_des_cblock *k;
38     char *prompt;
39     int verify;
40 {
41     krb5_error_code ok;
42     krb5_error_code retval;
43     char key_string[BUFSIZ];
44     char prompt2[BUFSIZ];
45     int string_size = sizeof(key_string);
46
47     if (!krb4_global_context) {
48             retval = krb5_init_context(&krb4_global_context);
49             if (retval)
50                     return retval;
51     }
52
53     if (verify) {
54         strcpy(prompt2, "Verifying, please re-enter ");
55         strncat(prompt2, prompt, sizeof(prompt2)-(strlen(prompt2)+1));
56     }
57     ok = krb5_read_password(krb4_global_context, prompt, verify ? prompt2 : 0,
58                             key_string, &string_size);
59     
60     if (ok == 0)
61         des_string_to_key(key_string, k);
62
63     memset(key_string, 0, sizeof (key_string));
64     return ok;
65 }