summaryrefslogtreecommitdiff
path: root/source/a/getty-ps/getty.bugfixes.diff
blob: 6a1ed29e9d8313e805635e68e9913015ee003e8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
This patch contains the following bugfixes:

* the TIMEOUT (and -t flag) has now different effect for getty and uugetty:
  with uugetty, TIMEOUT set will now cause uugetty exit no matter whether
  there has been any input from the user (the counting will start immediately
  after login() has been spawned - pre- getty-2.1.0 behavior), while for
  getty, it will make the counter start after single input has been detected
  from the user
  * getty.1 manpage updated accordingly

* @F issue substitution now works as expected

* @V / VERSION functionality documentation fix in getty.1 manpage

* fixed a bunch of memleaks (if not all):
  * Fputs() made strdup()-free (we now use static structs where possible)
  * avoided unnecessary dual strdup() for Version in defs()
  * freeing of "DEF **def" including its internals is now handled, as well as
    feeing of other variables in defs() pointing to strdup()ed memory areas

Jan Rafaj

--- ./man/getty.1.orig	2002-09-13 09:05:03.000000000 +0200
+++ ./man/getty.1	2005-07-21 10:24:53.000000000 +0200
@@ -307,7 +307,18 @@
 to exit (which
 .I init
 should then respawn), if the login is not completed within timeout seconds
-(after the login name is entered)
+(after the login name is entered). This option behaves differently for
+.I getty
+and
+.I uugetty.
+If
+.I getty
+is used, the counting will start after single input from the user has been
+detected, whileas with
+.I uugetty,
+the counting will start immediately after
+.IR login (1m)
+has been spawned, no matter the input from the user.
 
 Giving
 .B \-w
@@ -388,9 +399,12 @@
 If
 .I string
 begins with a '/' character, it is assumed to be the full pathname of a
-file, and
+text file, and
 .B @V
-is set to be the contents of that file.  The default is /proc/version.
+is set to be the contents of the first line in that file (line has to be
+terminated by newline character or by end of file).
+.br
+The default is /proc/version.
 .TP
 LOGIN=\fIname\fR
 Sets the name of the login program to
@@ -503,6 +517,14 @@
 to exit if no user name is accepted before the
 .I number
 of seconds elapse after the login prompt is displayed.
+With
+.I getty,
+the counting will start as soon as a single character
+has been entered by the user, whileas with
+.I uugetty,
+the counting will start immediately after the login prompt
+is displayed, no matter the input from the user.
+.br
 The default is to wait indefinitely for the user name.
 .TP
 CONNECT=\fIstring\fR
@@ -865,6 +887,11 @@
 .IR cu (1)
 and others).  This prevents two or more processes from having conficting
 use of a tty port.
+.br
+.I Uugetty
+also differs from
+.I getty
+by handling the -t parameter and TIMEOUT option.
 .PP
 When
 .I uugetty
--- ./main.c.orig	2004-04-11 03:34:34.000000000 +0200
+++ ./main.c	2005-07-21 11:37:19.000000000 +0200
@@ -78,6 +78,8 @@
 void	debugstart();
 #endif /* DEBUG */
 
+DEF	**def;
+
 /* trivial globals */
 
 char	buf[MAXLINE];
@@ -86,7 +88,7 @@
 char	tbuf[64];
 
 #define Perror(s)	{ debug(D_INIT, "Line %d: %s: Error %d: %s\n", \
-				__LINE__, s, errno, sys_errlist[errno]); \
+				__LINE__, s, errno, strerror(errno)); \
 			    exit(errno); \
 			}
 
@@ -149,6 +151,50 @@
 	}
 }
 
