home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume40 / ypx / part01 < prev    next >
Encoding:
Text File  |  1993-10-10  |  26.9 KB  |  953 lines

  1. Newsgroups: comp.sources.misc
  2. From: rob@wzv.win.tue.nl (Rob J. Nauta)
  3. Subject: v40i002:  ypx - transfer NIS maps beyond local network, Part01/01
  4. Message-ID: <1993Oct10.153951.14461@sparky.sterling.com>
  5. X-Md4-Signature: ff51797854ddfe5eb22e25653842cb6f
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Sterling Software
  8. Date: Sun, 10 Oct 1993 15:39:51 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: rob@wzv.win.tue.nl (Rob J. Nauta)
  12. Posting-number: Volume 40, Issue 2
  13. Archive-name: ypx/part01
  14. Environment: UNIX
  15.  
  16. YPX - A utility to transfer NIS maps beyond a local (broadcast) network.
  17.  
  18. ypx is a utility to transfer a NIS map from any host running a ypserv
  19. daemon. ypx is similar to ypcat, with some additions. To be able to 
  20. transfer a map, a domainname must be specified.  There unfortunately 
  21. is no way to ask the remote host about its domainname, so it must be 
  22. known already or guessed to transfer a map successfully. If none 
  23. is specified, the hostname of the remote host is used as the domainname.
  24. ypx is able to guess at the remote domainname, by trying parts of 
  25. the hostname, if guessing is enabled with the -g option. If the -s 
  26. option is used, ypx will connect to the sendmail daemon, read the 
  27. hostname, and parse that too, to be used as additional guesses. 
  28. Finally, any additional strings on the commandline will be added to 
  29. the list of domainname guesses.
  30.  
  31. Disclaimer
  32. ----------
  33. Warning ! I am not responsible for the use, or the failure to use 
  34. this program. Use at your own risk. Some uses of this program may 
  35. break existing local laws. Like any tool, illegal actions are not 
  36. the responsibility of the writer of the program, but of the user 
  37. who runs it. If you take the time to read the source, you'll find 
  38. that the internals are very simple. Anyone could write such a program, 
  39. many have already done this.
  40.  
  41. This version is basically unchanged since 1991. If you still find
  42. any bugs, please mail them to rob@wzv.win.tue.nl.
  43.  
  44. Rob J. Nauta
  45. ---------------------------------------------------------------------------
  46. #! /bin/sh
  47. # This is a shell archive.  Remove anything before this line, then unpack
  48. # it by saving it into a file and typing "sh file".  To overwrite existing
  49. # files, type "sh file -c".  You can also feed this as standard input via
  50. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  51. # will see the following message at the end:
  52. #        "End of archive 1 (of 1)."
  53. # Contents:  MANIFEST Makefile README nhost.c nhost.h yp-check.c
  54. #   ypx-add.c ypx-add.h ypx-boot.c ypx-func.c ypx-main.c ypx-sm.c
  55. #   ypx.1
  56. # Wrapped by rob@wzv on Wed Oct  6 22:25:16 1993
  57. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  58. if test -f MANIFEST -a "${1}" != "-c" ; then 
  59.   echo shar: Will not over-write existing file \"MANIFEST\"
  60. else
  61. echo shar: Extracting \"MANIFEST\" \(504 characters\)
  62. sed "s/^X//" >MANIFEST <<'END_OF_MANIFEST'
  63. X   File Name        Archive #    Description
  64. X-----------------------------------------------------------
  65. X MANIFEST                  1    This shipping list
  66. X Makefile                  1    
  67. X README                    1    
  68. X nhost.c                   1    
  69. X nhost.h                   1    
  70. X yp-check.c                1    
  71. X ypx-add.c                 1    
  72. X ypx-add.h                 1    
  73. X ypx-boot.c                1    
  74. X ypx-func.c                1    
  75. X ypx-main.c                1    
  76. X ypx-sm.c                  1    
  77. X ypx.1                     1    
  78. END_OF_MANIFEST
  79. if test 504 -ne `wc -c <MANIFEST`; then
  80.     echo shar: \"MANIFEST\" unpacked with wrong size!
  81. fi
  82. # end of overwriting check
  83. fi
  84. if test -f Makefile -a "${1}" != "-c" ; then 
  85.   echo shar: Will not over-write existing file \"Makefile\"
  86. else
  87. echo shar: Extracting \"Makefile\" \(540 characters\)
  88. sed "s/^X//" >Makefile <<'END_OF_Makefile'
  89. X#
  90. X# Makefile voor de diverse testprogramma's in deze directory.
  91. X#
  92. XCFLAGS =    -g    # For debugging
  93. X#CFLAGS =    -O3        # For final version
  94. X
  95. Xall:    ypx doc yp.chk
  96. X
  97. Xclean:
  98. X    rm -f a.out core *.BAK *.o ypx yp.chk MANIFEST*
  99. X
  100. X# modules
  101. X
  102. Xypx:        ypx-main.o ypx-func.o ypx-add.o ypx-sm.o nhost.o
  103. X    cc ${CFLAGS} -o ypx ypx-main.o ypx-func.o ypx-add.o ypx-sm.o nhost.o
  104. X
  105. Xyp.chk:        yp-check.o ypx-sm.o nhost.o
  106. X    cc $(CFLAGS) -o yp.chk yp-check.o ypx-sm.o nhost.o
  107. X
  108. Xdoc:    ypx.1
  109. X    nroff -man ypx.1 >ypx.doc
  110. X
  111. Xshar:        clean
  112. X    umask 077
  113. X    makekit -m README Makefile *.c *.h ypx.1
  114. END_OF_Makefile
  115. if test 540 -ne `wc -c <Makefile`; then
  116.     echo shar: \"Makefile\" unpacked with wrong size!
  117. fi
  118. # end of overwriting check
  119. fi
  120. if test -f README -a "${1}" != "-c" ; then 
  121.   echo shar: Will not over-write existing file \"README\"
  122. else
  123. echo shar: Extracting \"README\" \(2437 characters\)
  124. sed "s/^X//" >README <<'END_OF_README'
  125. X
  126. X
  127. XYPX - A utility to transfer NIS maps beyond a local network.
  128. X
  129. XIntroduction
  130. X------------
  131. Xypx is a utility which I wrote about a year ago, when I was studying
  132. Xthe Network Programming manual, as an experiment. Since older copies I
  133. Xsent to a couple of friends seem to be spreading fast, I've decided to
  134. Xpost it to alt.sources.
  135. X
  136. XDisclaimer
  137. X----------
  138. XWarning ! I am not responsible for the use, or the failure to use this
  139. Xprogram. Use at your own risk. Overenthousiastic use of this program
  140. Xmight break existing local laws. Like any tool, illegal actions are not
  141. Xthe responsibility of the writer of the program, but of the user who
  142. Xruns it. If you take the time to read the source, you'll find that the
  143. Xinternals are very simple. Anyone could write such a program, many have
  144. Xalready done this.
  145. X
  146. XInstalling and running ypx
  147. X--------------------------
  148. XUnpack the source (either a shar file or .zip file) in a directory, and
  149. Xtype 'make'. If make gives any warnings or errors, please send mail to
  150. Xthe adress below, so I can make the next release more portable. The
  151. Xmake step will produce the "ypx" binary, ready to run.
  152. X
  153. XDocumentation
  154. X-------------
  155. XA short document describes the command line options, it's called
  156. X"ypx.1".  This document is in the standard manual page format. The make
  157. Xstep will convert this file to an ASCII file called "ypx.doc". Install
  158. X"ypx.1" in a directory where man(1) can find it, optionally.
  159. X
  160. XThe future
  161. X----------
  162. XSince this is a first release, bugfixes and improvements will undoubtably
  163. Xfollow. Some ideas for improvements are:
  164. X- Find out how to transfer a map if the domainname is unknown.
  165. X- Avoid the portmapper by scanning a range of port numbers.
  166. X- Anything else I can think of.
  167. X
  168. XProgress is also made in effort to protect your system from NIS map
  169. Xtransfers by unauthorized individuals with unknown motives.
  170. X- SUN will soon publish a bugfix, which contains new binaries for
  171. Xypserv and other programs, to add access control.
  172. X- Wietse Venema, the world's #1 security expert, has released a
  173. Xversion of portmap.c with access control similar to his exellent
  174. Xtcpwrapper package. It is probably ftp'able from cert.sei.cmu.edu
  175. Xand ftp.win.tue.nl. His email adress is wietse@wzv.win.tue.nl.
  176. X
  177. XComments
  178. X--------
  179. XAny comments and suggestions are welcome. Send mail to:
  180. Xrob@wzv.win.tue.nl. I'll be happy to hear from you.
  181. X
  182. XReferences
  183. X----------
  184. XNetwork Programming manual from SunOS 4.1
  185. X/usr/include/rpcsvc/yp*
  186. X
  187. XRob J. Nauta
  188. X
  189. END_OF_README
  190. if test 2437 -ne `wc -c <README`; then
  191.     echo shar: \"README\" unpacked with wrong size!
  192. fi
  193. # end of overwriting check
  194. fi
  195. if test -f nhost.c -a "${1}" != "-c" ; then 
  196.   echo shar: Will not over-write existing file \"nhost.c\"
  197. else
  198. echo shar: Extracting \"nhost.c\" \(2553 characters\)
  199. sed "s/^X//" >nhost.c <<'END_OF_nhost.c'
  200. X/* nhost.c 2.3 dd. aug 13 1992        (c) Copyright 1991,1992 Rob J. Nauta.
  201. X * This module contains the findhost(), getsock() and opensock() functions.
  202. X * findhost() returns the official name of a host, indicated by a name or
  203. X * number. findhost2() returns a struct hostent *, and is meant to replace
  204. X * findhost. getsock() returns a struct sockaddr_in *, with the relevant
  205. X * fields filled with the internet number of the host. opensock() opens a
  206. X * socket to a given port on a given host. */
  207. X#include <stdio.h>
  208. X#include <sys/types.h>
  209. X#include <sys/socket.h>
  210. X#include <netinet/in.h>
  211. X#include <netdb.h>
  212. X#ifndef lint
  213. Xstatic char idstr[] = "@(#)nhost.c 2.1 91/11/20 RJN\n\
  214. X        (c) Copyright 1991 Fidelio Software. All rights reserved.\n";
  215. X#endif
  216. X
  217. Xstruct hostent *
  218. Xfindhost2(host)            /* Find a real hostname for the argument */
  219. Xchar *host;
  220. X{
  221. X    struct hostent *hp;
  222. X    unsigned long num;
  223. X
  224. X    if ((hp = gethostbyname(host)) == NULL) {
  225. X        num = inet_addr(host);    /* Try the number */
  226. X        if ((hp = gethostbyaddr(&num, sizeof(num), 0)) == NULL)
  227. X            return (NULL);
  228. X    }
  229. X    return (hp);
  230. X}
  231. X
  232. Xchar *
  233. Xfindhost(host)
  234. Xchar *host;
  235. X{
  236. X    struct hostent *hp;
  237. X
  238. X    if (hp = findhost2(host))
  239. X        return (hp->h_name);
  240. X    fprintf(stderr, "can't get adress for %s\n", host);
  241. X    return (NULL);
  242. X}
  243. X
  244. Xstruct sockaddr_in *
  245. Xgetsock(arg)
  246. Xchar *arg;
  247. X{
  248. X    static struct sockaddr_in sin;
  249. X    static struct hostent *hp;
  250. X
  251. X    sin.sin_addr.s_addr = inet_addr(arg);
  252. X    if (sin.sin_addr.s_addr != -1) {
  253. X        /* arg is aaa.bbb.ccc.ddd, so fill sin with data */
  254. X        sin.sin_family = AF_INET;
  255. X        return (&sin);
  256. X    }
  257. X    /* argument is probably a hostname */
  258. X    hp = gethostbyname(arg);
  259. X    if (hp) {
  260. X        /* Hostname lookup was successfull */
  261. X        sin.sin_family = hp->h_addrtype;
  262. X#if defined(h_addr)        /* In 4.3, this is a #define */
  263. X        memcpy((caddr_t) & sin.sin_addr,
  264. X               hp->h_addr_list[0], hp->h_length);
  265. X#else                /* defined(h_addr) */
  266. X        memcpy((caddr_t) & sin.sin_addr,
  267. X               hp->h_addr, hp->h_length);
  268. X#endif                /* defined(h_addr) */
  269. X        sin.sin_family = AF_INET;
  270. X        return (&sin);
  271. X    }
  272. X    fprintf(stderr, "Can't find %s !\n", arg);
  273. X    return (NULL);        /* Nothing found */
  274. X}
  275. X
  276. X/* opensock - open a stream connection to a port on a host. Returns -1 on
  277. X * failure, with errno set. */
  278. Xopensock(hostname, portnum)
  279. Xchar *hostname;
  280. Xint portnum;
  281. X{
  282. X    struct sockaddr_in *sp;
  283. X    int s;
  284. X
  285. X    if ((sp = getsock(hostname)) == NULL)
  286. X        return (-1);    /* Unknown host */
  287. X
  288. X    sp->sin_port = htons((u_short) portnum);
  289. X    if ((s = socket(sp->sin_family, SOCK_STREAM, 0)) < 0)
  290. X        return (-1);
  291. X    if (connect(s, sp, sizeof(*sp)) < 0) {
  292. X        close(s);
  293. X        return (-1);
  294. X    }
  295. X    return (s);        /* Success */
  296. X}
  297. END_OF_nhost.c
  298. if test 2553 -ne `wc -c <nhost.c`; then
  299.     echo shar: \"nhost.c\" unpacked with wrong size!
  300. fi
  301. # end of overwriting check
  302. fi
  303. if test -f nhost.h -a "${1}" != "-c" ; then 
  304.   echo shar: Will not over-write existing file \"nhost.h\"
  305. else
  306. echo shar: Extracting \"nhost.h\" \(122 characters\)
  307. sed "s/^X//" >nhost.h <<'END_OF_nhost.h'
  308. Xextern char *findhost();
  309. Xextern struct hostent *findhost2();
  310. Xextern struct sockaddr_in *getsock();
  311. Xextern int opensock();
  312. END_OF_nhost.h
  313. if test 122 -ne `wc -c <nhost.h`; then
  314.     echo shar: \"nhost.h\" unpacked with wrong size!
  315. fi
  316. # end of overwriting check
  317. fi
  318. if test -f yp-check.c -a "${1}" != "-c" ; then 
  319.   echo shar: Will not over-write existing file \"yp-check.c\"
  320. else
  321. echo shar: Extracting \"yp-check.c\" \(2779 characters\)
  322. sed "s/^X//" >yp-check.c <<'END_OF_yp-check.c'
  323. X/* YP security checker. Meant as an addition to COPS. */
  324. X
  325. X#include <stdio.h>
  326. X#include <rpc/rpc.h>
  327. X#include <rpcsvc/yp_prot.h>
  328. X#include "nhost.h"
  329. X#ifndef lint
  330. Xstatic char *copyright = "@(#)yp-check.c 1.0 92/05/10 Rob J. Nauta\n";
  331. X#endif
  332. X
  333. Xchar *get_smname();
  334. Xchar *defaultdomain, *programname;
  335. X
  336. XCLIENT *
  337. Xrpc_yp_client(arg, thisport)
  338. Xchar *arg;
  339. Xint thisport;
  340. X{
  341. X    char myhost[100];
  342. X    struct sockaddr_in *server_addr;
  343. X    int sock = RPC_ANYSOCK, klad = 0;
  344. X    CLIENT *client;
  345. X
  346. X    if (gethostname(myhost, 100))    /* Get our own hostname */
  347. X        perror(programname);
  348. X    server_addr = getsock(arg);    /* Get adress info */
  349. X    if (server_addr == NULL)
  350. X        return (NULL);
  351. X    server_addr->sin_port = thisport;    /* Normally 0 (= portmapper) */
  352. X
  353. X    if ((client = clnttcp_create(server_addr, YPPROG, YPVERS,
  354. X                     &sock, 0, 0)) == NULL) {
  355. X        clnt_pcreateerror(programname);
  356. X        return (NULL);    /* Failure */
  357. X    }
  358. X    client->cl_auth = authunix_create(myhost, 0, 0, 1, &klad);
  359. X    return (client);    /* Success */
  360. X}
  361. X
  362. Xmain(argc, argv)
  363. Xint argc;
  364. Xchar *argv[];
  365. X{
  366. X    int c;
  367. X    int debug = 0, errflg = 0;
  368. X    int thisport = 0;
  369. X    char *hostname;
  370. X    char which[256];
  371. X    FILE *P;
  372. X    extern int optind;
  373. X    extern char *optarg;
  374. X    CLIENT *client;        /* Client pointer */
  375. X
  376. X    programname = argv[0];
  377. X    while ((c = getopt(argc, argv, "d?")) != EOF)
  378. X        switch (c) {
  379. X            case 'd':    /* debug */
  380. X            debug++;
  381. X            break;
  382. X            case '?':    /* help */
  383. X            default:
  384. X            errflg++;
  385. X            break;
  386. X        }
  387. X    if (optind > argc)
  388. X        errflg++;
  389. X    if (errflg) {
  390. X        fprintf(stderr, "Usage:    %s [-d]  [domainname ...]\n",
  391. X            programname);
  392. X        exit(1);
  393. X    }
  394. X    yp_get_default_domain(&defaultdomain);
  395. X    if (debug)
  396. X        fprintf(stderr, "The default domainname is: %s\n",
  397. X            defaultdomain);
  398. X
  399. X    if ((P = popen("ypwhich", "r")) == NULL) {
  400. X        perror(argv[0]);
  401. X        exit(1);
  402. X    }
  403. X    fscanf(P, "%s", which);
  404. X    if (strcmp(which, "ypwhich:") == NULL) {
  405. X        /* Very ugly kludge, but this is to keep it simple */
  406. X        fprintf(stderr, "%s: Error running ypwhich.\n", argv[0]);
  407. X        exit(1);
  408. X    }
  409. X    if (debug)
  410. X        fprintf(stderr, "The current NIS server is: %s\n", which);
  411. X    client = rpc_yp_client(which, thisport);
  412. X    if (client == NULL)
  413. X        exit(2);    /* Host not found, or no ypserv */
  414. X    hostname = get_smname(which, debug);
  415. X    if (debug)
  416. X        fprintf(stderr, "Sendmail on that machine says its hostname is: %s\n", hostname);
  417. X
  418. X    /* Now test whether the domainname is too obvious */
  419. X    if (strstr(which, defaultdomain)) {
  420. X        printf("Warning!  The NIS domainname (%s)\n      is part of the NIS server's hostname (%s) !\n", defaultdomain, which);
  421. X        return (0);
  422. X    }
  423. X    if (strstr(hostname, defaultdomain)) {
  424. X        printf("Warning!  The NIS domainname (%s)\n      is part of the NIS server's hostname (%s) !\n", defaultdomain, hostname);
  425. X        return (0);
  426. X    }
  427. X    auth_destroy(client->cl_auth);    /* Free authorization struct */
  428. X    clnt_destroy(client);    /* Free client structure */
  429. X    return (0);
  430. X}
  431. END_OF_yp-check.c
  432. if test 2779 -ne `wc -c <yp-check.c`; then
  433.     echo shar: \"yp-check.c\" unpacked with wrong size!
  434. fi
  435. # end of overwriting check
  436. fi
  437. if test -f ypx-add.c -a "${1}" != "-c" ; then 
  438.   echo shar: Will not over-write existing file \"ypx-add.c\"
  439. else
  440. echo shar: Extracting \"ypx-add.c\" \(558 characters\)
  441. sed "s/^X//" >ypx-add.c <<'END_OF_ypx-add.c'
  442. X#include <string.h>
  443. X#define extern
  444. X#include "ypx-add.h"
  445. X/*
  446. X * Define extern as "" to define the otherwise external table and tablec as
  447. X * local variables in this module.
  448. X */
  449. X
  450. X#ifndef lint
  451. Xstatic char *copyright = "@(#)ypx-add.c 1.1 91/11/20 Rob J. Nauta\n";
  452. X#endif
  453. X
  454. X/*
  455. X * Parses a hostname, and adds it to the table
  456. X */
  457. Xvoid
  458. Xparse(name)
  459. Xchar *name;
  460. X{
  461. X    char *a = name, *b;
  462. X    char buffer[128];
  463. X
  464. X    while (1) {
  465. X        add(a);
  466. X        b = strchr(a, '.');
  467. X        if (b) {
  468. X            strncpy(buffer, a, b - a);
  469. X            buffer[b - a] = '\0';
  470. X            add(buffer);
  471. X            a = (++b);
  472. X        } else
  473. X            return;
  474. X    }
  475. X}
  476. END_OF_ypx-add.c
  477. if test 558 -ne `wc -c <ypx-add.c`; then
  478.     echo shar: \"ypx-add.c\" unpacked with wrong size!
  479. fi
  480. # end of overwriting check
  481. fi
  482. if test -f ypx-add.h -a "${1}" != "-c" ; then 
  483.   echo shar: Will not over-write existing file \"ypx-add.h\"
  484. else
  485. echo shar: Extracting \"ypx-add.h\" \(117 characters\)
  486. sed "s/^X//" >ypx-add.h <<'END_OF_ypx-add.h'
  487. X#define TABLESIZE 50
  488. Xextern char table[TABLESIZE][80];
  489. Xextern int tablec;
  490. X#define    add(a)    strcpy(table[tablec++], a);
  491. END_OF_ypx-add.h
  492. if test 117 -ne `wc -c <ypx-add.h`; then
  493.     echo shar: \"ypx-add.h\" unpacked with wrong size!
  494. fi
  495. # end of overwriting check
  496. fi
  497. if test -f ypx-boot.c -a "${1}" != "-c" ; then 
  498.   echo shar: Will not over-write existing file \"ypx-boot.c\"
  499. else
  500. echo shar: Extracting \"ypx-boot.c\" \(1202 characters\)
  501. sed "s/^X//" >ypx-boot.c <<'END_OF_ypx-boot.c'
  502. X/*
  503. X * Functie ypx_boot(host). Roept de bootparams service aan op host 'host'.
  504. X * Resultaat is een char *. Als er iets mis gaat, return een (char *) 0.
  505. X */
  506. X#include <stdio.h>
  507. X#include <sys/errno.h>
  508. X#include <sys/types.h>
  509. X#include <sys/socket.h>
  510. X#include <rpc/rpc.h>
  511. X#include <rpcsvc/bootparam.h>
  512. X#include "nhost.h"
  513. X
  514. X#ifndef lint
  515. Xstatic char *copyright = "@(#)ypx_boot.c 1.1 92/08/22 Rob J. Nauta\n";
  516. X#endif
  517. X
  518. Xchar *programname;
  519. Xint option;
  520. X
  521. Xchar *
  522. Xbootname(host)
  523. Xchar *host;
  524. X{
  525. X    int stat,i;
  526. X    static struct bp_whoami_arg bp_arg, *bp_p;
  527. X    static struct bp_whoami_res bp_r, *bp_res=NULL;
  528. X
  529. X    bp_p=&bp_arg;
  530. X    bp_arg.client_address.address_type=1;
  531. X    bp_arg.client_address.bp_address.ip_addr.net=(char)131;
  532. X    bp_arg.client_address.bp_address.ip_addr.host=(char)155;
  533. X    bp_arg.client_address.bp_address.ip_addr.lh=(char)70;
  534. X    bp_arg.client_address.bp_address.ip_addr.impno=(char)17;
  535. X    bp_res=&bp_r;
  536. X    bp_r.client_name=malloc(1024);
  537. X    bp_r.domain_name=malloc(1024);
  538. X
  539. X    if (stat = callrpc(host, BOOTPARAMPROG, BOOTPARAMVERS,
  540. X               BOOTPARAMPROC_WHOAMI, xdr_bp_whoami_arg, &bp_arg,
  541. X               xdr_bp_whoami_res, bp_res)) {
  542. X        clnt_perrno(stat);
  543. X        return(NULL);
  544. X    }
  545. X    /* Print de gevonden gegevens uit */
  546. X    return(bp_res->domain_name);
  547. X}
  548. END_OF_ypx-boot.c
  549. if test 1202 -ne `wc -c <ypx-boot.c`; then
  550.     echo shar: \"ypx-boot.c\" unpacked with wrong size!
  551. fi
  552. # end of overwriting check
  553. fi
  554. if test -f ypx-func.c -a "${1}" != "-c" ; then 
  555.   echo shar: Will not over-write existing file \"ypx-func.c\"
  556. else
  557. echo shar: Extracting \"ypx-func.c\" \(2809 characters\)
  558. sed "s/^X//" >ypx-func.c <<'END_OF_ypx-func.c'
  559. X#include <stdio.h>
  560. X#include <sys/time.h>
  561. X#include <rpc/rpc.h>
  562. X#include <rpcsvc/yp_prot.h>
  563. X#include "nhost.h"
  564. X#include "ypx-add.h"
  565. X
  566. X#ifndef lint
  567. Xstatic char *copyright = "@(#)ypx-func.c 2.2 92/05/08 Rob J. Nauta\n";
  568. X#endif
  569. Xstatic struct timeval TIMEOUT = {25, 0};    /* total timeout */
  570. Xextern char *programname, *ypdomain;
  571. X
  572. XCLIENT *
  573. Xrpc_yp_client(arg,thisport)
  574. Xchar *arg;
  575. Xint thisport;
  576. X{
  577. X    char myhost[100];
  578. X    struct sockaddr_in *server_addr;
  579. X    int sock = RPC_ANYSOCK, klad = 0;
  580. X    CLIENT *client;
  581. X
  582. X    if (gethostname(myhost, 100))    /* Get our own hostname */
  583. X        perror(programname);
  584. X    server_addr = getsock(arg);    /* Get adress info */
  585. X    if (server_addr == NULL)
  586. X        return (NULL);
  587. X    server_addr->sin_port = thisport;    /* Normally 0 (== portmapper)*/
  588. X
  589. X    /*
  590. X     * We use tcp, because receiving thousands of udp packets would slow
  591. X     * down things considerably.
  592. X     */
  593. X    if ((client = clnttcp_create(server_addr, YPPROG, YPVERS,
  594. X                     &sock, 0, 0)) == NULL) {
  595. X        clnt_pcreateerror(programname);
  596. X        return (NULL);    /* Failure */
  597. X    }
  598. X    client->cl_auth = authunix_create(myhost, 0, 0, 1, &klad);
  599. X    return (client);    /* Success */
  600. X}
  601. X
  602. Xstatic 
  603. Xgetmap(client, map, domain, outputfile)
  604. XCLIENT *client;
  605. Xchar *map, *domain;
  606. XFILE *outputfile;
  607. X{
  608. X    struct ypreq_nokey no;    /* To start lookup */
  609. X    struct ypreq_key key;    /* To continue lookup */
  610. X    enum clnt_stat re;
  611. X    static struct ypresp_key_val resp;    /* Results of lookup */
  612. X    char buffer[1024];
  613. X
  614. X    resp.keydat.dptr = malloc(1024);
  615. X    resp.valdat.dptr = malloc(1024);
  616. X    no.domain = domain;    /* Startup values */
  617. X    no.map = map;
  618. X    /* Get the first entry */
  619. X    re = clnt_call(client, YPPROC_FIRST, xdr_ypreq_nokey, &no,
  620. X               xdr_ypresp_key_val, &resp, TIMEOUT);
  621. X    if (re != RPC_SUCCESS) {
  622. X        clnt_perrno(re);
  623. X        return (2);
  624. X    }
  625. X    if (resp.status != 1)
  626. X        return (1);    /* Success, but no map, domainname wrong */
  627. X    while (resp.status == 1) {
  628. X        strncpy(buffer, resp.valdat.dptr, resp.valdat.dsize);
  629. X        buffer[resp.valdat.dsize] = (char) 0;
  630. X        fprintf(outputfile, "%s\n", buffer);
  631. X
  632. X        key.domain = domain;
  633. X        key.map = map;
  634. X        key.keydat.dptr = resp.keydat.dptr;
  635. X        key.keydat.dsize = resp.keydat.dsize;
  636. X
  637. X        /* Get next entry, using the previous one */
  638. X        re = clnt_call(client, YPPROC_NEXT, xdr_ypreq_key, &key,
  639. X                   xdr_ypresp_key_val, &resp, TIMEOUT);
  640. X        if (re != RPC_SUCCESS) {
  641. X            clnt_perrno(re);
  642. X            return (2);
  643. X        }
  644. X    }
  645. X    return (0);
  646. X}
  647. X
  648. X/*
  649. X * trymap - Tries the list of domainnames in table[] with getmap().
  650. X */
  651. Xtrymap(client, mapname, debug, outputfile)
  652. XCLIENT *client;
  653. Xchar *mapname;
  654. Xint debug;
  655. XFILE *outputfile;
  656. X{
  657. X    int teller = 0, res;
  658. X    while (teller < tablec) {
  659. X        if (debug)
  660. X            fprintf(stderr, "Trying domain %s\n", table[teller]);
  661. X        if ((res = getmap(client, mapname, table[teller], outputfile)
  662. X             ) == 0) {
  663. X            ypdomain = table[teller];
  664. X            return (0);    /* success */
  665. X        }
  666. X        teller++;
  667. X    }
  668. X    return (res);        /* failure */
  669. X}
  670. END_OF_ypx-func.c
  671. if test 2809 -ne `wc -c <ypx-func.c`; then
  672.     echo shar: \"ypx-func.c\" unpacked with wrong size!
  673. fi
  674. # end of overwriting check
  675. fi
  676. if test -f ypx-main.c -a "${1}" != "-c" ; then 
  677.   echo shar: Will not over-write existing file \"ypx-main.c\"
  678. else
  679. echo shar: Extracting \"ypx-main.c\" \(1974 characters\)
  680. sed "s/^X//" >ypx-main.c <<'END_OF_ypx-main.c'
  681. X/* ypx 2.1 (c) Copyright 1991,1992 by Rob J. Nauta. All rights reserved. */
  682. X#include <stdio.h>
  683. X#include <rpc/rpc.h>
  684. X#include "nhost.h"
  685. X#include "ypx-add.h"
  686. X#ifndef lint
  687. Xstatic char *copyright = "@(#)ypx-main.c 2.2 92/05/09 Rob J. Nauta\n";
  688. X#endif
  689. X
  690. Xextern CLIENT *rpc_yp_client();
  691. Xchar *ypdomain, *programname;
  692. X
  693. Xmain(argc, argv)
  694. Xint argc;
  695. Xchar *argv[];
  696. X{
  697. X    int c;
  698. X    int debug = 0, errflg = 0, guessing = 0, toafile = 0, sendmail = 0;
  699. X    int thisport = 0;
  700. X    char *mapname = "passwd.byname";
  701. X    FILE *outputfile;
  702. X    extern int optind;
  703. X    extern char *optarg;
  704. X    CLIENT *client;        /* Client pointer */
  705. X
  706. X    programname = argv[0];
  707. X    outputfile = stdout;
  708. X    tablec = 0;
  709. X    while ((c = getopt(argc, argv, "dgm:o:p:s")) != EOF)
  710. X        switch (c) {
  711. X            case 'd':    /* debug */
  712. X            debug++;
  713. X            break;
  714. X            case 'g':    /* guessing */
  715. X            guessing++;
  716. X            break;
  717. X            case 'm':    /* mapname */
  718. X            mapname = optarg;
  719. X            break;
  720. X            case 'o':    /* redirect output */
  721. X            outputfile = fopen(optarg, "w");
  722. X            toafile++;
  723. X            break;
  724. X            case 'p':    /* go directly to port thisport */
  725. X            thisport = atoi(optarg);
  726. X            break;
  727. X            case 's':    /* try sendmail */
  728. X            sendmail++;
  729. X            break;
  730. X            case '?':    /* help */
  731. X            default:
  732. X            errflg++;
  733. X            break;
  734. X        }
  735. X    if (optind >= argc)
  736. X        errflg++;
  737. X    if (errflg) {
  738. X        fprintf(stderr, "Usage:    %s [-dgs] [-m mapname] [-o outputfile] [-p portnumber]\n    hostname [domainname ...]\n",
  739. X            programname);
  740. X        exit(1);
  741. X    }
  742. X    client = rpc_yp_client(argv[optind], thisport);
  743. X    if (client == NULL)
  744. X        exit(2);    /* Host not found, or no ypserv */
  745. X    if (guessing)
  746. X        parse(argv[optind]);    /* build name table */
  747. X    if (sendmail)        /* Add sendmail hostname */
  748. X        parse(get_smname(argv[optind], debug));
  749. X    while (optind < argc)
  750. X        add(argv[optind++]);    /* just add arg to table */
  751. X
  752. X    if ((trymap(client, mapname, debug, outputfile) == 0) && debug)
  753. X        fprintf(stderr, "YP map transfer successfull.\n");
  754. X    auth_destroy(client->cl_auth);    /* Free authorization struct */
  755. X    clnt_destroy(client);    /* Free client structure */
  756. X    return (0);
  757. X}
  758. END_OF_ypx-main.c
  759. if test 1974 -ne `wc -c <ypx-main.c`; then
  760.     echo shar: \"ypx-main.c\" unpacked with wrong size!
  761. fi
  762. # end of overwriting check
  763. fi
  764. if test -f ypx-sm.c -a "${1}" != "-c" ; then 
  765.   echo shar: Will not over-write existing file \"ypx-sm.c\"
  766. else
  767. echo shar: Extracting \"ypx-sm.c\" \(783 characters\)
  768. sed "s/^X//" >ypx-sm.c <<'END_OF_ypx-sm.c'
  769. X#include <stdio.h>
  770. X#include <string.h>
  771. X#ifndef lint
  772. Xstatic char *copyright = "@(#)ypx-sm.c 1.0 91/11/20 Rob J. Nauta\n";
  773. X#endif
  774. X
  775. X/*
  776. X * Retrieves the full hostname from sendmail on the remote host.
  777. X */
  778. Xchar *
  779. Xget_smname(name, debug)
  780. Xchar *name;
  781. Xint debug;
  782. X{
  783. X    int s;
  784. X    static char result[80];
  785. X    char buffer[256], a[20], *p;
  786. X
  787. X    if (debug)
  788. X        fprintf(stderr, "Opening connection to sendmail ... ");
  789. X    if ((s = opensock(name, 25)) < 0) {
  790. X        if (debug)
  791. X            fprintf(stderr, "failed.\n");
  792. X        return (NULL);
  793. X    }
  794. X    read(s, buffer, 256);    /* Read one line */
  795. X    close(s);
  796. X    if (p = strchr(buffer, '\r'))
  797. X        *p = '\0';    /* Remove trailing garbage */
  798. X    if (debug)
  799. X        fprintf(stderr, "ok.\n%s\n", buffer);
  800. X    sscanf(buffer, "%s %s", a, result);    /* Read "220" and hostname */
  801. X    return (result);    /* Return hostname */
  802. X}
  803. END_OF_ypx-sm.c
  804. if test 783 -ne `wc -c <ypx-sm.c`; then
  805.     echo shar: \"ypx-sm.c\" unpacked with wrong size!
  806. fi
  807. # end of overwriting check
  808. fi
  809. if test -f ypx.1 -a "${1}" != "-c" ; then 
  810.   echo shar: Will not over-write existing file \"ypx.1\"
  811. else
  812. echo shar: Extracting \"ypx.1\" \(2435 characters\)
  813. sed "s/^X//" >ypx.1 <<'END_OF_ypx.1'
  814. X.\" (c) Copyright 1991 by Rob J. Nauta. All rights reserved.
  815. X.\" j
  816. X.TH YPX 1 "13 Nov 1991"
  817. X.SH NAME
  818. Xypx \- transfer a NIS map beyond the local (broadcast) network
  819. X.SH SYNOPSIS
  820. X.B ypx
  821. X[
  822. X.B \-dgs
  823. X] [
  824. X.BI \-m "\ mapname"
  825. X] [
  826. X.BI \-o "\ outputfile"
  827. X]
  828. X.I hostname
  829. X[
  830. X.I domainname ...
  831. X]
  832. X.SH DESCRIPTION
  833. XNormal NIS operation depends on the ability to send broadcast
  834. Xmessages over the local ethernet.
  835. XIt is possible to point a
  836. X.B ypbind
  837. Xdaemon to a
  838. X.B ypserv
  839. Xdaemon on a non-local system, however, this is not recommended.
  840. X.LP
  841. X.B ypx
  842. Xis a utility to transfer a NIS map from any host running a
  843. X.B ypserv
  844. Xdaemon.
  845. X.B ypx
  846. Xis similar to
  847. X.BR ypcat ,
  848. Xwith some additions.
  849. XTo be able to transfer a map, a
  850. X.I domainname
  851. Xmust be specified.
  852. XThere unfortunately is no way to ask the remote host about
  853. Xits domainname, so it must be known already or guessed to
  854. Xtransfer a map successfully.
  855. XIf none is specified, the hostname of the remote
  856. Xhost is used as the domainname.
  857. X.B ypx
  858. Xis able to guess at the remote domainname, by trying parts of
  859. Xthe hostname, if guessing is enabled with the
  860. X.B \-g
  861. Xoption. If the 
  862. X.B \-s
  863. Xoption is used,
  864. X.B ypx
  865. Xwill connect to the
  866. X.B sendmail
  867. Xdaemon, read the hostname, and parse that too, to be used
  868. Xas additional guesses.
  869. XFinally, any additional strings on the commandline will be
  870. Xadded to the list of domainname guesses.
  871. X.SH OPTIONS
  872. X.TP
  873. X.B \-d
  874. XDebug mode, gives progress information on stderr.
  875. X.TP
  876. X.B \-g
  877. XEnable domainname guessing.
  878. X.TP
  879. X.BI \-m "\ mapname"
  880. XSpecify the name of the NIS map to be transferred. The default is
  881. X.BR passwd.byname .
  882. X.TP
  883. X.BI \-o "\ outputfile"
  884. XSend output file to
  885. X.IR outputfile .
  886. XIf the transfer was unsuccessfull, the (zero length)
  887. X.I outputfile
  888. Xwill be removed.
  889. X.TP
  890. X.BI \-p "\ portnumber"
  891. XNormally the call is placed to the portmapper of the remote host, which
  892. Xwill tell us the portnumber
  893. X.IR ypserv (8)
  894. Xis using. If a portnumber is specified, the RPC call is placed
  895. Xdirectly to
  896. X.IR ypserv (8).
  897. X.TP
  898. X.B \-s
  899. XRetrieve the full hostname from sendmail, parse it, and add it to the
  900. Xlist of guesses.
  901. X.I
  902. X.\".SH FILES
  903. X.SH "SEE ALSO"
  904. X.BR domainname (1),
  905. X.BR sendmail (8),
  906. X.BR ypcat (1),
  907. X.BR ypserv (8).
  908. X.LP
  909. X.I System and Network Administration
  910. X.SH DIAGNOSTICS
  911. X.TP
  912. X.BI "Can't find " hostname !
  913. XThe hostname is invalid, or the host was not found.
  914. X.TP
  915. X.B "ypx: RPC: Program not registered"
  916. XThe remote host doesn't have a
  917. X.B ypserv
  918. Xdaemon running.
  919. X.\".SH BUGS
  920. X.SH AUTHOR
  921. X.TP
  922. XRob J. Nauta:
  923. X.I rob@wzv.win.tue.nl
  924. END_OF_ypx.1
  925. if test 2435 -ne `wc -c <ypx.1`; then
  926.     echo shar: \"ypx.1\" unpacked with wrong size!
  927. fi
  928. # end of overwriting check
  929. fi
  930. echo shar: End of archive 1 \(of 1\).
  931. cp /dev/null ark1isdone
  932. MISSING=""
  933. for I in 1 ; do
  934.     if test ! -f ark${I}isdone ; then
  935.     MISSING="${MISSING} ${I}"
  936.     fi
  937. done
  938. if test "${MISSING}" = "" ; then
  939.     echo You have unpacked all 1 archives.
  940.     rm -f ark[1-9]isdone
  941. else
  942.     echo You still need to unpack the following archives:
  943.     echo "        " ${MISSING}
  944. fi
  945. ##  End of shell archive.
  946. exit 0
  947. -- 
  948. /-----------------------------------------------\  Bloody your hands on a
  949. | Rob J. Nauta, UNIX computer security expert.  |  cactus tree -- Wipe them
  950. | rob@wzv.win.tue.nl, Phone: +31-40-837549      |  on your dress and send
  951. | Feel free to email me for free advice         |  it to me.  (the pixies)
  952. exit 0 # Just in case...
  953.