Sponsored Content
Full Discussion: Masking Password with *'s
Top Forums Programming Masking Password with *'s Post 302481683 by Driver on Sunday 19th of December 2010 06:59:38 AM
Old 12-19-2010
The code is missing one or more includes.

If you're on a newish system, try adding "#include <sys/select.h>". Otherwise, try "#include <sys/types.h>" and "#include <unistd.h>".

Jim's code looks generally acceptable, except that it does not do any error checking, and I'd rather set c_cc[VMIN] = 1 and not use select().

If Jim's code doesn't work for you, try the following much simplified version. Yes, you heard right, I'd even go as far as using stdio on a noncanonical terminal device. I have no indications that it is prohibited by UNIX to do this, nor have I encountered any real world systems which do not allow it. (What did break stdio for me was nonblocking file descriptors on HP-UX, although I do not remember details)

Code:
#include <termios.h>
#include <stdio.h>

static struct termios termold;

void
echo_off(void) {
        struct termios t;
        (void) tcgetattr(0, &termold);
        t = termold;
        t.c_lflag &= ~(ICANON | ECHO);
        t.c_cc[VMIN] = 1;
        t.c_cc[VTIME] = 0;
        (void) tcsetattr(0, TCSANOW, &t);
}

void
echo_on(void) {
        (void) tcsetattr(0, TCSANOW, &termold);
}

void
read_unbuffered(void) {
        int ch;
        setbuf(stdin, NULL);
        echo_off();
        while ((ch = getchar()) != '\n') {
             putchar('*');
        }
        echo_on();
}

int
main() {
        read_unbuffered();
}

 

10 More Discussions You Might Find Interesting

1. IP Networking

IP Masking

Is it possible for a internal LAN to mask a IP e.g. i have a server ip running the intranet ip being 192.168.0.8 and i want to make that like www.intranet.com is this possible on a internal network ? (1 Reply)
Discussion started by: perleo
1 Replies

2. Shell Programming and Scripting

Masking Content of a String

Hello, I need to know that whether a content of a string can be hidden or masked inside a shell script. My Sample Code is given below <Code> #!/usr/bin/ksh Userid=test DB=temp Passwd=`java Decryption test` # The Above command will get the encryped password for "test" user id and store... (2 Replies)
Discussion started by: maxmave
2 Replies

3. Shell Programming and Scripting

Data Masking

I have a pipe delimited file that I need to 'mask' to before loading to keep some data confidential. I need to maintain the first 4 bytes of certain columns and replace the remaining bytes with an 'x'. I would like to maintain spaces but it's not a requirement. Example, need to mask columns 2... (2 Replies)
Discussion started by: 1superdork
2 Replies

4. Emergency UNIX and Linux Support

Masking of number

BAT:0310:2009-08-0:Y4 :H:D:00003721:03103721.IFH:00138770:05767:00000000001279' EXR:CLP:912.570000' STA:A:9071559:2009-08-10::Wer::Mrs' DEF::531.97:531.97:310221661617::+ABC:BAL:1:N::::5:40.00:0.00:2009-08-10:CN:1111111111109962::3:N:missc :N:PH:00010833:... (5 Replies)
Discussion started by: mad_man12
5 Replies

5. Shell Programming and Scripting

Scripting help/advise on hiding/masking username/password

Hi, I currently have a UNIX script with a function that uses a username and password to connect to the database, retrieve some information and then exit. At the moment, am getting the username and password from a hidden plain text file and permission set to -r--------, i.e. read only to who... (1 Reply)
Discussion started by: newbie_01
1 Replies

6. Shell Programming and Scripting

masking issue

Hi I am facing an issue with the below script which has the below line each field being separated with a tab. I need to mask the 8 and 7th field based on following conditions 1. 8th field is 16 in length and is numerics i will mask the middle 6 digits except the first 6 and last 4. input... (2 Replies)
Discussion started by: mad_man12
2 Replies

7. Shell Programming and Scripting

Masking Password from within a Bash Shell Script

Is there a way to mask the password inside of a script to minimize the impact of a comprimised server? So ssh -o "PasswordAuthentication no" -o "HostbasedAuthentication yes" -l testuser 192.168.3.1 "mysqldump --opt --all-databases -u root -pPassword| gzip" > $backup_dir/mysqldump.gz a... (2 Replies)
Discussion started by: metallica1973
2 Replies

8. Shell Programming and Scripting

Masking algorithm