+/*
+ * Why a lot of programmers ignore the fact that memory area returned
+ * by strdup() and *alloc() has to be freed upon exit? :(( -JR
+ */
+void free_def(void)
+{
+	register DEF **deflist = def;
+
+	for (; *deflist != (DEF *)NULL; deflist++) {
+	    free((*deflist)->name);
+	    free((*deflist)->value);
+	    free(*deflist);
+	}
+}
+
+void free_sysname(void)
+{
+	if (SysName)
+		free(SysName);
+	SysName = NULL;
+}
+
+void free_version(void)
+{
+	if (Version)
+		free(Version);
+	Version = NULL;
+}
+
+#ifdef UUGETTY
+void free_lock(void)
+{
+	if (lock)
+		free(lock);
+	lock = NULL;
+}
+
+void free_altlock(void)
+{
+	if (altlock)
+		free(altlock);
+	altlock = NULL;
+}
+#endif
 
 /*
 ** main
@@ -320,7 +366,6 @@
 char	**args;
 {
 	register int	c;
-	DEF		**def;
 	char		*p;
 	char		termcap[1024];
 
@@ -416,22 +461,27 @@
 /* now, get all that info in the defaults file */
 
 	def = defbuild(defname);
+	atexit(free_def);
 #ifdef DEBUG
 	if ((p = defvalue(def, "DEBUG"))) (void) sscanf(p, "%o", &Debug);
 	if (Debug) debugstart();
 #endif /* DEBUG */
 	SysName = strdup(getuname());
+	atexit(free_sysname);
 	if (p = defvalue(def, "SYSTEM")) SysName = p;
