xref: /titanic_44/usr/src/cmd/krb5/kadmin/kpasswd/tty_kpasswd.c (revision 2e107de79998f3036decec2454002940afb9a6ff)
1 /*
2  * Copyright 2006 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.9 2001/02/26 18:22:08 epeisach Exp $
30  *
31  *
32  */
33 
34 static char rcsid[] = "$Id: tty_kpasswd.c,v 1.9 2001/02/26 18:22:08 epeisach Exp $";
35 
36 #include <kadm5/admin.h>
37 #include <krb5.h>
38 
39 #include "kpasswd_strings.h"
40 #define string_text error_message
41 
42 #include "kpasswd.h"
43 #include <stdio.h>
44 #include <pwd.h>
45 #include <string.h>
46 #include <libintl.h>
47 #include <locale.h>
48 
49 char *whoami;
50 
51 void display_intro_message(fmt_string, arg_string)
52      const char *fmt_string;
53      const char *arg_string;
54 {
55   com_err(whoami, 0, fmt_string, arg_string);
56 }
57 
58 long read_old_password(context, password, pwsize)
59      krb5_context context;
60      char *password;
61      unsigned int *pwsize;
62 {
63   long code = krb5_read_password(context,
64 	    (char *) string_text(KPW_STR_OLD_PASSWORD_PROMPT),
65 			 0, password, pwsize);
66   return code;
67 }
68 
69 long read_new_password(server_handle, password, pwsize, msg_ret, msg_len, princ)
70      void *server_handle;
71      char *password;
72      unsigned int *pwsize;
73      char *msg_ret;
74      int msg_len;
75      krb5_principal princ;
76 {
77 	return (kadm5_chpass_principal_util(server_handle, princ, NULL,
78 					   NULL /* don't need new pw back */,
79 		msg_ret, msg_len));
80 }
81 
82 
83 /*
84  * main() for tty version of kpasswd.c
85  */
86 int
87 main(argc, argv)
88      int argc;
89      char *argv[];
90 {
91   krb5_context context;
92   int retval;
93 
94   whoami = (whoami = strrchr(argv[0], '/')) ? whoami + 1 : argv[0];
95 
96 	(void) setlocale(LC_ALL, "");
97 
98 #if !defined(TEXT_DOMAIN)  /* Should be defined by cc -D */
99 #define	TEXT_DOMAIN	"SYS_TEST"	/* Use this only if it weren't */
100 #endif
101 
102 	(void) textdomain(TEXT_DOMAIN);
103 
104   retval = krb5_init_context(&context);
105   if (retval) {
106 		com_err(whoami, retval, gettext("initializing krb5 context"));
107        exit(retval);
108   }
109 	/* initialize_kpws_error_table(); SUNWresync121 */
110 
111   retval = kpasswd(context, argc, argv);
112 
113   if (!retval)
114     printf(string_text(KPW_STR_PASSWORD_CHANGED));
115 
116   exit(retval);
117 }
118