1 diff -urN -x '*.orig' -x '*~' conserver-8.1.15.org/configure.in conserver-8.1.15/configure.in
2 --- conserver-8.1.15.org/configure.in 2006-05-28 19:30:34.000000000 +0200
3 +++ conserver-8.1.15/configure.in 2007-01-19 22:29:33.683813250 +0100
5 AH_TEMPLATE([HAVE_OPENSSL], [have openssl support])
6 AH_TEMPLATE([HAVE_DMALLOC], [have dmalloc support])
7 AH_TEMPLATE([HAVE_SA_LEN],[Defined if sa_len member exists in struct sockaddr])
8 +AH_TEMPLATE([HAVE_MKSTEMP],[have mkstemp])
9 AH_TEMPLATE([TRUST_REVERSE_DNS],[Defined if we trust reverse DNS])
10 AH_TEMPLATE([USE_EXTENDED_MESSAGES],[Defined if we produce extended messages])
11 AH_TEMPLATE([USE_UNIX_DOMAIN_SOCKETS],[Defined if we use Unix domain sockets])
14 AC_DEFINE(HAVE_SA_LEN)],
17 +AC_MSG_CHECKING(for mkstemp)
18 +AC_TRY_COMPILE([#include <stdlib.h>],
19 + [mkstemp("/tmp/XXXXXX");],
21 + AC_DEFINE(HAVE_MKSTEMP)],
22 + [AC_MSG_RESULT(no)])
25 dnl ### Host specific checks. ######################################
27 diff -urN -x '*.orig' -x '*~' conserver-8.1.15.org/conserver/consent.c conserver-8.1.15/conserver/consent.c
28 --- conserver-8.1.15.org/conserver/consent.c 2006-06-17 04:03:15.000000000 +0200
29 +++ conserver-8.1.15/conserver/consent.c 2007-01-19 22:29:33.683813250 +0100
38 #if defined(FOR_CYCLADES_TS)
40 close(pCE->execSlaveFD);
43 + if (pCE->type == DEVICE && pCE->lock == FLAGTRUE) {
44 + rmlocks(pCE->device);
49 @@ -1006,6 +1009,21 @@
53 + if (pCE->lock == FLAGTRUE) {
54 + if (checklock(pCE->device) != NO_LOCK) {
55 + Error("[%s] checklock(%s): device already locked",
56 + pCE->server, pCE->device);
57 + ConsDown(pCE, FLAGTRUE, FLAGTRUE);
60 + if (makelock(pCE->device) == FAIL) {
61 + Error("[%s] makelock(%s): could not lock device",
62 + pCE->server, pCE->device);
63 + ConsDown(pCE, FLAGTRUE, FLAGTRUE);
66 + /* now we have the lock */
69 (cofile = open(pCE->device, O_RDWR | O_NONBLOCK, 0600))) {
71 diff -urN -x '*.orig' -x '*~' conserver-8.1.15.org/conserver/consent.h conserver-8.1.15/conserver/consent.h
72 --- conserver-8.1.15.org/conserver/consent.h 2006-05-28 19:27:14.000000000 +0200
73 +++ conserver-8.1.15/conserver/consent.h 2007-01-19 22:30:12.482238000 +0100
75 FLAG autoreinit; /* auto-reinitialize if failed */
76 FLAG unloved; /* copy "unloved" data to stdout */
77 FLAG login; /* allow logins to the console */
78 + FLAG lock; /* lock the device */
80 /*** runtime settings ***/
81 CONSFILE *fdlog; /* the local log file */
82 diff -urN -x '*.orig' -x '*~' conserver-8.1.15.org/conserver/locks.c conserver-8.1.15/conserver/locks.c
83 --- conserver-8.1.15.org/conserver/locks.c 1970-01-01 01:00:00.000000000 +0100
84 +++ conserver-8.1.15/conserver/locks.c 2007-01-19 22:37:58.587367750 +0100
86 +#ident "$Id$ Copyright (c) Gert Doering / Paul Sutcliffe Jr."
88 +/* large parts of the code in this module are taken from the
89 + * "getty kit 2.0" by Paul Sutcliffe, Jr., paul@devon.lns.pa.us,
90 + * and are used with permission here.
91 + * SVR4 style locking by Bodo Bauer, bodo@hal.nbg.sub.org.
93 +/* adopted from mgetty 1.1.30 for conserver
94 + * by Sebastian Zagrodzki, s.zagrodzki@net.icm.edu.pl */
106 +#include <sys/types.h>
107 +#include <sys/stat.h>
110 +/* some OSes do include this in stdio.h, others don't... */
115 +/* SVR4 uses a different locking mechanism. This is why we need this... */
117 +#include <sys/mkdev.h>
119 +#define LCK_NODEV -1
120 +#define LCK_OPNFAIL -2
125 +int add_lock_to_list(char *device)
127 + s_ldev *temp_ldev, *ldev, *p_ldev = NULL;
129 + Debug(2, "add_lock: %s", device);
130 + for (ldev = locked_devices; ldev && strcmp(ldev->name, device);
131 + p_ldev = ldev, ldev = ldev->next);
133 + if (ldev) { /* we had it already */
134 + Msg("add_lock: That lock was already on my list");
138 + if (!(temp_ldev = (s_ldev *) malloc(sizeof(s_ldev))))
141 + if (!(temp_ldev->name = (char *) malloc(strlen(device)+1)))
144 + strcpy(temp_ldev->name, device);
145 + temp_ldev->next = NULL;
147 + p_ldev->next = temp_ldev;
149 + locked_devices = temp_ldev;
153 +int remove_lock_from_list(char *device)
155 + s_ldev *ldev, *p_ldev = NULL;
157 + Debug(2, "remove_lock: %s", device);
158 + for (ldev = locked_devices; ldev && strcmp(ldev->name, device);
159 + p_ldev = ldev, ldev = ldev->next);
161 + Msg("remove_lock: That lock wasn't on my list");
166 + p_ldev->next = ldev->next;
168 + locked_devices = ldev->next;
173 +int lock_is_on_list(char *device)
176 + for (ldev = locked_devices; ldev && strcmp(ldev->name, device);
177 + ldev = ldev->next);
179 + Debug(2, "lock_is_on_list: not found: %s", device);
182 + Debug(2, "lock_is_on_list: FOUND: %s", device);
189 + * makelock() - attempt to create a lockfile
191 + * Returns FAIL if lock could not be made (line in use).
194 +int makelock(char *device)
197 + char *temp, buf[MAXLINE+1];
199 + char lock[MAXLINE+1];
201 + s_ldev *ldev, *temp_ldev;
202 + Debug(2, "makelock: %s", device);
203 + for (ldev = locked_devices; ldev; ldev = ldev->next) {
204 + if (!strcmp(device, locked_devices->name)) {
205 + Msg("We already had a lock");
210 + if (get_lock_name(lock, device) == NULL) {
211 + Error("Cannot get lock filename");
214 + Debug(2, "makelock: lock='%s'", lock);
216 + /* first make a temp file */
219 + /* secure, but not as portable */
221 + sprintf(buf, LOCK, "TM.XXXXXX");
222 + if ((fd = mkstemp(temp)) == FAIL ) {
223 + Error("cannot create tempfile (%s)", temp);
227 + /* portable, but subject to some problems on some platforms */
229 + sprintf(buf, LOCK, "TM.XXXXXX");
230 + temp = mktemp(buf);
232 + if ((fd = open(temp, O_CREAT|O_WRONLY|O_EXCL, 0644)) == FAIL) {
233 + Error("cannot create tempfile (%s)", temp);
234 + if ( errno == EEXIST && ++tries < 20 ) goto again;
239 + /* just in case some "umask" is set (errors are ignored) */
240 + chmod( temp, 0644 );
242 + /* put my pid in it */
243 + if ( lock_write_pid( fd ) == FAIL)
244 + { unlink(temp); return FAIL; }
246 + /* link it to the lock file */
248 + while (link(temp, lock) == FAIL)
250 + if (errno != EEXIST )
252 + Error("lock not made: link(temp,lock) failed" );
255 + if (errno == EEXIST) /* lock file already there */
257 + if ((pid = readlock(lock)) == FAIL)
259 + if ( errno == ENOENT ) /* disappeared */
263 + Debug(2, "cannot read lockfile" );
269 + if (pid == getpid()) /* huh? WE locked the line!*/
271 + Msg("we *have* the line!" );
275 + if ((kill(pid, 0) == FAIL) && errno == ESRCH)
277 + /* pid that created lockfile is gone */
278 + Debug(2, "stale lockfile, created by process %d, ignoring", pid );
279 + if ( unlink(lock) < 0 &&
280 + errno != EINTR && errno != ENOENT )
282 + Error("unlink() failed, giving up" );
289 + Msg("lock not made: lock file exists (pid=%d)", pid);
290 + } /* if (errno == EEXIST) */
292 + (void) unlink(temp);
296 + Debug(2, "lock made");
297 + (void) unlink(temp);
299 + Msg("Locking device");
300 + add_lock_to_list(device);
305 + * checklock() - test for presence of valid lock file
307 + * if lockfile found, return PID of process holding it, 0 otherwise
310 +int checklock (char *device)
314 + char name[MAXLINE+1];
316 + if ( get_lock_name( name, device ) == NULL )
318 + Error("cannot get lock name" );
322 + if ((stat(name, &st) == FAIL) && errno == ENOENT)
324 + Debug(2, "checklock: stat failed, no file");
328 + if ((pid = readlock(name)) == FAIL)
330 + Msg("checklock: couldn't read lockfile");
334 + if (pid == getpid())
336 + Msg("huh? It's *our* lock file!" );
340 + if ((kill(pid, 0) == FAIL) && errno == ESRCH)
342 + Debug(2, "checklock: no active process has lock, will remove");
343 + (void) unlink(name);
347 + Debug(2, "lockfile found, pid=%d", pid );
353 + * readlock() - read contents of lockfile
355 + * Returns pid read or FAIL on error.
360 +int readlock (char *name)
366 + if ((fd = open(name, O_RDONLY)) == FAIL)
369 + length = read(fd, apid, sizeof(apid)-1);
370 + apid[length]=0; /* make sscanf() happy */
373 + if ( length == sizeof( pid ) || sscanf(apid, "%d", &pid) != 1 ||
376 + pid = * ( (int *) apid );
377 +#if LOCKS_BINARY == 0
378 + Msg("compiled with ascii locks, found binary lock file (length=%d, pid=%d)!", length, pid );
381 +#if LOCKS_BINARY == 1
384 + Msg("compiled with binary locks, found ascii lock file (length=%d, pid=%d)!", length, pid );
394 + * write contents of lock file: my process ID in specified format
398 +int lock_write_pid (int fd)
401 + int bpid; /* must be 4 bytes wide! */
403 + if ( write(fd, &bpid, sizeof(bpid) ) != sizeof(bpid) )
406 + sprintf( apid, "%10d\n", (int) getpid() );
407 + if ( write(fd, apid, strlen(apid)) != strlen(apid) )
410 + Error("cannot write PID to (temp) lock file" );
419 + * rmlocks() - remove lockfile
423 +void rmlocks(char *device)
425 + char lock[MAXLINE + 1];
426 + Debug(2, "rmlocks: %s", device);
427 + get_lock_name(lock, device);
428 + Debug(2, "rmlocks: lock: %s", lock);
429 + if (lock_is_on_list(device))
431 + Msg("Removing lock file" );
432 + if (unlink(lock) == -1 )
433 + Error("error removing lock file (huh?!)" );
434 + /* mark lock file as 'not set' */
435 + remove_lock_from_list(device);
441 + * determine full path + name of the lock file for a given device
447 + * get_lock_name() - create SVR4 lock file name (Bodo Bauer)
450 +char *get_lock_name (char* lock, char* fax_tty)
453 + char ttyname[FILENAME_MAX];
455 + Debug(2, "get_lock_name(%s) called", fax_tty);
457 + if ( strncmp( fax_tty, "/dev/", 5 ) == 0 )
458 + strcpy( ttyname, fax_tty );
460 + sprintf(ttyname, "/dev/%s", fax_tty);
462 + Debug(2, "-> ttyname %s", ttyname);
464 + if (stat(ttyname, &tbuf) < 0) {
465 + if(errno == ENOENT) {
466 + Debug(2, "device does not exist: %s", ttyname);
469 + Debug(2, "could not access line: %s", ttyname);
474 + sprintf(lock,"%s/LK.%03u.%03u.%03u",
476 + major(tbuf.st_dev),
477 + tbuf.st_rdev >> 18,
478 + minor(tbuf.st_rdev));
480 + Debug(2, "lock file: %s", lock);
484 +#else /* not SVR4 */
486 +char * get_lock_name (char * lock_name, char * device)
488 +#ifdef LOCKS_LOWERCASE
489 + /* sco locking convention -> change all device names to lowercase */
493 + if ( ( i = strlen( device ) ) > sizeof(p) )
495 + Error("get_lock_name: device name too long" );
499 +#ifdef LOCKS_ALL_LOWERCASE
500 + /* convert the full name */
503 + p[i] = tolower( device[i] ); i--;
506 + /* convert only the last character */
507 + strcpy( p, device );
509 + p[i] = tolower( p[i] );
513 +#endif /* LOCKS_LOWERCASE */
515 + /* throw out all directory prefixes */
516 + if ( strchr( device, '/' ) != NULL )
517 + device = strrchr( device, '/' ) +1;
519 + sprintf( lock_name, LOCK, device);
525 diff -urN -x '*.orig' -x '*~' conserver-8.1.15.org/conserver/locks.h conserver-8.1.15/conserver/locks.h
526 --- conserver-8.1.15.org/conserver/locks.h 1970-01-01 01:00:00.000000000 +0100
527 +++ conserver-8.1.15/conserver/locks.h 2007-01-19 22:29:33.687813500 +0100
530 +#define LOCK "/var/lock/LCK..%s"
531 +#define MAXLINE 1024
532 +#define FALSE (1==0)
539 +int makelock (char *device);
540 +// int makelock_file ( char * lockname );
541 +int checklock (char *device);
542 +RETSIGTYPE rmlocks ();
543 +// int steal_lock (char * device, int pid );
546 +typedef struct _s_ldev {
548 + struct _s_ldev *next;
551 +static s_ldev *locked_devices = NULL;
553 +int readlock (char *name);
554 +int makelock (char *name);
555 +char *get_lock_name (char *lock_name, char *device);
556 +int lock_write_pid (int fd);
559 diff -urN -x '*.orig' -x '*~' conserver-8.1.15.org/conserver/main.c conserver-8.1.15/conserver/main.c
560 --- conserver-8.1.15.org/conserver/main.c 2006-04-03 15:32:08.000000000 +0200
561 +++ conserver-8.1.15/conserver/main.c 2007-01-19 22:29:33.687813500 +0100
563 "DumpDataStructures(): motd=%s, idletimeout=%d, idlestring=%s",
564 EMPTYSTR(pCE->motd), pCE->idletimeout,
565 EMPTYSTR(pCE->idlestring)));
567 + "DumpDataStructures(): lock=%s",
568 + FLAGSTR(pCE->lock)));
571 for (u = pCE->ro; u != (CONSENTUSERS *)0; u = u->next) {
572 diff -urN -x '*.orig' -x '*~' conserver-8.1.15.org/conserver/Makefile.in conserver-8.1.15/conserver/Makefile.in
573 --- conserver-8.1.15.org/conserver/Makefile.in 2005-06-06 17:03:06.000000000 +0200
574 +++ conserver-8.1.15/conserver/Makefile.in 2007-01-19 22:29:33.683813250 +0100
576 ### Makefile rules - no user-servicable parts below
578 CONSERVER_OBJS = access.o client.o consent.o group.o main.o master.o \
579 - readcfg.o fallback.o cutil.o
580 + readcfg.o fallback.o cutil.o locks.o
581 CONSERVER_HDRS = ../config.h $(top_srcdir)/compat.h $(srcdir)/access.h \
582 $(srcdir)/client.h $(srcdir)/consent.h $(srcdir)/cutil.h \
583 $(srcdir)/group.h $(srcdir)/main.h $(srcdir)/master.h \
584 - $(srcdir)/readcfg.h $(srcdir)/version.h
585 + $(srcdir)/readcfg.h $(srcdir)/version.h $(srcdir)/locks.h
587 ALL = conserver convert
589 diff -urN -x '*.orig' -x '*~' conserver-8.1.15.org/conserver/readcfg.c conserver-8.1.15/conserver/readcfg.c
590 --- conserver-8.1.15.org/conserver/readcfg.c 2006-03-20 17:47:03.000000000 +0100
591 +++ conserver-8.1.15/conserver/readcfg.c 2007-01-19 22:32:03.149154250 +0100
593 c->unloved = d->unloved;
594 if (d->login != FLAGUNKNOWN)
596 + if (d->lock != FLAGUNKNOWN)
598 if (d->host != (char *)0) {
599 if (c->host != (char *)0)
601 @@ -1656,6 +1658,7 @@
602 c->autoreinit = FLAGUNKNOWN;
603 c->unloved = FLAGUNKNOWN;
604 c->login = FLAGUNKNOWN;
605 + c->lock = FLAGUNKNOWN;
609 @@ -1693,6 +1696,8 @@
610 c->unloved = negative ? FLAGFALSE : FLAGTRUE;
611 else if (strcasecmp("login", token) == 0)
612 c->login = negative ? FLAGFALSE : FLAGTRUE;
613 + else if (strcasecmp("lock", token) == 0)
614 + c->lock = negative ? FLAGFALSE : FLAGTRUE;
616 Error("invalid option `%s' [%s:%d]", token, file, line);
618 @@ -3007,6 +3012,7 @@
619 pCEmatch->autoreinit = c->autoreinit;
620 pCEmatch->unloved = c->unloved;
621 pCEmatch->login = c->login;
622 + pCEmatch->lock = c->lock;
623 pCEmatch->inituid = c->inituid;
624 pCEmatch->initgid = c->initgid;
625 while (pCEmatch->aliases != (NAMES *)0) {
626 @@ -3185,6 +3191,8 @@
628 if (c->ondemand == FLAGUNKNOWN)
629 c->ondemand = FLAGFALSE;
630 + if (c->lock == FLAGUNKNOWN)
631 + c->lock = FLAGFALSE;
632 if (c->reinitoncc == FLAGUNKNOWN)
633 c->reinitoncc = FLAGFALSE;
634 if (c->striphigh == FLAGUNKNOWN)
635 diff -urN -x '*.orig' -x '*~' conserver-8.1.15.org/conserver.cf/conserver.cf.man conserver-8.1.15/conserver.cf/conserver.cf.man
636 --- conserver-8.1.15.org/conserver.cf/conserver.cf.man 2006-12-31 03:03:03.000000000 +0100
637 +++ conserver-8.1.15/conserver.cf/conserver.cf.man 2007-01-19 22:29:33.691813750 +0100
643 +Lock the device using UUCP-style locks.
648 Strip the high bit off all data coming from this console and all clients
649 connected to this console before processing occurs.