-	if (p = defvalue(def, "VERSION"))
-	     Version = strdup(p);
-	if (*Version == '/')
-	   { if ((fp = fopen(Version, "r")))
-		{  fgets(buf, MAXLINE, fp);
-		   fclose(fp);
-		   buf[strlen(buf)-1] = '\0';
-		   Version = strdup(buf);
+	if (p = defvalue(def, "VERSION")) {
+	    if (*p == '/') {
+		if ((fp = fopen(p, "r"))) {
+		    fgets(buf, MAXLINE, fp);
+		    fclose(fp);
+		    buf[strlen(buf)-1] = '\0';
+		    Version = strdup(buf);
 	        }
-	   }
+	    } else {
+		Version = strdup(p);
+	    }
+	    atexit(free_version);
+	}
 	if((p = defvalue(def, "LOGIN"))) login_pgm = p;
 	if((p = defvalue(def, "ISSUE"))) issue = p;
 	if((p = defvalue(def, "CLEAR")) && (strequal(p, "NO"))) 
@@ -489,12 +539,15 @@
 #ifdef UUGETTY
 	(void) sprintf(buf, LOCK, Device);
 	lock = strdup(buf);
+	atexit(free_lock);
 	if((p = defvalue(def, "ALTLOCK"))) {
 		(void) sprintf(buf, LOCK, p);
 		altlock = strdup(buf);
+		atexit(free_altlock);
 	} else if(! strequal(Device, InitDevice)) {
 		(void) sprintf(buf, LOCK, InitDevice);
 		altlock = strdup(buf);
+		atexit(free_altlock);
 	}
 
 	debug(D_LOCK, "lock = (%s), altlock = (%s)", lock, altlock);
@@ -625,8 +678,8 @@
 	with the uts struct filled above.
 	*/
 
-	debug(D_UTMP, "adding utmp entry: type: %d, pid: %d, line: %s,
-	   id: %c%c, time: %d, user: %s, host: %s, addr: %d",
+	debug(D_UTMP, "adding utmp entry: type: %d, pid: %d, line: %s, "
+	   "id: %c%c, time: %d, user: %s, host: %s, addr: %d",
 	   uts.ut_type, uts.ut_pid, uts.ut_line,
 	   (uts.ut_id[0] ? uts.ut_id[0] : ' '), 
 	   (uts.ut_id[1] ? uts.ut_id[1] : ' '), 
@@ -1077,16 +1130,20 @@
 login_prompt:
 		(void) ioctl(STDIN, TCFLSH, 0);
 #ifdef FIDO
-	if (emsi && (strcmp(emsi,"yes") == 0)) 
-		(void) Fputs("**EMSI_REQA77E\r", stdout);
+		if (emsi && (strcmp(emsi,"yes") == 0)) 
+			(void) Fputs("**EMSI_REQA77E\r", stdout);
 #endif
 		(void) Fputs(gtab->login, stdout);
-
+#ifndef UUGETTY
 		login_result=getlogname(&termio, buf, MAXLINE);
+#endif
 		if(TimeOut > 0) {
 			(void) signal(SIGALRM, timeout);
 			(void) alarm((unsigned) TimeOut);
 		}
+#ifdef UUGETTY
+		login_result=getlogname(&termio, buf, MAXLINE);
+#endif
 
 		switch(login_result) {
 #ifdef FIDO
@@ -1114,6 +1171,13 @@
 #ifdef SETTERM
 				setenv("TERM", term, TRUE);
 #endif /* SETTERM */
+				free_def();
+				free_sysname();
+				free_version();
+#ifdef UUGETTY
+				free_lock();
+				free_altlock();
+#endif
 				debug(D_RUN, "execing login");
 				(void) execl(login_pgm, 
 				  "login", buf, NULLPTR);
--- ./funcs.c.orig	2002-09-25 08:43:28.000000000 +0200
+++ ./funcs.c	2005-07-20 19:01:55.000000000 +0200
@@ -87,12 +87,11 @@
 register char *s;
 register FILE *stream;
 {
-    char c, n, tbuf[20], ubuf[MAXBUF];
-    char *cbuf;
+    char c, n, tbuf[20];
     time_t clock;
     struct tm *lt;
-    struct utsname utsbuf;
-    struct hostent *fqdname;
+    static struct utsname utsbuf;
+    static struct hostent *fqdname;
     FILE  *fp1;
 
     char *day_name[] = { "Sun", "Mon", "Tue", "Wed", "Thur", "Fri", "Sat" };
@@ -119,21 +118,8 @@
 				return(EOF);
 			break;
 		case 'F':	/* FQDName */
-			cbuf = strdup(SysName);
-#if 0			/* The does a seg violation - no idea why.... */
 			fqdname = gethostbyname(SysName);
-#endif
-#if 0			/* So, we cheat.....! */
-			/* Which also gets a seg violation! */
-			if (fp1 = fopen("/etc/HOSTNAME", "r"))
-			 { fgets(cbuf, MAXBUF, fp1);
-			   fclose(fp1);
-			   cbuf[strlen(cbuf)] = '\0';
-			 }
-			if (fqdname != NULL)
-			    cbuf = strdup(fqdname->h_name);
-#endif
-			if (Fputs(cbuf, stream) == EOF)
+			if (fqdname && Fputs(fqdname->h_name, stream) == EOF)
 			    return(EOF);
 			break;
 		case 'L':	/* line */
@@ -141,18 +127,15 @@
 				return(EOF);
 			break;
 		case 'M':	/* arch of machine */
-			cbuf = strdup(utsbuf.machine);
-			if (Fputs(cbuf, stream) == EOF)
+			if (Fputs(utsbuf.machine, stream) == EOF)
 				return(EOF);
 			break;
 		case 'O':	/* O/S name */
-			cbuf = strdup(utsbuf.sysname);
-			if (Fputs(cbuf, stream) == EOF)
+			if (Fputs(utsbuf.sysname, stream) == EOF)
 				return(EOF);
 			break;
 		case 'R':	/* O/S rev_id */
-			cbuf = strdup(utsbuf.release);
-			if (Fputs(cbuf, stream) == EOF)
+			if (Fputs(utsbuf.release, stream) == EOF)
 				return(EOF);
 			break;
 		case 'S':	/* system node name */
@@ -166,8 +149,8 @@
 				return(EOF);
 			break;
 		case 'U':	/* number of active users */
-			(void) sprintf(ubuf, "%d", Nusers);
-			if (Fputs(ubuf, stream) == EOF)
+			(void) sprintf(tbuf, "%d", Nusers);
+			if (Fputs(tbuf, stream) == EOF)
 				return(EOF);
 			break;
 		case 'V':	/* version */
@@ -175,12 +158,10 @@
 				return(EOF);
 			break;
 		case 'u':	/* user count str */
-			cbuf = malloc(20);
 			(void) sprintf(tbuf, "%d User", Nusers);
 			if (Nusers > 1) 
-			     cbuf = strcat(tbuf,"s");
-			else cbuf=strdup(tbuf);
-			if (Fputs(cbuf, stream) == EOF)
+			    strcat(tbuf, "s");
+			if (Fputs(tbuf, stream) == EOF)
 				return(EOF);
 			break;
 		case '@':	/* in case '@@' was used */