[cs631apue] setting the password

Paul-Anthony Dudzinski pdudzins at stevens.edu
Sun Dec 8 21:55:33 EST 2013


Hello all,

I am writing the function to take the password from the user using the
termios (3). So far I have

int get_pass(unsigned char *pwd)
{
    struct termios oflags, nflags;
    char password[MAX_PASS_LEN];
    char pass2[MAX_PASS_LEN];

    /* disabling echo */
    tcgetattr(fileno(stdin), &oflags);
    nflags = oflags;
    nflags.c_lflag &= ~ECHO;
    nflags.c_lflag |= ECHONL;

    if (tcsetattr(fileno(stdin),  TCSANOW, &nflags) != 0) {
    perror("tcsetattr");
    }

    printf("Password: ");
    fgets(password, sizeof(password), stdin);
    password[strlen(password) - 1] = 0;

    while( strcmp(password,pass2) != 0){
        printf("Again : ");
        fgets(pass2, sizeof(pass2), stdin);
        pass2[strlen(pass2) - 1] = 0;
    }

    memcpy(pwd,password,strlen(password));

    /* restore terminal */
    if (tcsetattr(fileno(stdin), TCSANOW, &oflags) != 0) {
        perror("tcsetattr");
        return EXIT_FAILURE;
    }

    return 0;
}


This works fine when I run this by itself in a separate main function.
However when I put this in with my other code I get some errors that I do
not know how to handle and makes my program unstable.


pdudzins at rainman:~/cs631/hw5$ ./a.out -e < test.txt > out.txt
tcsetattr: Inappropriate ioctl for device

I am not sure how to appropriately handle the terminal using tcsetattr. Has
anyone run into this problem?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.stevens.edu/pipermail/cs631apue/attachments/20131208/6629aafc/attachment.html>


More information about the cs631apue mailing list