xref: /titanic_41/usr/src/cmd/krb5/kadmin/kpasswd/tty_kpasswd.c (revision ba2e4443695ee6a6f420a35cd4fc3d3346d22932)
1 /*
2  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 #pragma ident	"%Z%%M%	%I%	%E% SMI"
7 
8 /*
9  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
10  *
11  *	Openvision retains the copyright to derivative works of
12  *	this source code.  Do *NOT* create a derivative of this
13  *	source code before consulting with your legal department.
14  *	Do *NOT* integrate *ANY* of this source code into another
15  *	product before consulting with your legal department.
16  *
17  *	For further information, read the top-level Openvision
18  *	copyright which is contained in the top-level MIT Kerberos
19  *	copyright.
20  *
21  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
22  *
23  */
24 
25 
26 /*
27  * Copyright 1993-1994 OpenVision Technologies, Inc., All Rights Reserved.
28  *
29  * $Header: /cvs/krbdev/krb5/src/kadmin/passwd/tty_kpasswd.c,v 1.7\
30  * 1997/02/20 06:13:01 probe Exp $
31  *
32  *
33  */
34 
35 static char rcsid[] = "$Id: tty_kpasswd.c,v 1.7 "
36                       "1997/02/20 06:13:01 probe Exp $";
37 
38 #include <kadm5/admin.h>
39 #include <krb5.h>
40 
41 #include "kpasswd_strings.h"
42 #define	string_text error_message
43 
44 #include <stdio.h>
45 #include <pwd.h>
46 #include <string.h>
47 #include <libintl.h>
48 #include <locale.h>
49 
50 char *whoami;
51 
52 void
53 display_intro_message(fmt_string, arg_string)
54 char *fmt_string;
55 char *arg_string;
56 {
57 	com_err(whoami, 0, fmt_string, arg_string);
58 }
59 
60 long
61 read_old_password(context, password, pwsize)
62 krb5_context context;
63 char *password;
64 unsigned int *pwsize;
65 {
66 	long code = krb5_read_password(context,
67 	    (char *) string_text(KPW_STR_OLD_PASSWORD_PROMPT),
68 	    0, password, pwsize);
69 
70 	return (code);
71 }
72 
73 long
74 read_new_password(server_handle, password, pwsize,
75                  msg_ret, msg_len, princ)
76 void *server_handle;
77 char *password;
78 int *pwsize;
79 char *msg_ret;
80 int msg_len;
81 krb5_principal princ;
82 {
83 	return (kadm5_chpass_principal_util(server_handle, princ, NULL,
84 		NULL /* don't need new pw back */,
85 		msg_ret, msg_len));
86 }
87 
88 
89 /*
90  * main() for tty version of kpasswd.c
91  */
92 int
93 main(argc, argv)
94 int argc;
95 char *argv[];
96 {
97 	krb5_context context;
98 	int retval;
99 
100 	whoami = (whoami = strrchr(argv[0], '/')) ? whoami + 1 : argv[0];
101 
102 	(void) setlocale(LC_ALL, "");
103 
104 #if !defined(TEXT_DOMAIN)  /* Should be defined by cc -D */
105 #define	TEXT_DOMAIN	"SYS_TEST"	/* Use this only if it weren't */
106 #endif
107 
108 	(void) textdomain(TEXT_DOMAIN);
109 
110 	if (retval = krb5_init_context(&context)) {
111 		com_err(whoami, retval, gettext("initializing krb5 context"));
112 		exit(retval);
113 	}
114 	/* initialize_kpws_error_table(); SUNWresync121 */
115 	retval = kpasswd(context, argc, argv);
116 
117 	if (!retval)
118 		printf(string_text(KPW_STR_PASSWORD_CHANGED));
119 
120 	exit(retval);
121 }
122