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