xref: /titanic_41/usr/src/cmd/krb5/kadmin/kpasswd/tty_kpasswd.c (revision 56a424cca6b3f91f31bdab72a4626c48c779fe8b)
17c478bd9Sstevel@tonic-gate /*
2*56a424ccSmp153739  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
37c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
47c478bd9Sstevel@tonic-gate  */
57c478bd9Sstevel@tonic-gate 
67c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
77c478bd9Sstevel@tonic-gate 
87c478bd9Sstevel@tonic-gate /*
97c478bd9Sstevel@tonic-gate  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
107c478bd9Sstevel@tonic-gate  *
117c478bd9Sstevel@tonic-gate  *	Openvision retains the copyright to derivative works of
127c478bd9Sstevel@tonic-gate  *	this source code.  Do *NOT* create a derivative of this
137c478bd9Sstevel@tonic-gate  *	source code before consulting with your legal department.
147c478bd9Sstevel@tonic-gate  *	Do *NOT* integrate *ANY* of this source code into another
157c478bd9Sstevel@tonic-gate  *	product before consulting with your legal department.
167c478bd9Sstevel@tonic-gate  *
177c478bd9Sstevel@tonic-gate  *	For further information, read the top-level Openvision
187c478bd9Sstevel@tonic-gate  *	copyright which is contained in the top-level MIT Kerberos
197c478bd9Sstevel@tonic-gate  *	copyright.
207c478bd9Sstevel@tonic-gate  *
217c478bd9Sstevel@tonic-gate  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
227c478bd9Sstevel@tonic-gate  *
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate  * Copyright 1993-1994 OpenVision Technologies, Inc., All Rights Reserved.
287c478bd9Sstevel@tonic-gate  *
29*56a424ccSmp153739  * $Header: /cvs/krbdev/krb5/src/kadmin/passwd/tty_kpasswd.c,v 1.9 2001/02/26 18:22:08 epeisach Exp $
307c478bd9Sstevel@tonic-gate  *
317c478bd9Sstevel@tonic-gate  *
327c478bd9Sstevel@tonic-gate  */
337c478bd9Sstevel@tonic-gate 
34*56a424ccSmp153739 static char rcsid[] = "$Id: tty_kpasswd.c,v 1.9 2001/02/26 18:22:08 epeisach Exp $";
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #include <kadm5/admin.h>
377c478bd9Sstevel@tonic-gate #include <krb5.h>
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #include "kpasswd_strings.h"
407c478bd9Sstevel@tonic-gate #define string_text error_message
417c478bd9Sstevel@tonic-gate 
42*56a424ccSmp153739 #include "kpasswd.h"
437c478bd9Sstevel@tonic-gate #include <stdio.h>
447c478bd9Sstevel@tonic-gate #include <pwd.h>
457c478bd9Sstevel@tonic-gate #include <string.h>
467c478bd9Sstevel@tonic-gate #include <libintl.h>
477c478bd9Sstevel@tonic-gate #include <locale.h>
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate char *whoami;
507c478bd9Sstevel@tonic-gate 
display_intro_message(fmt_string,arg_string)51*56a424ccSmp153739 void display_intro_message(fmt_string, arg_string)
52*56a424ccSmp153739      const char *fmt_string;
53*56a424ccSmp153739      const char *arg_string;
547c478bd9Sstevel@tonic-gate {
557c478bd9Sstevel@tonic-gate   com_err(whoami, 0, fmt_string, arg_string);
567c478bd9Sstevel@tonic-gate }
577c478bd9Sstevel@tonic-gate 
read_old_password(context,password,pwsize)58*56a424ccSmp153739 long read_old_password(context, password, pwsize)
597c478bd9Sstevel@tonic-gate      krb5_context context;
607c478bd9Sstevel@tonic-gate      char *password;
617c478bd9Sstevel@tonic-gate      unsigned int *pwsize;
627c478bd9Sstevel@tonic-gate {
637c478bd9Sstevel@tonic-gate   long code = krb5_read_password(context,
647c478bd9Sstevel@tonic-gate 	    (char *) string_text(KPW_STR_OLD_PASSWORD_PROMPT),
657c478bd9Sstevel@tonic-gate 			 0, password, pwsize);
66*56a424ccSmp153739   return code;
677c478bd9Sstevel@tonic-gate }
687c478bd9Sstevel@tonic-gate 
read_new_password(server_handle,password,pwsize,msg_ret,msg_len,princ)69*56a424ccSmp153739 long read_new_password(server_handle, password, pwsize, msg_ret, msg_len, princ)
707c478bd9Sstevel@tonic-gate      void *server_handle;
717c478bd9Sstevel@tonic-gate      char *password;
72*56a424ccSmp153739      unsigned int *pwsize;
737c478bd9Sstevel@tonic-gate      char *msg_ret;
747c478bd9Sstevel@tonic-gate      int msg_len;
757c478bd9Sstevel@tonic-gate      krb5_principal princ;
767c478bd9Sstevel@tonic-gate {
777c478bd9Sstevel@tonic-gate 	return (kadm5_chpass_principal_util(server_handle, princ, NULL,
787c478bd9Sstevel@tonic-gate 					   NULL /* don't need new pw back */,
797c478bd9Sstevel@tonic-gate 		msg_ret, msg_len));
807c478bd9Sstevel@tonic-gate }
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate /*
847c478bd9Sstevel@tonic-gate  * main() for tty version of kpasswd.c
857c478bd9Sstevel@tonic-gate  */
867c478bd9Sstevel@tonic-gate int
main(argc,argv)877c478bd9Sstevel@tonic-gate main(argc, argv)
887c478bd9Sstevel@tonic-gate      int argc;
897c478bd9Sstevel@tonic-gate      char *argv[];
907c478bd9Sstevel@tonic-gate {
917c478bd9Sstevel@tonic-gate   krb5_context context;
927c478bd9Sstevel@tonic-gate   int retval;
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate   whoami = (whoami = strrchr(argv[0], '/')) ? whoami + 1 : argv[0];
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)  /* Should be defined by cc -D */
997c478bd9Sstevel@tonic-gate #define	TEXT_DOMAIN	"SYS_TEST"	/* Use this only if it weren't */
1007c478bd9Sstevel@tonic-gate #endif
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
1037c478bd9Sstevel@tonic-gate 
104*56a424ccSmp153739   retval = krb5_init_context(&context);
105*56a424ccSmp153739   if (retval) {
1067c478bd9Sstevel@tonic-gate 		com_err(whoami, retval, gettext("initializing krb5 context"));
1077c478bd9Sstevel@tonic-gate        exit(retval);
1087c478bd9Sstevel@tonic-gate   }
1097c478bd9Sstevel@tonic-gate 	/* initialize_kpws_error_table(); SUNWresync121 */
110*56a424ccSmp153739 
1117c478bd9Sstevel@tonic-gate   retval = kpasswd(context, argc, argv);
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate   if (!retval)
1147c478bd9Sstevel@tonic-gate     printf(string_text(KPW_STR_PASSWORD_CHANGED));
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate   exit(retval);
1177c478bd9Sstevel@tonic-gate }
118