home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sources / misc / 4245 < prev    next >
Encoding:
Text File  |  1993-01-10  |  50.4 KB  |  1,449 lines

  1. Newsgroups: comp.sources.misc
  2. Path: sparky!kent
  3. From: amber@engin.umich.edu (Lee Liming)
  4. Subject: v34i103:  netuse - A Network Host Usage Monitoring System, Part05/06
  5. Message-ID: <1993Jan11.023832.25587@sparky.imd.sterling.com>
  6. Followup-To: comp.sources.d
  7. X-Md4-Signature: 5596b0fe1715b63d234510153297ea3f
  8. Sender: kent@sparky.imd.sterling.com (Kent Landfield)
  9. Organization: Sterling Software
  10. References: <csm-v34i099=netuse.203327@sparky.IMD.Sterling.COM>
  11. Date: Mon, 11 Jan 1993 02:38:32 GMT
  12. Approved: kent@sparky.imd.sterling.com
  13. Lines: 1434
  14.  
  15. Submitted-by: amber@engin.umich.edu (Lee Liming)
  16. Posting-number: Volume 34, Issue 103
  17. Archive-name: netuse/part05
  18. Environment: UNIX, MS-DOS, OS/2, INET, MSC
  19.  
  20. #! /bin/sh
  21. # This is a shell archive.  Remove anything before this line, then feed it
  22. # into a shell via "sh file" or similar.  To overwrite existing files,
  23. # type "sh file -c".
  24. # Contents:  netuse/clients/getmach.1 netuse/clients/getmach.c
  25. #   netuse/clients/hostinfo.1 netuse/clients/netuseadmin.1
  26. #   netuse/daemons/getdisk.c netuse/daemons/getusers.c
  27. #   netuse/daemons/netuse.8 netuse/daemons/netused.8
  28. #   netuse/lib/config.h netuse/lib/netadmin.c netuse/lib/variable.h
  29. # Wrapped by kent@sparky on Sun Jan 10 20:28:37 1993
  30. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  31. echo If this archive is complete, you will see the following message:
  32. echo '          "shar: End of archive 5 (of 6)."'
  33. if test -f 'netuse/clients/getmach.1' -a "${1}" != "-c" ; then 
  34.   echo shar: Will not clobber existing file \"'netuse/clients/getmach.1'\"
  35. else
  36.   echo shar: Extracting \"'netuse/clients/getmach.1'\" \(3373 characters\)
  37.   sed "s/^X//" >'netuse/clients/getmach.1' <<'END_OF_FILE'
  38. X.TH getmach 1 "June 6, 1992" "" "CAEN - The University of Michigan"
  39. X.UC 4
  40. X.SH NAME
  41. Xgetmach \- NETUSE Host Selection utility
  42. X.SH SYNOPSIS
  43. X.B getmach [
  44. X.BR specifications
  45. X.B ]
  46. X.SH DESCRIPTION
  47. X.I getmach
  48. Xis a tool for selecting a network host which meets specific usage criteria.
  49. XThe
  50. X.I getmach
  51. Xclient consults the
  52. X.I netuse
  53. Xserver, which maintains a list of network hosts
  54. Xwhich periodically report their status.  The
  55. X.I netuse
  56. Xserver returns a host which meets the specification given on the command line,
  57. Xand
  58. X.I getmach
  59. Xprints this hostname on the terminal.
  60. X.PP
  61. XA particular hostname will only be returned once to any client on the network
  62. Xduring a given two minute period.  Thus, successive
  63. X.I getmach
  64. Xcommands are guaranteed to return unique hostnames, so long as additional
  65. Xhosts which meet the specifications are available.  The complete listing of
  66. Xhosts reporting to the
  67. X.I netuse
  68. Xserver can be displayed using the
  69. X.IR hostinfo (1)
  70. Xcommand.
  71. X.PP
  72. XIf no machines meet the given specifications, or if all matching machines have
  73. Xbeen given out within the past two minutes,
  74. X.I getmach
  75. Xwill produce no output, and the return code will be set to 1.
  76. X.PP
  77. XWith no options specified, an arbitrary hostname will be returned.  As
  78. Xadditional specifications are made, only hosts which meet the specifications
  79. Xwill be returned.
  80. X.SH OPTIONS
  81. XThe following options may be used with the
  82. X.I hostinfo
  83. Xcommand to specify criteria for selecting hosts.
  84. X.TP 16
  85. X-help
  86. XList the available specifications.
  87. X.TP 16
  88. X-sun
  89. XRequest only Suns.
  90. X.TP 16
  91. X-ibm
  92. XRequest only IBM RS/6000s.
  93. X.TP 16
  94. X-dec
  95. XRequest only DECstations.
  96. X.TP 16
  97. X-hp
  98. XRequest only HP9000s.
  99. X.TP 16
  100. X-model <model>
  101. XSpecify a model type to be matched.  Model types are those listed by the 
  102. Xhostinfo(1) command when the -models flag is used.
  103. X.TP 16
  104. X-l1 <load>
  105. XSpecify the maximum 1-minute load average.
  106. X.TP 16
  107. X-l2 <load>
  108. XSpecify the maximum 5-minute load average.
  109. X.TP 16
  110. X-l3 <load>
  111. XSpecify the maximum 15-minute load average.
  112. X.TP 16
  113. X-users <nusers>
  114. XSpecify the maximum number of login sessions.
  115. X.TP 16
  116. X-console
  117. XSpecify no one logged into the display.
  118. X.TP 16
  119. X-tmp <kbytes>
  120. XSpecify the minimum free space on /tmp.
  121. X.SH COPYRIGHT
  122. XCopyright (C) 1992 by the Regents of the University of Michigan.
  123. X.PP
  124. XUser agrees to reproduce said copyright notice on all copies of the software
  125. Xmade by the recipient.  
  126. X.PP
  127. XAll Rights Reserved. Permission is hereby granted for the recipient to make
  128. Xcopies and use this software for its own internal purposes only. Recipient of
  129. Xthis software may re-distribute this software outside of their own
  130. Xinstitution. Permission to market this software commercially, to include this
  131. Xproduct as part of a commercial product, or to make a derivative work for
  132. Xcommercial purposes, is explicitly prohibited.  All other uses are also
  133. Xprohibited unless authorized in writing by the Regents of the University of
  134. XMichigan.
  135. X.PP
  136. XThis software is offered without warranty. The Regents of the University of
  137. XMichigan disclaim all warranties, express or implied, including but not
  138. Xlimited to the implied warranties of merchantability and fitness for any
  139. Xparticular purpose. In no event shall the Regents of the University of
  140. XMichigan be liable for loss or damage of any kind, including but not limited
  141. Xto incidental, indirect, consequential, or special damages. 
  142. X.SH SEE ALSO
  143. Xhostinfo(1), netuse(8), netused(8),
  144. X.I Monitoring Hosts with NETUSE
  145. X
  146. END_OF_FILE
  147.   if test 3373 -ne `wc -c <'netuse/clients/getmach.1'`; then
  148.     echo shar: \"'netuse/clients/getmach.1'\" unpacked with wrong size!
  149.   fi
  150.   # end of 'netuse/clients/getmach.1'
  151. fi
  152. if test -f 'netuse/clients/getmach.c' -a "${1}" != "-c" ; then 
  153.   echo shar: Will not clobber existing file \"'netuse/clients/getmach.c'\"
  154. else
  155.   echo shar: Extracting \"'netuse/clients/getmach.c'\" \(5893 characters\)
  156.   sed "s/^X//" >'netuse/clients/getmach.c' <<'END_OF_FILE'
  157. X/******************************************************************************
  158. X GETMACH.C - Network Host Use Monitor Machine Selection Utility
  159. X
  160. X This program contacts the NETUSE server and returns the hostname of a
  161. X specific host on the network which meets given criteria.  If no host meets
  162. X the criteria, no output is produced.  The -help option lists the possible
  163. X selection criteria.
  164. X
  165. X Lee Liming and Michael Neil, The Computer Aided Engineering Network
  166. X The University of Michigan
  167. X
  168. X Copyright (C) 1990, 1991, 1992 by the Regents of the University of Michigan.
  169. X
  170. X User agrees to reproduce said copyright notice on all copies of the software
  171. X made by the recipient.  
  172. X
  173. X All Rights Reserved. Permission is hereby granted for the recipient to make
  174. X copies and use this software for its own internal purposes only. Recipient of
  175. X this software may re-distribute this software outside of their own
  176. X institution. Permission to market this software commercially, to include this
  177. X product as part of a commercial product, or to make a derivative work for
  178. X commercial purposes, is explicitly prohibited.  All other uses are also
  179. X prohibited unless authorized in writing by the Regents of the University of
  180. X Michigan.
  181. X
  182. X This software is offered without warranty. The Regents of the University of
  183. X Michigan disclaim all warranties, express or implied, including but not
  184. X limited to the implied warranties of merchantability and fitness for any
  185. X particular purpose. In no event shall the Regents of the University of
  186. X Michigan be liable for loss or damage of any kind, including but not limited
  187. X to incidental, indirect, consequential, or special damages. 
  188. X******************************************************************************/
  189. X
  190. X#include <stdio.h>
  191. X#include <sys/types.h>
  192. X#include <netuse.h>
  193. X
  194. X
  195. X#ifdef __STDC__
  196. Xmain(int argc,char *argv[])
  197. X#else
  198. Xmain(argc,argv)
  199. Xint argc;
  200. Xchar *argv[];
  201. X#endif
  202. X{
  203. X     double l1,l2,l3;
  204. X     int users,console,i,modellist=0;
  205. X     long tmp;
  206. X     u_char machtype,modtype;
  207. X     char mname[132],buffer[512];
  208. X
  209. X     l1=100.0; l2=100.0; l3=100.0;
  210. X     users=100; console=100;
  211. X     tmp=0;
  212. X     machtype=0; modtype=0;
  213. X     for (i=1; i<argc; i++) {
  214. X          strcpy(buffer,argv[i]);
  215. X          stoupper(buffer);
  216. X          if (!strcmp(buffer,"-L1")) {
  217. X               i++;
  218. X               if (sscanf(argv[i],"%lf",&l1)!=1) {
  219. X                    printf("Bad argument value (%s,%s).\n",argv[i-1],argv[i]);
  220. X                    --i;
  221. X               }
  222. X               continue;
  223. X          }
  224. X          if (!strcmp(buffer,"-L2")) {
  225. X               i++;
  226. X               if (sscanf(argv[i],"%lf",&l2)!=1) {
  227. X                    printf("Bad argument value (%s,%s).\n",argv[i-1],argv[i]);
  228. X                    --i;
  229. X               }
  230. X               continue;
  231. X          }
  232. X          if (!strcmp(buffer,"-L3")) {
  233. X               i++;
  234. X               if (sscanf(argv[i],"%lf",&l3)!=1) {
  235. X                    printf("Bad argument value (%s,%s).\n",argv[i-1],argv[i]);
  236. X                    --i;
  237. X               }
  238. X               continue;
  239. X          }
  240. X          if (!strcmp(buffer,"-USERS")) {
  241. X               i++;
  242. X               if (sscanf(argv[i],"%d",&users)!=1) {
  243. X                    printf("Bad argument value (%s,%s).\n",argv[i-1],argv[i]);
  244. X                    --i;
  245. X               }
  246. X               continue;
  247. X          }
  248. X          if (!strcmp(buffer,"-MODEL")) {
  249. X               i++;
  250. X               if (!(modtype=netStrToModel(argv[i]))) {
  251. X                    printf("Unknown model specifier (%s,%s).\n",argv[i-1],argv[i]);
  252. X                    --i;
  253. X               }
  254. X               continue;
  255. X          }
  256. X          if (!strcmp(buffer,"-TMP")) {
  257. X               i++;
  258. X               if (sscanf(argv[i],"%ld",&tmp)!=1) {
  259. X                    printf("Bad argument value (%s,%s).\n",argv[i-1],argv[i]);
  260. X                    --i;
  261. X               }
  262. X               continue;
  263. X          }
  264. X          if (!strcmp(buffer,"-CONSOLE")) {
  265. X               console=0;
  266. X               continue;
  267. X          }
  268. X          if (!strcmp(buffer,"-SUN")) {
  269. X               machtype=MACH_SUN;
  270. X               continue;
  271. X          }
  272. X          if (!strcmp(buffer,"-IBM")) {
  273. X               machtype=MACH_IBM_RS6000;
  274. X               continue;
  275. X          }
  276. X          if (!strcmp(buffer,"-APOLLO")) {
  277. X               machtype=MACH_APOLLO;
  278. X               continue;
  279. X          }
  280. X          if (!strcmp(buffer,"-DEC")) {
  281. X               machtype=MACH_DEC;
  282. X               continue;
  283. X          }
  284. X          if (!strcmp(buffer,"-HP")) {
  285. X               machtype=MACH_HP;
  286. X               continue;
  287. X          }
  288. X          if (!strcmp(buffer,"-HELP")) {
  289. X               printf("\nUsage: getmach [options]\n\n");
  290. X               printf("Options: -l1 <load>       Specify maximum 1-min load average\n");
  291. X               printf("         -l2 <load>       Specify maximum 5-min load average\n");
  292. X               printf("         -l3 <load>       Specify maximum 15-min load average\n");
  293. X               printf("         -users <nusers>  Specify maximum number of login sessions\n");
  294. X               printf("         -console         Specify no one logged into the display\n");
  295. X               printf("         -tmp <kbytes>    Specify minimum free space on /tmp\n");
  296. X               printf("         -model <model>   Specify model type\n");
  297. X               printf("         -sun             Request only Sun SparcStations\n");
  298. X               printf("         -ibm             Request only IBM RS/6000s\n");
  299. X               printf("         -dec             Request only DECstations\n");
  300. X               printf("         -apollo          Request only Apollos\n");
  301. X               printf("         -hp              Request only HP9000s\n\n");
  302. X               exit(0);
  303. X          }
  304. X     }
  305. X     netSetup();
  306. X     netuseFind(mname,l1,l2,l3,users,console,tmp,machtype,modtype);
  307. X     netShutdown();
  308. X     if (strlen(mname)) {
  309. X          printf("%s\n",mname);
  310. X          exit(0);
  311. X     }
  312. X     else exit(1);
  313. X}
  314. END_OF_FILE
  315.   if test 5893 -ne `wc -c <'netuse/clients/getmach.c'`; then
  316.     echo shar: \"'netuse/clients/getmach.c'\" unpacked with wrong size!
  317.   fi
  318.   # end of 'netuse/clients/getmach.c'
  319. fi
  320. if test -f 'netuse/clients/hostinfo.1' -a "${1}" != "-c" ; then 
  321.   echo shar: Will not clobber existing file \"'netuse/clients/hostinfo.1'\"
  322. else
  323.   echo shar: Extracting \"'netuse/clients/hostinfo.1'\" \(3527 characters\)
  324.   sed "s/^X//" >'netuse/clients/hostinfo.1' <<'END_OF_FILE'
  325. X.TH hostinfo 1 "June 6, 1992" "" "CAEN - The University of Michigan"
  326. X.UC 4
  327. X.SH NAME
  328. Xhostinfo \- Network Host Information listing utility
  329. X.SH SYNOPSIS
  330. X.B hostinfo [
  331. X.BR options
  332. X.B ]
  333. X.SH DESCRIPTION
  334. X.I hostinfo
  335. Xis a tool for listing available hosts on the Internet.  The
  336. X.I hostinfo
  337. Xclient consults the
  338. X.I netuse
  339. Xserver, which maintains a list of network hosts
  340. Xwhich periodically report their status.  The
  341. X.I netuse
  342. Xserver transfers the list
  343. Xof hosts to the
  344. X.I hostinfo
  345. Xclient, which displays the list on the terminal.
  346. X.PP
  347. XThe host listing is given in order of least use (machines reporting a low
  348. Xcurrent usage will be displayed first).  Machines with users logged into the
  349. Xconsole will always be listed after machines with no one logged into the
  350. Xconsole.
  351. X.PP
  352. XWith no options specified, the listing will include machines of all types.
  353. XOnly the ten least-used machines will be listed.  Currently, the only types of
  354. Xmachines supported are DECstation 3100 and 5000s, Sun 4s (SparcStation and
  355. XSparcStation+), Apollos (all models), HP9000 700 series, and IBM RS/6000s.
  356. XHosts that have not reported recently (within the last 15 minutes) will not be
  357. Xincluded.
  358. X.PP
  359. XThe information for each host includes the following: hostname, type, load
  360. Xaverages over the past 1, 5, and 15 minutes, number of current login sessions,
  361. Xstatus of the display (login or nologin), time of last report, and the number
  362. Xof kilobytes of free space on the /tmp filesystem.
  363. X.PP
  364. XIf the -models flag is used, the listing format is modified to include a wider
  365. Xtype field, including the model as well as the vendor.  With this type of
  366. Xlisting, the time of last report is not displayed.
  367. X.SH OPTIONS
  368. XThe following options may be used with the
  369. X.I hostinfo
  370. Xcommand to modify the types of machines listed.
  371. X.TP 16
  372. X-help
  373. XList the available options.
  374. X.TP 16
  375. X-sun
  376. XInclude only Suns in the listing.
  377. X.TP 16
  378. X-dec
  379. XInclude only DECstations in the listing.
  380. X.TP 16
  381. X-ibm
  382. XInclude only IBM RS/6000s in the listing.
  383. X.TP 16
  384. X-hp
  385. XInclude only HP9000s in the listing.
  386. X.TP 16
  387. X-any
  388. XInclude any type of machine in the listing.
  389. X.TP 16
  390. X-model <model>
  391. XInclude only machines of the specified model.
  392. X.TP 16
  393. X-all
  394. XList all known hosts.
  395. X.TP 16
  396. X-down
  397. XList machines that have NOT reported in the last 15 minutes.
  398. X.TP 16
  399. X-models
  400. XList models rather than last report time.
  401. X.SH COPYRIGHT
  402. XCopyright (C) 1992 by the Regents of the University of Michigan.
  403. X.PP
  404. XUser agrees to reproduce said copyright notice on all copies of the software
  405. Xmade by the recipient.  
  406. X.PP
  407. XAll Rights Reserved. Permission is hereby granted for the recipient to make
  408. Xcopies and use this software for its own internal purposes only. Recipient of
  409. Xthis software may re-distribute this software outside of their own
  410. Xinstitution. Permission to market this software commercially, to include this
  411. Xproduct as part of a commercial product, or to make a derivative work for
  412. Xcommercial purposes, is explicitly prohibited.  All other uses are also
  413. Xprohibited unless authorized in writing by the Regents of the University of
  414. XMichigan.
  415. X.PP
  416. XThis software is offered without warranty. The Regents of the University of
  417. XMichigan disclaim all warranties, express or implied, including but not
  418. Xlimited to the implied warranties of merchantability and fitness for any
  419. Xparticular purpose. In no event shall the Regents of the University of
  420. XMichigan be liable for loss or damage of any kind, including but not limited
  421. Xto incidental, indirect, consequential, or special damages. 
  422. X.SH SEE ALSO
  423. Xgetmach(1), netuse(8), netused(8),
  424. X.I Monitoring Hosts with NETUSE
  425. X
  426. END_OF_FILE
  427.   if test 3527 -ne `wc -c <'netuse/clients/hostinfo.1'`; then
  428.     echo shar: \"'netuse/clients/hostinfo.1'\" unpacked with wrong size!
  429.   fi
  430.   # end of 'netuse/clients/hostinfo.1'
  431. fi
  432. if test -f 'netuse/clients/netuseadmin.1' -a "${1}" != "-c" ; then 
  433.   echo shar: Will not clobber existing file \"'netuse/clients/netuseadmin.1'\"
  434. else
  435.   echo shar: Extracting \"'netuse/clients/netuseadmin.1'\" \(3243 characters\)
  436.   sed "s/^X//" >'netuse/clients/netuseadmin.1' <<'END_OF_FILE'
  437. X.TH netuseadmin 1 "November 29, 1992" "" "CAEN - The University of Michigan"
  438. X.UC 4
  439. X.SH NAME
  440. Xnetuseadmin \- NETUSE administration utility
  441. X.SH SYNOPSIS
  442. X.B netuseadmin
  443. X.SH DESCRIPTION
  444. X.I netuseadmin
  445. Xis an interface to the functions of the netuse master daemon.  The
  446. X.I netuse(8)
  447. Xdaemon receives periodic reports from clients running the 
  448. X.I netused(8)
  449. Xdaemon and requests from the 
  450. X.I hostinfo(1)
  451. Xand 
  452. X.I getmach(1)
  453. Xclient applications.  
  454. X.I netuseadmin
  455. Xallows the network administrator to add and delete hosts from the NETUSE
  456. Xdatabase, and to control the daemon's basic operations, including saving
  457. Xstate and quitting.
  458. X.PP
  459. X.I netuseadmin
  460. Xis an interactive utility.  Commands are given within the program at the
  461. X"netuseadmin>" prompt.
  462. X.PP
  463. XThe "help" command will generate a list of the available commands and their
  464. Xarguments.  They are also listed below.
  465. X.TP 16
  466. Xadd
  467. XAdd a host to the database.  The 
  468. X.I netuse
  469. Xdaemon will add the host (listing it as down until it receives a report from
  470. Xthe host), and eventually attempt to start the host's 
  471. X.I netused
  472. Xdaemon if remote wakeup functionality has been enabled (see the installation
  473. Xguide, 
  474. X.I Monitoring Hosts with NETUSE).
  475. X.TP 16
  476. Xdelete
  477. XRemove a host from the NETUSE database.  Note that this does not kill the 
  478. X.I netused
  479. Xdaemon on the named host.  Unless this is done, the host will continue sending
  480. Xreports to the
  481. X.I netuse
  482. Xmaster daemon, and will be added back into the database.
  483. X.TP 16
  484. Xlist
  485. XProduce a list of the database contents similar to the output of "hostinfo
  486. X-all".  
  487. X.TP 16
  488. Xreload
  489. XReload the host database from the state-save file.
  490. X.TP 16
  491. Xsavestate
  492. XForce the server to save its database state in the state-save file.  This is
  493. Xautomatically done periodically by the master daemon, but it may be necessary
  494. Xat times to force a dump at a specific time (before shutting down the server, 
  495. Xfor example).
  496. X.TP 16 
  497. Xuse
  498. XRead subsequent commands from a file, as if they were typed at the command
  499. Xprompt.
  500. X.TP 16
  501. Xquit
  502. XExit the
  503. X.I netuseadmin
  504. Xprogram.
  505. X.SH COPYRIGHT
  506. XCopyright (C) 1992 by the Regents of the University of Michigan.
  507. X.PP
  508. XUser agrees to reproduce said copyright notice on all copies of the software
  509. Xmade by the recipient.  
  510. X.PP
  511. XAll Rights Reserved. Permission is hereby granted for the recipient to make
  512. Xcopies and use this software for its own internal purposes only. Recipient of
  513. Xthis software may re-distribute this software outside of their own
  514. Xinstitution. Permission to market this software commercially, to include this
  515. Xproduct as part of a commercial product, or to make a derivative work for
  516. Xcommercial purposes, is explicitly prohibited.  All other uses are also
  517. Xprohibited unless authorized in writing by the Regents of the University of
  518. XMichigan.
  519. X.PP
  520. XThis software is offered without warranty. The Regents of the University of
  521. XMichigan disclaim all warranties, express or implied, including but not
  522. Xlimited to the implied warranties of merchantability and fitness for any
  523. Xparticular purpose. In no event shall the Regents of the University of
  524. XMichigan be liable for loss or damage of any kind, including but not limited
  525. Xto incidental, indirect, consequential, or special damages. 
  526. X.SH SEE ALSO
  527. Xnetuse(8), netused(8), getmach(1), hostinfo(1),
  528. X.I Monitoring Hosts with NETUSE
  529. END_OF_FILE
  530.   if test 3243 -ne `wc -c <'netuse/clients/netuseadmin.1'`; then
  531.     echo shar: \"'netuse/clients/netuseadmin.1'\" unpacked with wrong size!
  532.   fi
  533.   # end of 'netuse/clients/netuseadmin.1'
  534. fi
  535. if test -f 'netuse/daemons/getdisk.c' -a "${1}" != "-c" ; then 
  536.   echo shar: Will not clobber existing file \"'netuse/daemons/getdisk.c'\"
  537. else
  538.   echo shar: Extracting \"'netuse/daemons/getdisk.c'\" \(3505 characters\)
  539.   sed "s/^X//" >'netuse/daemons/getdisk.c' <<'END_OF_FILE'
  540. X/******************************************************************************
  541. X This code gets the disk usage for /tmp for a DEC or a SUN.  (See below for
  542. X extensions to other platforms.)
  543. X
  544. X define mips for DEC
  545. X define sun for SUN
  546. X define testing for a compileable program with main
  547. X define DEBUG for debugging output
  548. X
  549. X Hacked up by: Mike Neil on Oct 11, 1990.
  550. X
  551. X Copyright (C) 1990, 1991, 1992 by the Regents of the University of Michigan.
  552. X
  553. X User agrees to reproduce said copyright notice on all copies of the software
  554. X made by the recipient.  
  555. X
  556. X All Rights Reserved. Permission is hereby granted for the recipient to make
  557. X copies and use this software for its own internal purposes only. Recipient of
  558. X this software may re-distribute this software outside of their own
  559. X institution. Permission to market this software commercially, to include this
  560. X product as part of a commercial product, or to make a derivative work for
  561. X commercial purposes, is explicitly prohibited.  All other uses are also
  562. X prohibited unless authorized in writing by the Regents of the University of
  563. X Michigan.
  564. X
  565. X This software is offered without warranty. The Regents of the University of
  566. X Michigan disclaim all warranties, express or implied, including but not
  567. X limited to the implied warranties of merchantability and fitness for any
  568. X particular purpose. In no event shall the Regents of the University of
  569. X Michigan be liable for loss or damage of any kind, including but not limited
  570. X to incidental, indirect, consequential, or special damages. 
  571. X******************************************************************************/
  572. X
  573. X#include <stdio.h>
  574. X
  575. X
  576. X#ifdef mips
  577. X#include <sys/types.h>
  578. X#include <sys/param.h>
  579. X#include <sys/mount.h>
  580. X
  581. X
  582. X#ifdef __STDC__
  583. Xlong getdisk(void)
  584. X#else
  585. Xlong getdisk()
  586. X#endif
  587. X{
  588. X    struct fs_data tempspace;
  589. X    
  590. X    if (statfs("/tmp", &tempspace) != 1)
  591. X        if (statfs("/tmp", &tempspace) != 1)
  592. X            tempspace.fd_req.bfreen = 0;
  593. X    
  594. X    if (tempspace.fd_req.bfreen < 0)
  595. X      tempspace.fd_req.bfreen = 0;
  596. X      
  597. X#ifdef DEBUG
  598. X      printf("%d  %d\n", tempspace.fd_req.btot, tempspace.fd_req.bfreen);
  599. X                 /*        TotalSpace^     Available User Space */
  600. X#endif
  601. X    
  602. X    return((long)tempspace.fd_req.bfreen);
  603. X}
  604. X#endif
  605. X
  606. X
  607. X#if (defined(sun) || defined(_AIX) || defined(hpux))
  608. X
  609. X#include <sys/types.h>
  610. X#if (defined(_AIX))
  611. X#include <sys/statfs.h>
  612. X#else
  613. X#include <sys/vfs.h>
  614. X#endif
  615. X
  616. X#ifdef __STDC__
  617. Xlong getdisk(void)
  618. X#else
  619. Xlong getdisk()
  620. X#endif
  621. X{
  622. X    struct statfs tempspace;
  623. X    long num;
  624. X    
  625. X    if (statfs("/tmp", &tempspace) != 0)
  626. X      if (statfs("/tmp", &tempspace) != 0)
  627. X        tempspace.f_bavail = 0;
  628. X        
  629. X    if (tempspace.f_bavail < 0)
  630. X      tempspace.f_bavail = 0;
  631. X          
  632. X#ifdef DEBUG
  633. X      printf("%d  %d\n", tempspace.f_bsize, tempspace.f_bavail);
  634. X    /*                 BlockSize^     Available User Space in blocks */
  635. X#endif
  636. X    
  637. X    num = (tempspace.f_bsize * tempspace.f_bavail) / 1024;
  638. X    return(num);
  639. X}
  640. X
  641. X#endif
  642. X
  643. X#ifdef apollo
  644. X
  645. X#include <sys/types.h>
  646. X#include <sys/statfs.h>
  647. X
  648. X#ifdef __STDC__
  649. Xlong getdisk(void)
  650. X#else
  651. Xlong getdisk()
  652. X#endif
  653. X{
  654. X    struct statfs tempspace;
  655. X    long num;
  656. X    
  657. X    if (statfs("/tmp", &tempspace,sizeof(tempspace),0) != 0)
  658. X      if (statfs("/tmp", &tempspace,sizeof(tempspace),0) != 0)
  659. X        tempspace.f_bfree = 0;
  660. X        
  661. X    if (tempspace.f_bfree < 0)
  662. X      tempspace.f_bfree = 0;
  663. X          
  664. X#ifdef DEBUG
  665. X      printf("%d  %d\n", tempspace.f_bsize, tempspace.f_bfree);
  666. X    /*                 BlockSize^     Available User Space in blocks */
  667. X#endif
  668. X    
  669. X    num = (tempspace.f_bfree);
  670. X    return(num);
  671. X}
  672. X
  673. X#endif
  674. X
  675. X#ifdef testing
  676. Xmain()
  677. X{
  678. X  printf("%d",getdisk());
  679. X}
  680. X#endif
  681. END_OF_FILE
  682.   if test 3505 -ne `wc -c <'netuse/daemons/getdisk.c'`; then
  683.     echo shar: \"'netuse/daemons/getdisk.c'\" unpacked with wrong size!
  684.   fi
  685.   # end of 'netuse/daemons/getdisk.c'
  686. fi
  687. if test -f 'netuse/daemons/getusers.c' -a "${1}" != "-c" ; then 
  688.   echo shar: Will not clobber existing file \"'netuse/daemons/getusers.c'\"
  689. else
  690.   echo shar: Extracting \"'netuse/daemons/getusers.c'\" \(3215 characters\)
  691.   sed "s/^X//" >'netuse/daemons/getusers.c' <<'END_OF_FILE'
  692. X/******************************************************************************
  693. X This code gets the user list.
  694. X
  695. X Hacked up by: Mike Neil.
  696. X
  697. X Copyright (C) 1990, 1991, 1992 by the Regents of the University of Michigan.
  698. X
  699. X User agrees to reproduce said copyright notice on all copies of the software
  700. X made by the recipient.  
  701. X
  702. X All Rights Reserved. Permission is hereby granted for the recipient to make
  703. X copies and use this software for its own internal purposes only. Recipient of
  704. X this software may re-distribute this software outside of their own
  705. X institution. Permission to market this software commercially, to include this
  706. X product as part of a commercial product, or to make a derivative work for
  707. X commercial purposes, is explicitly prohibited.  All other uses are also
  708. X prohibited unless authorized in writing by the Regents of the University of
  709. X Michigan.
  710. X
  711. X This software is offered without warranty. The Regents of the University of
  712. X Michigan disclaim all warranties, express or implied, including but not
  713. X limited to the implied warranties of merchantability and fitness for any
  714. X particular purpose. In no event shall the Regents of the University of
  715. X Michigan be liable for loss or damage of any kind, including but not limited
  716. X to incidental, indirect, consequential, or special damages. 
  717. X******************************************************************************/
  718. X#include <stdio.h>
  719. X#include <sys/types.h>
  720. X#include <utmp.h>
  721. X
  722. X#if (defined(mips) || defined(sun) || defined(hpux))
  723. X#include <sys/types.h>
  724. X#include <sys/stat.h>
  725. X#endif
  726. X
  727. X
  728. X#ifdef __STDC__
  729. Xint getusers(int *users,int *console)
  730. X#else
  731. Xint getusers(users,console)
  732. Xint *users;
  733. Xint *console;
  734. X#endif
  735. X{
  736. X    struct utmp user;
  737. X#ifdef hpux
  738. X        struct utmp *utptr;
  739. X#endif
  740. X#if (defined(mips) || defined(sun) || defined(hpux))
  741. X    struct stat buf;
  742. X#endif
  743. X    int etcutmp;
  744. X    int eof = 1;
  745. X    char line[9], name[9], host[17];
  746. X    
  747. X        *users=0;
  748. X        *console=0;
  749. X#if (defined(mips) || defined (sun) || defined(hpux))
  750. X    stat ("/dev/console" , &buf);
  751. X    if (buf.st_uid != 0) ++(*console);
  752. X#endif
  753. X
  754. X#ifdef hpux
  755. X        while (utptr=getutent()) {
  756. X                memcpy((char *)&user,(char *)utptr,sizeof(user));
  757. X                if (user.ut_type!=USER_PROCESS) continue;
  758. X        strncpy(name, user.ut_user, 8);
  759. X#else
  760. X    etcutmp = open("/etc/utmp", 0);
  761. X    while(read (etcutmp, (char *)&user, sizeof(struct utmp))) {
  762. X#if !(defined(sun) || defined(mips))
  763. X                if (user.ut_type!=USER_PROCESS) continue;
  764. X#endif
  765. X        strncpy(name, user.ut_name, 8);
  766. X#endif
  767. X        name[8] = '\0';
  768. X        strncpy(line, user.ut_line, 8);
  769. X        line[8] = '\0';
  770. X        strncpy(host, user.ut_host, 16);
  771. X        host[16] = '\0';
  772. X#ifdef testing
  773. X                printf("name= \"%s\"  line=\"%s\"  host=\"%s\"\n",
  774. X                       name,line,host);
  775. X#endif
  776. X        if (strlen(name)) {
  777. X            ++(*users);
  778. X#if (!defined(mips) && !defined(sun) && !defined(hpux))
  779. X            if (!strcmp(line,"console") || !strcmp(host,":0.0") ||
  780. X                            !strcmp(line,"display"))
  781. X            {
  782. X                ++(*console);
  783. X            }
  784. X#endif
  785. X        }
  786. X    }
  787. X#ifdef hpux
  788. X        endutent();
  789. X#else    
  790. X    close(etcutmp);
  791. X#endif      
  792. X        return(*users);
  793. X}
  794. X
  795. X
  796. X#ifdef testing
  797. Xmain()
  798. X{
  799. X     int u,c,rv;
  800. X
  801. X     rv=getusers(&u,&c);
  802. X     printf("Results:  rv=%d u=%d c=%d\n",rv,u,c);
  803. X}
  804. X#endif
  805. END_OF_FILE
  806.   if test 3215 -ne `wc -c <'netuse/daemons/getusers.c'`; then
  807.     echo shar: \"'netuse/daemons/getusers.c'\" unpacked with wrong size!
  808.   fi
  809.   # end of 'netuse/daemons/getusers.c'
  810. fi
  811. if test -f 'netuse/daemons/netuse.8' -a "${1}" != "-c" ; then 
  812.   echo shar: Will not clobber existing file \"'netuse/daemons/netuse.8'\"
  813. else
  814.   echo shar: Extracting \"'netuse/daemons/netuse.8'\" \(1935 characters\)
  815.   sed "s/^X//" >'netuse/daemons/netuse.8' <<'END_OF_FILE'
  816. X.TH netuse 8 "November 29, 1992" "" "CAEN - The University of Michigan"
  817. X.UC 4
  818. X.SH NAME
  819. Xnetuse \- NETUSE Host Monitor master daemon
  820. X.SH SYNOPSIS
  821. X.B netuse 
  822. X.SH DESCRIPTION
  823. X.I netuse
  824. Xis the master daemon which receives reports from all hosts running the 
  825. X.I netused
  826. Xdaemon at a given site.  It stores the reports from each monitored host, and
  827. Xresponds to requests for information from NETUSE clients (such as
  828. X.I getmach(1)
  829. Xand 
  830. X.I hostinfo(1).
  831. X.PP
  832. XThis daemon should run on only one machine at each site using NETUSE.  There
  833. Xare no features for redundancy or fallback servers.
  834. X.PP
  835. XThe 
  836. X.I netuseadmin(1)
  837. Xprogram is used to administer the
  838. X.I netuse
  839. Xdaemon remotely while it is running.
  840. X.SH COPYRIGHT
  841. XCopyright (C) 1992 by the Regents of the University of Michigan.
  842. X.PP
  843. XUser agrees to reproduce said copyright notice on all copies of the software
  844. Xmade by the recipient.  
  845. X.PP
  846. XAll Rights Reserved. Permission is hereby granted for the recipient to make
  847. Xcopies and use this software for its own internal purposes only. Recipient of
  848. Xthis software may re-distribute this software outside of their own
  849. Xinstitution. Permission to market this software commercially, to include this
  850. Xproduct as part of a commercial product, or to make a derivative work for
  851. Xcommercial purposes, is explicitly prohibited.  All other uses are also
  852. Xprohibited unless authorized in writing by the Regents of the University of
  853. XMichigan.
  854. X.PP
  855. XThis software is offered without warranty. The Regents of the University of
  856. XMichigan disclaim all warranties, express or implied, including but not
  857. Xlimited to the implied warranties of merchantability and fitness for any
  858. Xparticular purpose. In no event shall the Regents of the University of
  859. XMichigan be liable for loss or damage of any kind, including but not limited
  860. Xto incidental, indirect, consequential, or special damages. 
  861. X.SH SEE ALSO
  862. Xgetmach(1), hostinfo(1), netuseadmin(1), netused(8),
  863. X.I Monitoring Hosts with NETUSE
  864. END_OF_FILE
  865.   if test 1935 -ne `wc -c <'netuse/daemons/netuse.8'`; then
  866.     echo shar: \"'netuse/daemons/netuse.8'\" unpacked with wrong size!
  867.   fi
  868.   # end of 'netuse/daemons/netuse.8'
  869. fi
  870. if test -f 'netuse/daemons/netused.8' -a "${1}" != "-c" ; then 
  871.   echo shar: Will not clobber existing file \"'netuse/daemons/netused.8'\"
  872. else
  873.   echo shar: Extracting \"'netuse/daemons/netused.8'\" \(2757 characters\)
  874.   sed "s/^X//" >'netuse/daemons/netused.8' <<'END_OF_FILE'
  875. X.TH netused 8 "November 29, 1992" "" "CAEN - The University of Michigan"
  876. X.UC 4
  877. X.SH NAME
  878. Xnetused \- NETUSE Host Monitor monitoring/reporting daemon
  879. X.SH SYNOPSIS
  880. X.B netused [
  881. X.BR options
  882. X.B ]
  883. X.SH DESCRIPTION
  884. X.I netused
  885. Xis a daemon which runs on a host and periodically determines the status of the
  886. Xhost's usage and reports it to the NETUSE master daemon 
  887. X.I netuse(8).
  888. X.PP
  889. XWithout any options, 
  890. X.I netused
  891. Xruns as a perpetual daemon, exactly as described above.  The default periods
  892. Xfor checking the hosts's status and for reporting to the master daemon are
  893. Xdefined at compile time, but may be set using the -wakeup and -report options. 
  894. X.SH OPTIONS
  895. XThe following options may be used with the
  896. X.I netused
  897. Xcommand to specify variations on the daemon's usual operation.
  898. X.TP 16
  899. X-once
  900. XReport once to the server, then quit.  This is useful for adding the current
  901. Xhost to the NETUSE database.
  902. X.TP 16
  903. X-force
  904. XForce 
  905. X.I netused
  906. Xto run, even if it determines that it shouldn't because of other causes.  (See
  907. Xthe installation guide 
  908. X.I Monitoring Hosts with NETUSE).
  909. X.TP 16
  910. X-wakeup
  911. XSet the period (in seconds) between status checks.
  912. X.TP 16
  913. X-report
  914. XSet the time period (in seconds) between reports to the master daemon.  This
  915. Xshould be a multiple of the wakeup period.
  916. X.TP 16
  917. X-inetd
  918. XObsolete option informing 
  919. X.I netused 
  920. Xthat it is being run from the 
  921. X.I inetd(8) 
  922. Xdaemon.
  923. X.SH BUGS
  924. X.I netused
  925. Xcurrently doesn't seem to like RS/6000 load average computation under AIX 3.2.
  926. XThe load averages are computed correctly for AIX 3.1 versions.
  927. X.SH COPYRIGHT
  928. XCopyright (C) 1992 by the Regents of the University of Michigan.
  929. X.PP
  930. XUser agrees to reproduce said copyright notice on all copies of the software
  931. Xmade by the recipient.  
  932. X.PP
  933. XAll Rights Reserved. Permission is hereby granted for the recipient to make
  934. Xcopies and use this software for its own internal purposes only. Recipient of
  935. Xthis software may re-distribute this software outside of their own
  936. Xinstitution. Permission to market this software commercially, to include this
  937. Xproduct as part of a commercial product, or to make a derivative work for
  938. Xcommercial purposes, is explicitly prohibited.  All other uses are also
  939. Xprohibited unless authorized in writing by the Regents of the University of
  940. XMichigan.
  941. X.PP
  942. XThis software is offered without warranty. The Regents of the University of
  943. XMichigan disclaim all warranties, express or implied, including but not
  944. Xlimited to the implied warranties of merchantability and fitness for any
  945. Xparticular purpose. In no event shall the Regents of the University of
  946. XMichigan be liable for loss or damage of any kind, including but not limited
  947. Xto incidental, indirect, consequential, or special damages. 
  948. X.SH SEE ALSO
  949. Xgetmach(1), hostinfo(1), netuse(8), 
  950. X.I Monitoring Hosts with NETUSE
  951. END_OF_FILE
  952.   if test 2757 -ne `wc -c <'netuse/daemons/netused.8'`; then
  953.     echo shar: \"'netuse/daemons/netused.8'\" unpacked with wrong size!
  954.   fi
  955.   # end of 'netuse/daemons/netused.8'
  956. fi
  957. if test -f 'netuse/lib/config.h' -a "${1}" != "-c" ; then 
  958.   echo shar: Will not clobber existing file \"'netuse/lib/config.h'\"
  959. else
  960.   echo shar: Extracting \"'netuse/lib/config.h'\" \(4265 characters\)
  961.   sed "s/^X//" >'netuse/lib/config.h' <<'END_OF_FILE'
  962. X/******************************************************************************
  963. X CONFIG.H - NETUSE customization header file
  964. X
  965. X This header file defines site-dependent customizations.
  966. X
  967. X Lee Liming, Computer Aided Engineering Network
  968. X The University of Michigan
  969. X
  970. X Copyright (C) 1992 by the Regents of the University of Michigan.
  971. X
  972. X User agrees to reproduce said copyright notice on all copies of the software
  973. X made by the recipient.  
  974. X
  975. X All Rights Reserved. Permission is hereby granted for the recipient to make
  976. X copies and use this software for its own internal purposes only. Recipient of
  977. X this software may re-distribute this software outside of their own
  978. X institution. Permission to market this software commercially, to include this
  979. X product as part of a commercial product, or to make a derivative work for
  980. X commercial purposes, is explicitly prohibited.  All other uses are also
  981. X prohibited unless authorized in writing by the Regents of the University of
  982. X Michigan.
  983. X
  984. X This software is offered without warranty. The Regents of the University of
  985. X Michigan disclaim all warranties, express or implied, including but not
  986. X limited to the implied warranties of merchantability and fitness for any
  987. X particular purpose. In no event shall the Regents of the University of
  988. X Michigan be liable for loss or damage of any kind, including but not limited
  989. X to incidental, indirect, consequential, or special damages. 
  990. X******************************************************************************/
  991. X
  992. X#ifndef _CONFIG_INCLUDED_
  993. X#define _CONFIG_INCLUDED_
  994. X
  995. X
  996. X/*  The NETUSE_SERVER macro should expand to the IP hostname of the machine  */
  997. X/*  on which the netuse daemon for your site runs.                           */
  998. X
  999. X#define NETUSE_SERVER   "myhost.some.where"
  1000. X
  1001. X/*  At CAEN, we have some unusual ways of determining whether or not the     */
  1002. X/*  netused daemon should run on a given host.  The existence of USE_CAENLAB */
  1003. X/*  says that netused will use those CAEN-specific heuristics.  Other sites  */
  1004. X/*  should not use this.                                                     */
  1005. X
  1006. X/* #define USE_CAENLAB */
  1007. X
  1008. X/*  The name of the file in which the netused daemon stores problem reports. */
  1009. X
  1010. X#define NETUSEDLOG      "/tmp/netused.log"
  1011. X
  1012. X/*  The name of the file in which the netuse daemon stores log messages.     */
  1013. X
  1014. X#define NETUSELOG       "/usr/adm/netuse-req.log"
  1015. X
  1016. X/*  The name of the file in which the netuse daemon stores host information. */
  1017. X
  1018. X#define NETUSEHOSTFILE  "/usr/adm/netuse.hosts"
  1019. X
  1020. X/* The types of log messages that routinely get logged by the netuse daemon. */
  1021. X/* E.g., to log all NETUSE requests, uncomment LOGREQUESTS.  To log all      */
  1022. X/* wakeup calls sent by netuse, uncomment LOGWAKEUPS.  These log files can   */
  1023. X/* get pretty big, though...                                                 */
  1024. X
  1025. X/* #define LOGWAKEUPS */
  1026. X#define LOGREQUESTS
  1027. X
  1028. X/* The default port numbers and service names used by netuse and netused.    */
  1029. X
  1030. X#define NETUSED_PORT    1689           /* Used if /etc/services doesn't know */
  1031. X#define NETUSE_PORT     1690           /* Used if /etc/services doesn't know */
  1032. X#define NETUSED_SERVICE "netused"    /* Inet service name for client daemons */
  1033. X#define NETUSE_SERVICE  "netuse"      /* Inet service name for NETUSE server */
  1034. X
  1035. X/* The number of hosts to be listed by netuse if -all is not specified.      */
  1036. X
  1037. X#define MAXLSTLEN         10
  1038. X
  1039. X/* Number of minutes without a report from a node before netuse considers    */
  1040. X/* the node "down".                                                          */
  1041. X
  1042. X#define DOWNTIME          15
  1043. X
  1044. X/* Number of minutes without a report from a node before netuse deletes the  */
  1045. X/* node from its database.                                                   */ 
  1046. X
  1047. X#define GIVEUPTIME     10080
  1048. X
  1049. X/* Default period (in seconds) between reports by netused.                   */
  1050. X/* Note that AIX load averaging requires that netused wake up around once    */
  1051. X/* every 15 seconds, but it still reports once every 8 wakeups (2 min.)      */
  1052. X
  1053. X#ifdef _AIX
  1054. X#define DEFAULT_PERIOD    15           /* Period between wakeups for netused */
  1055. X#define REPORT_CYCLE       8       /* Number of wakeups in each report cycle */
  1056. X#else
  1057. X#define DEFAULT_PERIOD   120
  1058. X#define REPORT_CYCLE       1
  1059. X#endif
  1060. X
  1061. X
  1062. X#endif /* _CONFIG_INCLUDED_ */
  1063. END_OF_FILE
  1064.   if test 4265 -ne `wc -c <'netuse/lib/config.h'`; then
  1065.     echo shar: \"'netuse/lib/config.h'\" unpacked with wrong size!
  1066.   fi
  1067.   # end of 'netuse/lib/config.h'
  1068. fi
  1069. if test -f 'netuse/lib/netadmin.c' -a "${1}" != "-c" ; then 
  1070.   echo shar: Will not clobber existing file \"'netuse/lib/netadmin.c'\"
  1071. else
  1072.   echo shar: Extracting \"'netuse/lib/netadmin.c'\" \(6078 characters\)
  1073.   sed "s/^X//" >'netuse/lib/netadmin.c' <<'END_OF_FILE'
  1074. X/******************************************************************************
  1075. X NETADMIN.C - NETUSE Administration Client Library Routines
  1076. X
  1077. X The functions included here are for making administrative server requests.
  1078. X They are fairly powerful, and could be used to deny service to other clients,
  1079. X and are included in the library out of pure naivity (and because it wouldn't
  1080. X make any difference if they weren't).
  1081. X
  1082. X Lee Liming, The Computer Aided Engineering Network
  1083. X The University of Michigan
  1084. X
  1085. X Copyright (C) 1990, 1991, 1992 by the Regents of the University of Michigan.
  1086. X
  1087. X User agrees to reproduce said copyright notice on all copies of the software
  1088. X made by the recipient.  
  1089. X
  1090. X All Rights Reserved. Permission is hereby granted for the recipient to make
  1091. X copies and use this software for its own internal purposes only. Recipient of
  1092. X this software may re-distribute this software outside of their own
  1093. X institution. Permission to market this software commercially, to include this
  1094. X product as part of a commercial product, or to make a derivative work for
  1095. X commercial purposes, is explicitly prohibited.  All other uses are also
  1096. X prohibited unless authorized in writing by the Regents of the University of
  1097. X Michigan.
  1098. X
  1099. X This software is offered without warranty. The Regents of the University of
  1100. X Michigan disclaim all warranties, express or implied, including but not
  1101. X limited to the implied warranties of merchantability and fitness for any
  1102. X particular purpose. In no event shall the Regents of the University of
  1103. X Michigan be liable for loss or damage of any kind, including but not limited
  1104. X to incidental, indirect, consequential, or special damages. 
  1105. X******************************************************************************/
  1106. X
  1107. X#include <stdio.h>
  1108. X#include <sys/types.h>
  1109. X#ifdef IBMTCPIP
  1110. X#include <types.h>
  1111. X#endif
  1112. X#include <sys/socket.h>
  1113. X#include <netinet/in.h>
  1114. X#include <netdb.h>
  1115. X#include "network.h"
  1116. X#include "protocol.h"
  1117. X#include "netuse.h"
  1118. X
  1119. X
  1120. X/******************************************************************************
  1121. X int netuseAddName(char *name,u_short type,u_short model)
  1122. X
  1123. X This function adds a host given by name (internet hostname or an ASCII
  1124. X equivalent of the IP address) to the server's host list.  If no IP address
  1125. X for the host can be found, RV_NOMATCH is returned.  All other errors are
  1126. X passed directly back to the caller.  The host's vendor type should be given
  1127. X by the type parameter.
  1128. X******************************************************************************/
  1129. X
  1130. X#ifdef __STDC__
  1131. Xint netuseAddName(char *name,u_char type,u_char model)
  1132. X#else
  1133. Xint netuseAddName(name,type,model)
  1134. Xchar *name;
  1135. Xu_char type,model;
  1136. X#endif
  1137. X{
  1138. X     USEREC msg;
  1139. X     int rv;
  1140. X
  1141. X     msg.opcode=OP_ADDHOST;
  1142. X     msg.machine=type;
  1143. X     msg.model=model;
  1144. X     if (!(msg.ipaddr=netGetAddress(name))) return(RV_NOMATCH);
  1145. X#if (defined(MSDOS) || defined(OS2))
  1146. X     msg.uid=0;
  1147. X#else
  1148. X     msg.uid=getuid();
  1149. X#endif
  1150. X     if ((rv=packetSend(&msg))!=RV_nOK) return(rv);
  1151. X     if ((rv=packetReceive(&msg))!=RV_nOK) return(rv);
  1152. X     else return(msg.retcode);
  1153. X}
  1154. X
  1155. X
  1156. X/******************************************************************************
  1157. X int netuseAddIP(u_long ip_addr,u_short type)
  1158. X
  1159. X This function adds a host to the NETUSE server's host list using the numeric
  1160. X IP address instead of the hostname.  Again, the machine type should be given
  1161. X in the type parameter.  All errors are passed back to the caller.
  1162. X******************************************************************************/
  1163. X
  1164. X#ifdef __STDC__
  1165. Xint netuseAddIP(u_long ip_addr,u_short type)
  1166. X#else
  1167. Xint netuseAddIP(ip_addr,type)
  1168. Xu_long ip_addr;
  1169. Xu_short type;
  1170. X#endif
  1171. X{
  1172. X     USEREC msg;
  1173. X     int rv;
  1174. X
  1175. X     msg.opcode=OP_ADDHOST;
  1176. X     msg.machine=type;
  1177. X     msg.ipaddr=ip_addr;
  1178. X#if (defined(MSDOS) || defined(OS2))
  1179. X     msg.uid=0;
  1180. X#else
  1181. X     msg.uid=getuid();
  1182. X#endif
  1183. X     if ((rv=packetSend(&msg))!=RV_nOK) return(rv);
  1184. X     if ((rv=packetReceive(&msg))!=RV_nOK) return(rv);
  1185. X     else return(msg.retcode);
  1186. X}
  1187. X
  1188. X
  1189. X/******************************************************************************
  1190. X int netuseDelName(char *name)
  1191. X
  1192. X The host represented by the hostname given in name (or the IP address in text
  1193. X format in name) is removed from the NETUSE server's host list.
  1194. X******************************************************************************/
  1195. X
  1196. X#ifdef __STDC__
  1197. Xint netuseDelName(char *name)
  1198. X#else
  1199. Xint netuseDelName(name)
  1200. Xchar *name;
  1201. X#endif
  1202. X{
  1203. X     USEREC msg;
  1204. X     int rv;
  1205. X
  1206. X     msg.opcode=OP_DELHOST;
  1207. X     if (!(msg.ipaddr=netGetAddress(name))) return(RV_NOMATCH);
  1208. X#if (defined(MSDOS) || defined(OS2))
  1209. X     msg.uid=0;
  1210. X#else
  1211. X     msg.uid=getuid();
  1212. X#endif
  1213. X     if ((rv=packetSend(&msg))!=RV_nOK) return(rv);
  1214. X     if ((rv=packetReceive(&msg))!=RV_nOK) return(rv);
  1215. X     else return(msg.retcode);
  1216. X}
  1217. X
  1218. X
  1219. X/******************************************************************************
  1220. X int netuseSaveState(void)
  1221. X
  1222. X This function requests that the server save it's hostlist into the static
  1223. X host file.
  1224. X******************************************************************************/
  1225. X
  1226. X#ifdef __STDC__
  1227. Xint netuseSaveState(void)
  1228. X#else
  1229. Xint netuseSaveState()
  1230. X#endif
  1231. X{
  1232. X     USEREC msg;
  1233. X     int rv;
  1234. X
  1235. X     msg.opcode=OP_SAVESTATE;
  1236. X#if (defined(MSDOS) || defined(OS2))
  1237. X     msg.uid=0;
  1238. X#else
  1239. X     msg.uid=getuid();
  1240. X#endif
  1241. X     if ((rv=packetSend(&msg))!=RV_nOK) return(rv);
  1242. X     if ((rv=packetReceive(&msg))!=RV_nOK) return(rv);
  1243. X     else return(msg.retcode);
  1244. X}
  1245. X
  1246. X
  1247. X/******************************************************************************
  1248. X int netuseLoadHosts(void)
  1249. X
  1250. X This function requests the server to throw away all of the hosts in it's
  1251. X hostlist and load a new hostlist from the static host file.
  1252. X******************************************************************************/
  1253. X
  1254. X#ifdef __STDC__
  1255. Xint netuseLoadHosts(void)
  1256. X#else
  1257. Xint netuseLoadHosts()
  1258. X#endif
  1259. X{
  1260. X     USEREC msg;
  1261. X     int rv;
  1262. X
  1263. X     msg.opcode=OP_LOADHOSTS;
  1264. X#if (defined(MSDOS) || defined(OS2))
  1265. X     msg.uid=0;
  1266. X#else
  1267. X     msg.uid=getuid();
  1268. X#endif
  1269. X     if ((rv=packetSend(&msg))!=RV_nOK) return(rv);
  1270. X     if ((rv=packetReceive(&msg))!=RV_nOK) return(rv);
  1271. X     else return(msg.retcode);
  1272. X}
  1273. END_OF_FILE
  1274.   if test 6078 -ne `wc -c <'netuse/lib/netadmin.c'`; then
  1275.     echo shar: \"'netuse/lib/netadmin.c'\" unpacked with wrong size!
  1276.   fi
  1277.   # end of 'netuse/lib/netadmin.c'
  1278. fi
  1279. if test -f 'netuse/lib/variable.h' -a "${1}" != "-c" ; then 
  1280.   echo shar: Will not clobber existing file \"'netuse/lib/variable.h'\"
  1281. else
  1282.   echo shar: Extracting \"'netuse/lib/variable.h'\" \(5615 characters\)
  1283.   sed "s/^X//" >'netuse/lib/variable.h' <<'END_OF_FILE'
  1284. X/*****************************************************************************
  1285. X VARIABLE.H - The variable management module's header file
  1286. X
  1287. X Defines: typedef   VARENTRY
  1288. X          typedef   VARTABLE
  1289. X          int       varHashName(u_long name);
  1290. X          VARENTRY *varAllocate(void);
  1291. X          void      varFreeTable(void);
  1292. X          void      varSet(VARENTRY *var);
  1293. X          VARENTRY *varFindMatch(VARENTRY *template);
  1294. X          VARENTRY *varFind(u_long ip_addr);
  1295. X          int       varSaveState(void);
  1296. X          int       varLoadHosts(void);
  1297. X          void      varInit();
  1298. X          void      varDumpTable(char *fname);
  1299. X          void      treeInsert(TREE **tptr,VARENTRY *vptr);
  1300. X          void      treeBuild(u_char machtype);
  1301. X          void      treePrintHost(FILE *outf,TREE *tptr);
  1302. X          void      treeDump(FILE *outf,TREE *tptr,u_char opcode,int *i);
  1303. X          void      treePrintList(FILE *outf,u_char machtype,u_char opcode);
  1304. X
  1305. X Copyright (C) 1990, 1991, 1992 by the Regents of the University of Michigan.
  1306. X
  1307. X User agrees to reproduce said copyright notice on all copies of the software
  1308. X made by the recipient.  
  1309. X
  1310. X All Rights Reserved. Permission is hereby granted for the recipient to make
  1311. X copies and use this software for its own internal purposes only. Recipient of
  1312. X this software may re-distribute this software outside of their own
  1313. X institution. Permission to market this software commercially, to include this
  1314. X product as part of a commercial product, or to make a derivative work for
  1315. X commercial purposes, is explicitly prohibited.  All other uses are also
  1316. X prohibited unless authorized in writing by the Regents of the University of
  1317. X Michigan.
  1318. X
  1319. X This software is offered without warranty. The Regents of the University of
  1320. X Michigan disclaim all warranties, express or implied, including but not
  1321. X limited to the implied warranties of merchantability and fitness for any
  1322. X particular purpose. In no event shall the Regents of the University of
  1323. X Michigan be liable for loss or damage of any kind, including but not limited
  1324. X to incidental, indirect, consequential, or special damages. 
  1325. X******************************************************************************/
  1326. X
  1327. X#ifndef _VARIABLE_INCLUDED_
  1328. X
  1329. X#define _VARIABLE_INCLUDED_
  1330. X
  1331. X
  1332. X#define VAR_ENTRIES   113            /* Number of entries in the hash table */
  1333. X
  1334. X
  1335. Xtypedef struct _user {
  1336. X             char         *name;
  1337. X             char         *tty;
  1338. X             struct _user *next;
  1339. X        } USER,*USERLIST;
  1340. X
  1341. Xtypedef struct _varentry {
  1342. X             char             *name;                 /* The variable's name */
  1343. X             u_long            ip_addr;                       /* IP address */
  1344. X             char             *class;                        /* Entry class */
  1345. X             float             l1,l2,l3;             /* Load average values */
  1346. X             u_long            tmp;                      /* kb free on /tmp */
  1347. X             u_char            machine;                  /* Type of machine */
  1348. X             u_char            model;               /* Machine's model type */
  1349. X             long              lastused;        /* Time of entry's last use */
  1350. X             long              logtime;              /* Time of last update */
  1351. X             int               users;      /* How many users are logged in? */
  1352. X             int               console;        /* Is anyone on the console? */
  1353. X             USERLIST          userFirst;               /* Who is logged in */
  1354. X             struct _varentry *next;    /* Link to next entry in hash chain */
  1355. X        } VARENTRY;
  1356. Xtypedef VARENTRY *VARTABLE[VAR_ENTRIES];         /* The variable hash table */
  1357. X
  1358. Xtypedef struct _nodetree {
  1359. X             VARENTRY         *data;
  1360. X             struct _nodetree *left,*right;
  1361. X        } TREE;
  1362. X
  1363. X
  1364. X#ifdef __STDC__
  1365. X
  1366. Xint       varHashName(u_long name);
  1367. XUSER     *userAllocate(void);
  1368. Xvoid      userFree(USER *uptr);
  1369. Xvoid      userFreeList(USER *uptr);
  1370. XVARENTRY *varAllocate(void);
  1371. Xvoid      varFree(VARENTRY *vptr);
  1372. Xvoid      varFreeTable(void);
  1373. Xvoid      varSet(VARENTRY *var);
  1374. XVARENTRY *varFindMatch(VARENTRY *template);
  1375. XVARENTRY *varFind(u_long ip_addr);
  1376. Xvoid      varDumpTable(char *fname);
  1377. Xvoid      varDumpTableWithModels(char *fname);
  1378. Xint       varSaveState(void);
  1379. Xint       varLoadHosts(void);
  1380. Xvoid      varInit(void);
  1381. Xvoid      treeInsert(TREE **tptr,VARENTRY *vptr);
  1382. Xvoid      treeBuild(u_char machtype,u_char modeltype);
  1383. Xvoid      treePrintHost(FILE *outf,TREE *tptr);
  1384. Xvoid      treeDump(FILE *outf,TREE *tptr,u_char opcode,int *i);
  1385. Xvoid      treePrintList(FILE *outf,u_char machtype,u_char modeltype,
  1386. X                        u_char opcode);
  1387. Xvoid      treePrintHostWithModels(FILE *outf,TREE *tptr);
  1388. Xvoid      treeDumpWithModels(FILE *outf,TREE *tptr,u_char opcode,int *i);
  1389. Xvoid      treePrintListWithModels(FILE *outf,u_char machtype,u_char modeltype,
  1390. X                                  u_char opcode);
  1391. X
  1392. X#else  /* ifndef __STDC__ */
  1393. X
  1394. Xint       varHashName();
  1395. XUSER     *userAllocate();
  1396. Xvoid      userFree();
  1397. Xvoid      userFreeList();
  1398. XVARENTRY *varAllocate();
  1399. Xvoid      varFree();
  1400. Xvoid      varFreeTable();
  1401. Xvoid      varSet();
  1402. XVARENTRY *varFindMatch();
  1403. XVARENTRY *varGetValue();
  1404. Xint       varSaveState();
  1405. Xint       varLoadHosts();
  1406. Xvoid      varInit();
  1407. Xvoid      varDumpTable();
  1408. Xvoid      varDumpTableWithModels();
  1409. Xint       varSaveState();
  1410. Xint       varLoadHosts();
  1411. Xvoid      varInit();
  1412. Xvoid      treeInsert();
  1413. Xvoid      treeBuild();
  1414. Xvoid      treePrintHost();
  1415. Xvoid      treeDump();
  1416. Xvoid      treePrintList();
  1417. Xvoid      treePrintHostWithModels();
  1418. Xvoid      treeDumpWithModels();
  1419. Xvoid      treePrintListWithModels();
  1420. X
  1421. X#endif
  1422. X
  1423. X#endif  /* _VARIABLE_INCLUDED_ */
  1424. END_OF_FILE
  1425.   if test 5615 -ne `wc -c <'netuse/lib/variable.h'`; then
  1426.     echo shar: \"'netuse/lib/variable.h'\" unpacked with wrong size!
  1427.   fi
  1428.   # end of 'netuse/lib/variable.h'
  1429. fi
  1430. echo shar: End of archive 5 \(of 6\).
  1431. cp /dev/null ark5isdone
  1432. MISSING=""
  1433. for I in 1 2 3 4 5 6 ; do
  1434.     if test ! -f ark${I}isdone ; then
  1435.     MISSING="${MISSING} ${I}"
  1436.     fi
  1437. done
  1438. if test "${MISSING}" = "" ; then
  1439.     echo You have unpacked all 6 archives.
  1440.     rm -f ark[1-9]isdone
  1441. else
  1442.     echo You still must unpack the following archives:
  1443.     echo "        " ${MISSING}
  1444. fi
  1445. exit 0
  1446. exit 0 # Just in case...
  1447.