I have a requirement of masking few specific fields in the UNIX file. The details are as following- File is fixed length file with each record of 250 charater length. 2 fields needs to be masked – the positions are 21:30 and 110:120 The character by character making needs to be done which... (5 Replies)
Discussion started by: n78298
5 Replies

9. UNIX for Dummies Questions & Answers

Masking data

How Can I mask one particular columns using some unix command? (4 Replies)
Discussion started by: dsa
4 Replies

10. Shell Programming and Scripting

Masking with gsub command

My file "test.dat" data as below Requirement is to mask(replace) all english characters with "X" EXCEPT first 7 characters of every line. my command awk '{gsub("]","X")}1' test.dat looks not working properly, Appreciate any suggestion... (6 Replies)
Discussion started by: JSKOBS
6 Replies
TERMIOS(3)						     Library Functions Manual							TERMIOS(3)

NAME
termios, tcgetattr, tcsetattr, cfgetispeed, cfgetospeed, cfsetispeed, cfsetospeed, tcsendbreak, tcdrain, tcflush, tcflow - change terminal attributes SYNOPSIS
#include <termios.h> int tcgetattr(int fd, struct termios *tp) int tcsetattr(int fd, int action, const struct termios *tp) speed_t cfgetispeed(const struct termios *tp) speed_t cfgetospeed(const struct termios *tp) int cfsetispeed(struct termios *tp, speed_t speed) int cfsetospeed(struct termios *tp, speed_t speed) int tcsendbreak(int fd, int duration) int tcdrain(int fd) int tcflush(int fd, int queue_selector) int tcflow(int fd, int action) DESCRIPTION
These are the user functions that modify the tty attributes mentioned in tty(4). In the following, fd refers to an open terminal device file, tp is the address of a struct termios, and speed and values of type speed_t are equal to one of the B0, B50, etc. baud rate symbols. All functions, symbols, and types are declared in <termios.h>. The effects of the tty functions are: tcgetattr(fd, tp) Get the current settings of the tty attributes. tcsetattr(fd, TCSANOW, tp) Set the terminal attributes. The change occurs immediately. tcsetattr(fd, TCSADRAIN, tp) Set the terminal attributes. The change occurs once all the output waiting in the output queues has been transmitted. This should be used when options affecting output are changed. tcsetattr(fd, TCSAFLUSH, tp) Set the terminal attributes. But first wait until all the output waiting in the output queues has been transmitted. All input waiting in the input queues is then discarded and the change is made. This should be used when switching from canonical to non- canonical mode or vice-versa. (Oddly enough, this is seldom what you want, because it discards typeahead. An editing shell does the Right Thing if it uses TCSANOW instead. POSIX may not guarantee good results, but in practice most systems make the canonical input available in raw mode.) cfgetispeed(tp) Return the input baud rate encoded in the termios structure. cfgetospeed(tp) Return the output baud rate encoded in the termios structure. cfsetispeed(tp, speed) Encode the new input baud rate into the termios structure. cfsetospeed(tp, speed) Encode the new output baud rate into the termios structure. tcsendbreak(fd, duration) Emit a break condition on a serial line for a time indicated by duration. (Always 0.4 seconds under Minix, duration is ignored.) tcdrain(fd) Wait until all output waiting in the output queues has been transmitted. tcflush(fd, TCIFLUSH) Flush the input queue. (I.e. discard it.) tcflush(fd, TCOFLUSH) Flush the output queue. tcflush(fd, TCIOFLUSH) Flush the input and output queues. tcflow(fd, TCOOFF) Suspend output. (Like the effect of STOP.) tcflow(fd, TCOON) Restart output. (Like the effect of START.) tcflow(fd, TCIOFF) Transmit a STOP character intended to make the remote device stop transmitting data. tcflow(fd, TCION) Transmit a START character to restart the remote device. SEE ALSO
stty(1), tty(4). DIAGNOSTICS
All functions return 0 unless otherwise specified, and -1 on error with errno set to indicate the type of error. The most notable errors are ENOTTY if fd does not refer to a terminal device, and EINTR if one of the functions waiting for output to drain is interrupted. NOTES
It may be interesting to know that the functions operating on the tty are directly translated into the following Minix ioctl requests: TCGETS, TCSETS (now), TCSETSW (drain), TCSETSF, (flush), TCSBRK, TCDRAIN, TCFLSH, and TCFLOW. You should only use this knowledge when try- ing to understand the tty driver code, of course. BUGS
AUTHOR
Kees J. Bot (kjb@cs.vu.nl) TERMIOS(3)
All times are GMT -4. The time now is 07:29 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy