Operating System - HP-UX
1748139 Members
3562 Online
108758 Solutions
New Discussion юеВ

Equivalent C API for getpassphrase on HPUX

 
SOLVED
Go to solution
Moiz Khambaty
Occasional Contributor

Equivalent C API for getpassphrase on HPUX

Hi,
I am trying to port a Solaris application to HPUX.This application uses a C API "getpassphrase" for reading a user password.The getpassphrase() API is not available for HPUX.On HPUX we have a C API namely getpass().But the limitation of this API is that it can accept password only upto a maximum of 8 characters whereas I want a C API that is capable of accepting passwords upto a length of 256 characters.

Is there any C API on HPUX which could address this requirement ?

Thanking you,
Moiz Khambaty.
2 REPLIES 2
Georg Tresselt
Honored Contributor

Re: Equivalent C API for getpassphrase on HPUX

No. AFAIK there is only a getpass() function at best.
http://www.tresselt.eu
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Equivalent C API for getpassphrase on HPUX

Getpass() is due to be obsoleted so you should avoid it in any case. This is a rather easy function to write. All you need to do is open /dev/tty; send that file descriptor to an ioctl using TCGETA to load a termios struct, copy that struct into a new struct and then you set c_lflag to disable ECHO. Use another ioctl using TCSETA to actually instantiate your changes. Read in your password and then make a final ioctl(TCSETA) to restore the original attributes.
You should also use a signal handler to restore the attributes because the ioctl() affects the tty device -- not just the current process. If you exit with ECHO disabled, it remains disabled. You can also choose to set the interrupt, kill, etc. control characters to impossible values (0377) as you disable echo.


This is really one of those functions that you should code yourself to avoid platform dependencies. Man both termio and termios to determine which one you really want to use.
If it ain't broke, I can fix that.