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
TCSETATTR(3)						   BSD Library Functions Manual 					      TCSETATTR(3)

NAME
cfgetispeed, cfsetispeed, cfgetospeed, cfsetospeed, cfsetspeed, cfmakeraw, cfmakesane, tcgetattr, tcsetattr -- manipulating the termios structure LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <termios.h> speed_t cfgetispeed(const struct termios *t); int cfsetispeed(struct termios *t, speed_t speed); speed_t cfgetospeed(const struct termios *t); int cfsetospeed(struct termios *t, speed_t speed); int cfsetspeed(struct termios *t, speed_t speed); void cfmakeraw(struct termios *t); void cfmakesane(struct termios *t); int tcgetattr(int fd, struct termios *t); int tcsetattr(int fd, int action, const struct termios *t); DESCRIPTION
The cfmakeraw(), cfmakesane(), tcgetattr() and tcsetattr() functions are provided for getting and setting the termios structure. The cfgetispeed(), cfsetispeed(), cfgetospeed(), cfsetospeed() and cfsetspeed() functions are provided for getting and setting the baud rate values in the termios structure. The effects of the functions on the terminal as described below do not become effective, nor are all errors detected, until the tcsetattr() function is called. Certain values for baud rates set in the termios structure and passed to tcsetattr() have special meanings. These are discussed in the portion of the manual page that describes the tcsetattr() function. GETTING AND SETTING THE BAUD RATE
The input and output baud rates are found in the termios structure. The unsigned integer speed_t is typedef'd in the include file <termios.h>. The value of the integer corresponds directly to the baud rate being represented, however, the following symbolic values are defined. #define B0 0 #define B50 50 #define B75 75 #define B110 110 #define B134 134 #define B150 150 #define B200 200 #define B300 300 #define B600 600 #define B1200 1200 #define B1800 1800 #define B2400 2400 #define B4800 4800 #define B9600 9600 #define B19200 19200 #define B38400 38400 #ifndef _POSIX_SOURCE #define EXTA 19200 #define EXTB 38400 #endif /*_POSIX_SOURCE */ The cfgetispeed() function returns the input baud rate in the termios structure referenced by tp. The cfsetispeed() function sets the input baud rate in the termios structure referenced by tp to speed. The cfgetospeed() function returns the output baud rate in the termios structure referenced by tp. The cfsetospeed() function sets the output baud rate in the termios structure referenced by tp to speed. The cfsetspeed() function sets both the input and output baud rate in the termios structure referenced by tp to speed. Upon successful completion, the functions cfsetispeed(), cfsetospeed(), and cfsetspeed() return a value of 0. Otherwise, a value of -1 is returned and the global variable errno is set to indicate the error. GETTING AND SETTING THE TERMIOS STATE
This section describes the functions that are used to control the general terminal interface. Unless otherwise noted for a specific command, these functions are restricted from use by background processes. Attempts to perform these operations shall cause the process group to be sent a SIGTTOU signal. If the calling process is blocking or ignoring SIGTTOU signals, the process is allowed to perform the operation and the SIGTTOU signal is not sent. In all the functions, although fd is an open file descriptor, the functions affect the underlying terminal file, not just the open file description associated with the particular file descriptor. The cfmakeraw() function sets the flags stored in the termios structure to a state disabling all input and output processing, giving a ``raw I/O path'', while the cfmakesane() function sets them to a state similar to those of a newly created terminal device. It should be noted that there is no function to reverse this effect. This is because there are a variety of processing options that could be re-enabled and the correct method is for an application to snapshot the current terminal state using the function tcgetattr(), setting raw or sane mode with cfmakeraw() or cfmakesane() and the subsequent tcsetattr(), and then using another tcsetattr() with the saved state to revert to the previous terminal state. The tcgetattr() function copies the parameters associated with the terminal referenced by fd in the termios structure referenced by tp. This function is allowed from a background process, however, the terminal attributes may be subsequently changed by a foreground process. The tcsetattr() function sets the parameters associated with the terminal from the termios structure referenced by tp. The action argument is created by or'ing the following values, as specified in the include file <termios.h>. TCSANOW The change occurs immediately. TCSADRAIN The change occurs after all output written to fd has been transmitted to the terminal. This value of action should be used when changing parameters that affect output. TCSAFLUSH The change occurs after all output written to fd has been transmitted to the terminal. Additionally, any input that has been received but not read is discarded. TCSASOFT If this value is or'ed into the action value, the values of the c_cflag, c_ispeed, and c_ospeed fields are ignored. The 0 baud rate is used to terminate the connection. If 0 is specified as the output speed to the function tcsetattr(), modem control will no longer be asserted on the terminal, disconnecting the terminal. If zero is specified as the input speed to the function tcsetattr(), the input baud rate will be set to the same value as that specified by the output baud rate. If tcsetattr() is unable to make any of the requested changes, it returns -1 and sets errno. Otherwise, it makes all of the requested changes it can. If the specified input and output baud rates differ and are a combination that is not supported, neither baud rate is changed. Upon successful completion, the functions tcgetattr() and tcsetattr() return a value of 0. Otherwise, they return -1 and the global variable errno is set to indicate the error, as follows: [EBADF] The fd argument to tcgetattr() or tcsetattr() was not a valid file descriptor. [EINTR] The tcsetattr() function was interrupted by a signal. [EINVAL] The action argument to the tcsetattr() function was not valid, or an attempt was made to change an attribute represented in the termios structure to an unsupported value. [ENOTTY] The file associated with the fd argument to tcgetattr() or tcsetattr() is not a terminal. SEE ALSO
tcsendbreak(3), termios(4) STANDARDS
The cfgetispeed(), cfsetispeed(), cfgetospeed(), cfsetospeed(), tcgetattr() and tcsetattr() functions are expected to be compliant with the IEEE Std 1003.1-1988 (``POSIX.1'') specification. The cfmakeraw(), cfmakesane() and cfsetspeed() functions, as well as the TCSASOFT option to the tcsetattr() function are extensions to the IEEE Std 1003.1-1988 (``POSIX.1'') specification. BSD
January 2, 1994 BSD
All times are GMT -4. The time now is 08:07 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy