/**************************************************************\ * * * Copyright (c) 1991 Gordian Inc. * * * * Author: Michael Thomas * * Module: ets$configd.c * * Created: Tue Jun 4 13:19:10 1991 * * Abstract: * * Main module for the ETS configuration daemon. * * * \**************************************************************/ /* Edit History: */ #include #include #include #include /* * The object of this daemon is field requests on the specified * LAT port which is of the dedicated variety. The protocol used * is *very* simple, in that a server connects to a service, specifies * the name of the file to read and we (if possible) just spew its * contents */ char * strchr (); char FNF [] = "%FNF, Can't open file.\n"; char NOACC [] = "%NOPERM, Can't open file.\n"; main () { char device [50]; char bf [512], * c; char rdir [256]; int fd, rfd, len; long tm; char user [30]; stat_t sb; time (&tm); fprintf (stderr, "Device: "); gets (device); fprintf (stderr, "Directory Restriction: "); gets (rdir); fprintf (stderr, "\r\nETS configurator daemon V1.0\n"); cuserid (user); fprintf (stderr, " o started by %s on %s", user, ctime (&tm)); if (rdir [0]) fprintf (stderr, " o restricted to directory %s\n", rdir); else fprintf (stderr, " o unrestricted access to world readable files\n\n"); fflush (stderr); while (1) { char fn [256]; if ((fd = open (device, O_RDWR)) < 0) { perror ("open"); exit (0); } time (&tm); len = read (fd, bf, 255); if (len <= 0) { if (len < 0) perror ("read"); close (fd); continue; } bf [len] = 0; if ((c = strchr (bf, '\r')) || (c = strchr (bf, '\n'))) * c = 0; if (rdir [0]) { if ((c = strrchr (bf, ']')) || (c = strrchr (bf, '>')) || (c = strrchr (bf, ':'))) { * c = 0; c++; } else c = bf; sprintf (fn, "%s%s", rdir, c); } else strcpy (fn, bf); if (stat (fn, &sb) < 0) { write (fd, FNF, sizeof (FNF)); fprintf (stderr, "can't stat %s @%s", fn, ctime (&tm)); perror ("stat"); close (fd); continue; } else { /* check permissions on the file for other (world) */ if ((sb.st_mode & 4) == 0) { fprintf (stderr, "no access to file %s @%s\n", fn, ctime(&tm)); write (fd, NOACC, sizeof (NOACC)); close (fd); continue; } } rfd = open (fn, O_RDONLY); if (rfd < 0) { fprintf (stderr, "can't open %s @%s", fn, ctime (&tm)); write (fd, FNF, sizeof (FNF)); perror ("openread"); close (fd); continue; } fprintf (stderr, "Opened %s @%s", fn, ctime (&tm)); while ((len = read (rfd, bf, 512)) > 0) { if (write (fd, bf, len) < 0) { perror ("write"); break; } } close (rfd); close (fd); fflush (stderr); } }