summaryrefslogtreecommitdiffstats
path: root/src/lib/des425/read_passwd.c
blob: a58a7a4499a9cb35ae80fe4bf6b6dbdbdcfc01d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
 * lib/des425/read_passwd.c
 *
 * Copyright 1985,1986,1987,1988,1991 by the Massachusetts Institute
 * of Technology.
 * All Rights Reserved.
 *
 * Export of this software from the United States of America may
 *   require a specific license from the United States Government.
 *   It is the responsibility of any person or organization contemplating
 *   export to obtain such a license before exporting.
 * 
 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
 * distribute this software and its documentation for any purpose and
 * without fee is hereby granted, provided that the above copyright
 * notice appear in all copies and that both that copyright notice and
 * this permission notice appear in supporting documentation, and that
 * the name of M.I.T. not be used in advertising or publicity pertaining
 * to distribution of the software without specific, written prior
 * permission.  M.I.T. makes no representations about the suitability of
 * this software for any purpose.  It is provided "as is" without express
 * or implied warranty.
 * 
 *
 * This routine prints the supplied string to standard
 * output as a prompt, and reads a password string without
 * echoing.
 */

#include "des.h"

static krb5_context krb4_global_context = 0;

/*** Routines ****************************************************** */
krb5_error_code
des_read_password/*_v4_compat_crock*/(k,prompt,verify)
    mit_des_cblock *k;
    char *prompt;
    int	verify;
{
    krb5_error_code ok;
    krb5_error_code retval;
    char key_string[BUFSIZ];
    char prompt2[BUFSIZ];
    int string_size = sizeof(key_string);

    if (!krb4_global_context) {
	    retval = krb5_init_context(&krb4_global_context);
	    if (retval)
		    return retval;
    }

    if (verify) {
	strcpy(prompt2, "Verifying, please re-enter ");
	strncat(prompt2, prompt, sizeof(prompt2)-(strlen(prompt2)+1));
    }
    ok = krb5_read_password(krb4_global_context, prompt, verify ? prompt2 : 0,
			    key_string, &string_size);
    
    if (ok == 0)
	des_string_to_key(key_string, k);

    memset(key_string, 0, sizeof (key_string));
    return ok;
}

krb5_error_code
des_read_pw_string/*_v4_compat_crock*/(buf, bufsize, prompt, prompt2)
    char *buf;
    int *bufsize;
    char *prompt;
    char *prompt2;
{
    krb5_error_code retval;
    
    if (!krb4_global_context) {
	    retval = krb5_init_context(&krb4_global_context);
	    if (retval)
		    return retval;
    }

    retval = krb5_read_password(krb4_global_context, prompt, prompt2,
			    buf, bufsize);
    return retval;
}