home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / 3b1 / volume02 / uucpd / part01 < prev    next >
Encoding:
Text File  |  1993-09-07  |  10.3 KB  |  374 lines

  1. Path: comp-sources-3b1
  2. From: Uucp Admins against ATnT <uucpadm@becker.GTS.ORG>
  3. Subject:  v02i042:  uucpd for 3B1 TCP/IP, Part01/01
  4. Newsgroups: comp.sources.3b1
  5. Approved: dave@galaxia.network23.com
  6. X-Checksum-Snefru: 86ee5d56 63523a77 55b692ee 56ca18a1
  7.  
  8. Submitted-by: Uucp Admins against ATnT <uucpadm@becker.GTS.ORG>
  9. Posting-number: Volume 2, Issue 42
  10. Archive-name: uucpd/part01
  11.  
  12. [ This was originally submitted with a copy of the binary enclosed.  Since ]
  13. [ this is a *sources* group I did not want to post the binary.  After      ]
  14. [ exchaning a couple of letters with the submittor, it was agreed to post  ]
  15. [ the source code only and make the binary available in the archives.  By  ]
  16. [ the time you see this, the binary will be available on both uunet and    ]
  17. [ OSU in the file "att7300/networking/uucpd.Z".                            ]
  18. [ -- Dave
  19.  
  20.  
  21. Here's uucpd for 3B1 TCP/IP (you need the TCP/IP
  22. software & ethernet card for this of course).  It's
  23. probably portable to most System V sockets-based
  24. TCP/IP as well, but it may need some tweaks to
  25. make it work elsewhere (there are better versions
  26. for BSD-based unices, so this wouldn't necessarily
  27. be too great a place to start for those).
  28.  
  29.  
  30. Make the directory "uucpd" in your source directory
  31. and unshar this into it.  Check "makeit" to see that
  32. the desired C compiler is invoked ("shcc" is what's
  33. supplied) and compile, if you don't want to use the
  34. given compressed uuencoded binary.
  35.  
  36.  
  37. Copy the executable into "/usr/ethernet/daemons"
  38. and then add this line to "/etc/lddrv/ether.rc":
  39.  
  40.  
  41.     /usr/ethernet/daemons/uucpd
  42.  
  43.  
  44. and add this line to "/etc/services":
  45.  
  46.  
  47.     uucp        540/tcp        uucpd    # uucp daemon
  48.  
  49.  
  50. Then the next time you start up ethernet you'll have
  51. a uucp daemon that will handle up to 3 simultaneous
  52. sessions (if ethernet is already active you can just
  53. invoke the uucpd daemon directly).
  54.  
  55.  
  56. #! /bin/sh
  57. # This is a shell archive.  Remove anything before this line, then unpack
  58. # it by saving it into a file and typing "sh file".  To overwrite existing
  59. # files, type "sh file -c".  You can also feed this as standard input via
  60. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  61. # will see the following message at the end:
  62. #        "End of shell archive."
  63. # Contents:  makeit uucpd.c
  64. # Wrapped by dave@galaxia on Tue Sep  7 20:53:10 1993
  65. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  66. if test -f 'makeit' -a "${1}" != "-c" ; then 
  67.   echo shar: Will not clobber existing file \"'makeit'\"
  68. else
  69. echo shar: Extracting \"'makeit'\" \(121 characters\)
  70. sed "s/^X//" >'makeit' <<'END_OF_FILE'
  71. Xshcc -I/usr/ethernet/include -DSHORT_IDENT -DSYSTEM5 -c uucpd.c
  72. Xif [ $? -eq 0 ]; then shcc -s -o uucpd uucpd.o -lnet; fi
  73. END_OF_FILE
  74. if test 121 -ne `wc -c <'makeit'`; then
  75.     echo shar: \"'makeit'\" unpacked with wrong size!
  76. fi
  77. chmod +x 'makeit'
  78. # end of 'makeit'
  79. fi
  80. if test -f 'uucpd.c' -a "${1}" != "-c" ; then 
  81.   echo shar: Will not clobber existing file \"'uucpd.c'\"
  82. else
  83. echo shar: Extracting \"'uucpd.c'\" \(6908 characters\)
  84. sed "s/^X//" >'uucpd.c' <<'END_OF_FILE'
  85. X/*
  86. X * Copyright (c) 1985 The Regents of the University of California.
  87. X * All rights reserved.
  88. X *
  89. X * This code is derived from software contributed to Berkeley by
  90. X * Rick Adams.
  91. X *
  92. X * Redistribution and use in source and binary forms, with or without
  93. X * modification, are permitted provided that the following conditions
  94. X * are met:
  95. X * 1. Redistributions of source code must retain the above copyright
  96. X *    notice, this list of conditions and the following disclaimer.
  97. X * 2. Redistributions in binary form must reproduce the above copyright
  98. X *    notice, this list of conditions and the following disclaimer in the
  99. X *    documentation and/or other materials provided with the distribution.
  100. X * 3. All advertising materials mentioning features or use of this software
  101. X *    must display the following acknowledgement:
  102. X *    This product includes software developed by the University of
  103. X *    California, Berkeley and its contributors.
  104. X * 4. Neither the name of the University nor the names of its contributors
  105. X *    may be used to endorse or promote products derived from this software
  106. X *    without specific prior written permission.
  107. X *
  108. X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  109. X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  110. X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  111. X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  112. X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  113. X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  114. X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  115. X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  116. X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  117. X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  118. X * SUCH DAMAGE.
  119. X */
  120. X
  121. X#ifndef lint
  122. Xchar copyright[] =
  123. X"@(#) Copyright (c) 1985 The Regents of the University of California.\n\
  124. X All rights reserved.\n";
  125. X#endif /* not lint */
  126. X
  127. X#ifndef lint
  128. Xstatic char sccsid[] = "@(#)uucpd.c    5.10 (Berkeley) 2/26/91";
  129. X#endif /* not lint */
  130. X
  131. X/*
  132. X * 4.2BSD TCP/IP server for uucico
  133. X * uucico's TCP channel causes this server to be run at the remote end.
  134. X */
  135. X
  136. X#include <sys/types.h>
  137. X#include <sys/wait.h>
  138. X#include <sys/ioctl.h>
  139. X#include <sys/socket.h>
  140. X#include <netinet/in.h>
  141. X#include <arpa/inet.h>
  142. X#include <netdb.h>
  143. X#include <signal.h>
  144. X#include <fcntl.h>
  145. X#include <time.h>
  146. X#include <pwd.h>
  147. X#include <unistd.h>
  148. X#include <errno.h>
  149. X#include <stdio.h>
  150. X#include <string.h>
  151. X#include <utmp.h>
  152. X
  153. X#define    _PATH_UUCICO    "/usr/lib/uucp/uucico"
  154. X
  155. Xstruct    utmp utmp;
  156. Xstruct    sockaddr_in hisctladdr;
  157. Xint hisaddrlen = sizeof hisctladdr;
  158. Xstruct    sockaddr_in myctladdr;
  159. X
  160. X#define BACKLOG    3
  161. X
  162. X#define    SCPYN(a, b)    strncpy(a, b, sizeof (a))
  163. X
  164. Xchar Username[64];
  165. Xchar *nenv[] = {
  166. X    Username,
  167. X    NULL,
  168. X};
  169. Xextern char **environ;
  170. X
  171. Xmain(argc, argv)
  172. Xint argc;
  173. Xchar **argv;
  174. X{
  175. X    register int s, tcp_socket;
  176. X    struct servent *sp;
  177. X    extern int errno;
  178. X    int dologout();
  179. X    int wtmp;
  180. X
  181. X    environ = nenv;
  182. X    sp = getservbyname("uucp", "tcp");
  183. X    if (sp == NULL){
  184. X        perror("uucpd: getservbyname");
  185. X        exit(1);
  186. X    }
  187. X    switch (fork()) {
  188. X    case -1:    perror("uucpd: fork"); exit(1);
  189. X    case  0:    break;
  190. X    default:    exit(0);
  191. X    }
  192. X
  193. X    if (setpgrp() == -1) {
  194. X        perror("uucpd: setpgrp");
  195. X        exit(1);
  196. X    }
  197. X
  198. X    bzero((char *)&myctladdr, sizeof (myctladdr));
  199. X    myctladdr.sin_family = AF_INET;
  200. X    myctladdr.sin_port = sp->s_port;
  201. X    tcp_socket = socket(AF_INET, SOCK_STREAM, 0);
  202. X    if (tcp_socket < 0) {
  203. X        perror("uucpd: socket");
  204. X        exit(1);
  205. X    }
  206. X    if (bind(tcp_socket, (char *)&myctladdr, sizeof (myctladdr)) < 0) {
  207. X        perror("uucpd: bind");
  208. X        exit(1);
  209. X    }
  210. X
  211. X    listen(tcp_socket, BACKLOG);    /* at most 3 simultaneous connections */
  212. X    signal(SIGCLD, dologout);
  213. X    wtmp = open(WTMP_FILE, O_WRONLY|O_APPEND);
  214. X    if (wtmp >= 0) {
  215. X        SCPYN(utmp.ut_user, "LOGIN");
  216. X        SCPYN(utmp.ut_id, "");
  217. X        SCPYN(utmp.ut_line, "uucpd");
  218. X        utmp.ut_pid = getpid();
  219. X        utmp.ut_type = LOGIN_PROCESS;
  220. X        utmp.ut_exit.e_termination = 0;
  221. X        utmp.ut_exit.e_exit = 0;
  222. X        time(&utmp.ut_time);
  223. X        (void) write(wtmp, (char *)&utmp, sizeof (utmp));
  224. X        (void) close(wtmp);
  225. X    }
  226. X
  227. X    for(;;) {
  228. X        s = accept(tcp_socket, &hisctladdr, &hisaddrlen);
  229. X        if (s < 0){
  230. X            if (errno == EINTR) 
  231. X                continue;
  232. X            perror("uucpd: accept");
  233. X            exit(1);
  234. X        }
  235. X        if (fork() == 0) {
  236. X            close(0); close(1); close(2);
  237. X            dup(s); dup(s); dup(s);
  238. X            close(tcp_socket); close(s);
  239. X            doit();
  240. X            exit(1);
  241. X        }
  242. X        close(s);
  243. X    }
  244. X
  245. X}
  246. X
  247. Xdoit()
  248. X{
  249. X    char user[64], passwd[64];
  250. X    char *xpasswd, *crypt();
  251. X    struct passwd *pw, *getpwnam();
  252. X
  253. X    alarm(60);
  254. X    printf("login: "); fflush(stdout);
  255. X    if (readline(user, sizeof user) < 0) {
  256. X        fprintf(stderr, "user read\n");
  257. X        return;
  258. X    }
  259. X    /* truncate username to 8 characters */
  260. X    user[8] = '\0';
  261. X    pw = getpwnam(user);
  262. X    if (pw == NULL) {
  263. X        fprintf(stderr, "user unknown\n");
  264. X        return;
  265. X    }
  266. X    if (strcmp(pw->pw_shell, _PATH_UUCICO)) {
  267. X        fprintf(stderr, "Login incorrect.");
  268. X        return;
  269. X    }
  270. X    if (pw->pw_passwd && *pw->pw_passwd != '\0') {
  271. X        printf("Password: "); fflush(stdout);
  272. X        if (readline(passwd, sizeof passwd) < 0) {
  273. X            fprintf(stderr, "passwd read\n");
  274. X            return;
  275. X        }
  276. X        xpasswd = crypt(passwd, pw->pw_passwd);
  277. X        if (strcmp(xpasswd, pw->pw_passwd)) {
  278. X            fprintf(stderr, "Login incorrect.");
  279. X            return;
  280. X        }
  281. X    }
  282. X    alarm(0);
  283. X    sprintf(Username, "LOGNAME=%s", user);
  284. X    dologin(pw);
  285. X    setgid(pw->pw_gid);
  286. X    chdir(pw->pw_dir);
  287. X    setuid(pw->pw_uid);
  288. X    execl(_PATH_UUCICO, "uucico", (char *)0);
  289. X    perror("uucico server: execl");
  290. X}
  291. X
  292. Xreadline(p, n)
  293. Xregister char *p;
  294. Xregister int n;
  295. X{
  296. X    char c;
  297. X
  298. X    while (n-- > 0) {
  299. X        if (read(0, &c, 1) <= 0)
  300. X            return(-1);
  301. X        c &= 0177;
  302. X        if (c == '\n' || c == '\r') {
  303. X            *p = '\0';
  304. X            return(0);
  305. X        }
  306. X        *p++ = c;
  307. X    }
  308. X    return(-1);
  309. X}
  310. X
  311. Xdologout()
  312. X{
  313. X    int  status;
  314. X    int pid, wtmp;
  315. X
  316. X    while ((pid=wait(&status)) > 0) {
  317. X        wtmp = open(WTMP_FILE, O_WRONLY|O_APPEND);
  318. X        if (wtmp >= 0) {
  319. X            SCPYN(utmp.ut_user, "");
  320. X            SCPYN(utmp.ut_id, "");
  321. X            SCPYN(utmp.ut_line, "uucpd");
  322. X            utmp.ut_pid = pid;
  323. X            utmp.ut_type = DEAD_PROCESS;
  324. X            utmp.ut_exit.e_termination = status & 0xff;
  325. X            utmp.ut_exit.e_exit = (status>>8) & 0xff;
  326. X            (void) time(&utmp.ut_time);
  327. X            (void) write(wtmp, (char *)&utmp, sizeof (utmp));
  328. X            SCPYN(utmp.ut_user, "LOGIN");
  329. X            utmp.ut_pid = getpid();
  330. X            utmp.ut_type = LOGIN_PROCESS;
  331. X            utmp.ut_exit.e_termination = 0;
  332. X            utmp.ut_exit.e_exit = 0;
  333. X            time(&utmp.ut_time);
  334. X            (void) write(wtmp, (char *)&utmp, sizeof (utmp));
  335. X            (void) close(wtmp);
  336. X        }
  337. X    }
  338. X    signal(SIGCLD, dologout);
  339. X}
  340. X
  341. X/*
  342. X * Record login in wtmp file.
  343. X */
  344. Xdologin(pw)
  345. Xstruct passwd *pw;
  346. X{
  347. X    int wtmp;
  348. X
  349. X    wtmp = open(WTMP_FILE, O_WRONLY|O_APPEND);
  350. X    if (wtmp >= 0) {
  351. X        SCPYN(utmp.ut_user, pw->pw_name);
  352. X        SCPYN(utmp.ut_id, "");
  353. X        SCPYN(utmp.ut_line, "uucpd");
  354. X        utmp.ut_pid = getpid();
  355. X        utmp.ut_type = USER_PROCESS;
  356. X        utmp.ut_exit.e_termination = 0;
  357. X        utmp.ut_exit.e_exit = 0;
  358. X        time(&utmp.ut_time);
  359. X        (void) write(wtmp, (char *)&utmp, sizeof (utmp));
  360. X        (void) close(wtmp);
  361. X    }
  362. X}
  363. END_OF_FILE
  364. if test 6908 -ne `wc -c <'uucpd.c'`; then
  365.     echo shar: \"'uucpd.c'\" unpacked with wrong size!
  366. fi
  367. # end of 'uucpd.c'
  368. fi
  369. echo shar: End of shell archive.
  370. exit 0
  371. -- 
  372. David H. Brierley                            Work: dhb@ssd.ray.com
  373. 3B1 Hacker Extraordinaire                    Home: dave@galaxia.network23.com
  374.