Annotation of 43BSDTahoe/ucb/ftp/getpass.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1985 Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * Redistribution and use in source and binary forms are permitted
        !             6:  * provided that the above copyright notice and this paragraph are
        !             7:  * duplicated in all such forms and that any documentation,
        !             8:  * advertising materials, and other materials related to such
        !             9:  * distribution and use acknowledge that the software was developed
        !            10:  * by the University of California, Berkeley.  The name of the
        !            11:  * University may not be used to endorse or promote products derived
        !            12:  * from this software without specific prior written permission.
        !            13:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
        !            14:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
        !            15:  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            16:  */
        !            17: 
        !            18: #ifndef lint
        !            19: static char sccsid[] = "@(#)getpass.c  5.6 (Berkeley) 6/29/88";
        !            20: #endif /* not lint */
        !            21: 
        !            22: #include <stdio.h>
        !            23: #include <signal.h>
        !            24: #include <sgtty.h>
        !            25: 
        !            26: static struct sgttyb ttyb;
        !            27: static int flags;
        !            28: static FILE *fi;
        !            29: 
        !            30: static intfix()
        !            31: {
        !            32:        ttyb.sg_flags = flags;
        !            33:        if (fi != NULL)
        !            34:                (void) stty(fileno(fi), &ttyb);
        !            35:        exit(SIGINT);
        !            36: }
        !            37: 
        !            38: char *
        !            39: mygetpass(prompt)
        !            40: char *prompt;
        !            41: {
        !            42:        register char *p;
        !            43:        register c;
        !            44:        static char pbuf[50+1];
        !            45:        int (*signal())();
        !            46:        int (*sig)();
        !            47: 
        !            48:        if ((fi = fopen("/dev/tty", "r")) == NULL)
        !            49:                fi = stdin;
        !            50:        else
        !            51:                setbuf(fi, (char *)NULL);
        !            52:        sig = signal(SIGINT, intfix);
        !            53:        (void) gtty(fileno(fi), &ttyb);
        !            54:        flags = ttyb.sg_flags;
        !            55:        ttyb.sg_flags &= ~ECHO;
        !            56:        (void) stty(fileno(fi), &ttyb);
        !            57:        fprintf(stderr, "%s", prompt); (void) fflush(stderr);
        !            58:        for (p=pbuf; (c = getc(fi))!='\n' && c!=EOF;) {
        !            59:                if (p < &pbuf[sizeof(pbuf)-1])
        !            60:                        *p++ = c;
        !            61:        }
        !            62:        *p = '\0';
        !            63:        fprintf(stderr, "\n"); (void) fflush(stderr);
        !            64:        ttyb.sg_flags = flags;
        !            65:        (void) stty(fileno(fi), &ttyb);
        !            66:        (void) signal(SIGINT, sig);
        !            67:        if (fi != stdin)
        !            68:                (void) fclose(fi);
        !            69:        return(pbuf);
        !            70: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.