lock.c (33b02016) lock.c (ed7f0ec9)
1/* $NetBSD: lock.c,v 1.32 2012/03/20 20:34:58 matt Exp $ */
1/* $NetBSD: lock.c,v 1.33 2013/10/18 20:47:06 christos Exp $ */
2
3/*
4 * Copyright (c) 1980, 1987, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Bob Toxen.
9 *

--- 27 unchanged lines hidden (view full) ---

37__COPYRIGHT("@(#) Copyright (c) 1980, 1987, 1993\
38 The Regents of the University of California. All rights reserved.");
39#endif /* not lint */
40
41#ifndef lint
42#if 0
43static char sccsid[] = "@(#)lock.c 8.1 (Berkeley) 6/6/93";
44#endif
2
3/*
4 * Copyright (c) 1980, 1987, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Bob Toxen.
9 *

--- 27 unchanged lines hidden (view full) ---

37__COPYRIGHT("@(#) Copyright (c) 1980, 1987, 1993\
38 The Regents of the University of California. All rights reserved.");
39#endif /* not lint */
40
41#ifndef lint
42#if 0
43static char sccsid[] = "@(#)lock.c 8.1 (Berkeley) 6/6/93";
44#endif
45__RCSID("$NetBSD: lock.c,v 1.32 2012/03/20 20:34:58 matt Exp $");
45__RCSID("$NetBSD: lock.c,v 1.33 2013/10/18 20:47:06 christos Exp $");
46#endif /* not lint */
47
48/*
49 * Lock a terminal up until the given key is entered, until the root
50 * password is entered, or the given interval times out.
51 *
52 * Timeout interval is by default TIMEOUT, it can be changed with
53 * an argument of the form -time where time is in minutes

--- 46 unchanged lines hidden (view full) ---

100{
101 struct passwd *pw;
102 struct timeval timval;
103 struct itimerval ntimer, otimer;
104 struct tm *timp;
105 time_t curtime;
106 int ch, usemine;
107 long sectimeout;
46#endif /* not lint */
47
48/*
49 * Lock a terminal up until the given key is entered, until the root
50 * password is entered, or the given interval times out.
51 *
52 * Timeout interval is by default TIMEOUT, it can be changed with
53 * an argument of the form -time where time is in minutes

--- 46 unchanged lines hidden (view full) ---

100{
101 struct passwd *pw;
102 struct timeval timval;
103 struct itimerval ntimer, otimer;
104 struct tm *timp;
105 time_t curtime;
106 int ch, usemine;
107 long sectimeout;
108 char *ap, *mypw, *ttynam;
108 char *ap, *ttynam;
109 const char *tzn;
110 uid_t uid = getuid();
111 char hostname[MAXHOSTNAMELEN + 1], s[BUFSIZ], s1[BUFSIZ];
112#ifdef USE_PAM
113 pam_handle_t *pamh = NULL;
114 static const struct pam_conv pamc = { &openpam_ttyconv, NULL };
115 int pam_err;
109 const char *tzn;
110 uid_t uid = getuid();
111 char hostname[MAXHOSTNAMELEN + 1], s[BUFSIZ], s1[BUFSIZ];
112#ifdef USE_PAM
113 pam_handle_t *pamh = NULL;
114 static const struct pam_conv pamc = { &openpam_ttyconv, NULL };
115 int pam_err;
116#else
117 char *mypw = NULL;
116#endif
117
118 if ((pw = getpwuid(getuid())) == NULL)
119 errx(1, "unknown uid %lu.", (u_long)uid);
120
121 notimeout = 0;
122 sectimeout = TIMEOUT;
118#endif
119
120 if ((pw = getpwuid(getuid())) == NULL)
121 errx(1, "unknown uid %lu.", (u_long)uid);
122
123 notimeout = 0;
124 sectimeout = TIMEOUT;
123 mypw = NULL;
124 usemine = 0;
125
126 while ((ch = getopt(argc, argv, "npt:")) != -1)
127 switch ((char)ch) {
128 case 'n':
129 notimeout = 1;
130 break;
131 case 't':

--- 73 unchanged lines hidden (view full) ---

205 (void)fgets(s1, sizeof(s1), stdin);
206 (void)putchar('\n');
207 if (strcmp(s1, s)) {
208 (void)printf("\alock: passwords didn't match.\n");
209 (void)tcsetattr(STDIN_FILENO, TCSADRAIN, &tty);
210 exit(1);
211 }
212 s[0] = '\0';
125 usemine = 0;
126
127 while ((ch = getopt(argc, argv, "npt:")) != -1)
128 switch ((char)ch) {
129 case 'n':
130 notimeout = 1;
131 break;
132 case 't':

--- 73 unchanged lines hidden (view full) ---

206 (void)fgets(s1, sizeof(s1), stdin);
207 (void)putchar('\n');
208 if (strcmp(s1, s)) {
209 (void)printf("\alock: passwords didn't match.\n");
210 (void)tcsetattr(STDIN_FILENO, TCSADRAIN, &tty);
211 exit(1);
212 }
213 s[0] = '\0';
214#ifndef USE_PAM
213 mypw = s1;
215 mypw = s1;
216#endif
214 }
215#ifdef USE_PAM
216 if (usemine) {
217 pam_err = pam_start("lock", pw->pw_name, &pamc, &pamh);
218 if (pam_err != PAM_SUCCESS)
219 err(1, "pam_start: %s", pam_strerror(NULL, pam_err));
220 }
221#endif

--- 138 unchanged lines hidden ---
217 }
218#ifdef USE_PAM
219 if (usemine) {
220 pam_err = pam_start("lock", pw->pw_name, &pamc, &pamh);
221 if (pam_err != PAM_SUCCESS)
222 err(1, "pam_start: %s", pam_strerror(NULL, pam_err));
223 }
224#endif

--- 138 unchanged lines hidden ---