]> git.sur5r.net Git - openldap/blobdiff - libraries/liblutil/getpass.c
fix memory handling
[openldap] / libraries / liblutil / getpass.c
index ceb2ab99d025115d3f02a03a1e4d1eb94956c441..2745da308cd5c7e40d22ee35273ecbc0e5efe0c0 100644 (file)
@@ -1,5 +1,20 @@
-/*
- * Copyright (c) 1992, 1993  Regents of the University of Michigan.
+/* getpass.c -- get password from user */
+/* $OpenLDAP$ */
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1998-2005 The OpenLDAP Foundation.
+ * Portions Copyright 1998-2003 Kurt D. Zeilenga.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
+ */
+/* Portions Copyright (c) 1992, 1993  Regents of the University of Michigan.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms are permitted
  * software without specific prior written permission. This software
  * is provided ``as is'' without express or implied warranty.
  */
+/* This work was originally developed by the University of Michigan
+ * and distributed as part of U-MICH LDAP.  It was adapted for use in
+ * -llutil by Kurt D. Zeilenga.
+ */
 
 #include "portable.h"
 
-#ifndef HAVE_GETPASS
-
 #include <stdio.h>
-#include <stdlib.h>
+
+#include <ac/stdlib.h>
 
 #include <ac/ctype.h>
-#include <ac/errno.h>
 #include <ac/signal.h>
 #include <ac/string.h>
 #include <ac/termios.h>
 #include <ac/time.h>
 #include <ac/unistd.h>
 
+#ifdef NEED_GETPASSPHRASE
+
 #ifdef HAVE_FCNTL_H
 #include <fcntl.h>
 #endif
 
 #include <lber.h>
 #include <ldap.h>
-#include <ldapconfig.h>
+
+#include "ldap_defaults.h"
 
 char *
-getpass( const char *prompt )
+lutil_getpass( const char *prompt )
 {
 #if !defined(HAVE_POSIX_TERMIOS) && !defined(HAVE_SGTTY_H)
        static char buf[256];
        int i, c;
 
+       if( prompt == NULL ) prompt = _("Password: ");
+
 #ifdef DEBUG
        if (debug & D_TRACE)
                printf("->getpass(%s)\n", prompt);
 #endif
+
        printf("%s", prompt);
        i = 0;
        while ( (c = getch()) != EOF && c != '\n' && c != '\r' )
@@ -67,6 +90,8 @@ getpass( const char *prompt )
        FILE *fi;
        RETSIGTYPE (*sig)( int sig );
 
+       if( prompt == NULL ) prompt = _("Password: ");
+
 #ifdef DEBUG
        if (debug & D_TRACE)
                printf("->getpass(%s)\n", prompt);
@@ -146,7 +171,7 @@ getpass( const char *prompt )
        if (no_pass)
                return(NULL);
        return(pbuf);
-#endif /* DOS */
+#endif
 }
 
-#endif /* !HAVE_GETPASS */
+#endif /* !NEED_GETPASSPHRASE */