[comp.protocols.appletalk] CAP 5.0 aufs patches for application accounting

koreth@ssyx.ucsc.edu (Steven Grimm) (03/29/89)

These are patches to aufs.c and afpfork.c, to keep track of application
launching on aufs volumes.  They allow the creation of an accounting
logfile (specified with the -A option) which contains server pids, time/
date of launching, and application name.  This logfile can be run through
a parser (which I will post to the net shortly) to determine simultaneous
program usage for licensing purposes.

One eventual use will be to determine the number of simultaneous users
who should be allowed to run individual applications, to conform to
licensing agreements.  We are working on code to limit simultaneous
invocations of administrator-specified files; those diffs will also
be posted when ready.

Note that these changes were made with Budd's lwsrv accounting patches
already present, so if you haven't applied those, you might have to edit
these before applying them.

Questions, comments, and theories to koreth@ssyx.ucsc.edu.

---
Steven Grimm				koreth@ssyx.ucsc.edu
Division of Social Sciences		uunet!ucbvax!ucscc!ssyx!koreth
University of California, Santa Cruz	"A waist is a terrible thing to mind."


*** aufs.c.old	Fri Mar 24 16:03:20 1989
--- aufs.c	Sat Mar 25 16:36:04 1989
***************
*** 80,85 ****
--- 80,86 ----
  private char *guestid = NULL;	/* any guest ids? */
  private char *coredir = NULL;	/* place to put coredumps */
  export char *userlogindir = NULL;	/* budd -- name of userlogin file */
+ export char *appl_logfile = NULL;	/* koreth -- application logfile */
  export int mcs, qs;		/* maxcmdsize and quantum size */
  export int sqs = atpMaxNum;	/* maximum send quantum */
  export int n_rrpkts = atpMaxNum; /* maximum send quantum to allow remote */
***************
*** 90,96 ****
  private char zonetorun[34];	/* zone to run in if different than std. */
  private char logfile[MAXPATHLEN]; /* log file name if any */
  private int parent_pid;		/* pid of main server */
! private int mypid;		/* pid of running process */
  private int nomoresessions = FALSE; /* set true of out of asp sessions */
  private int sesscount = 0;	/* number of asp sessions active */
  private int cno = -1;		/* current connection */
--- 91,97 ----
  private char zonetorun[34];	/* zone to run in if different than std. */
  private char logfile[MAXPATHLEN]; /* log file name if any */
  private int parent_pid;		/* pid of main server */
! export int mypid;		/* pid of running process */
  private int nomoresessions = FALSE; /* set true of out of asp sessions */
  private int sesscount = 0;	/* number of asp sessions active */
  private int cno = -1;		/* current connection */
***************
*** 160,165 ****
--- 161,167 ----
  
    fprintf(stderr,"usage: %s [-d cap-flags] [-a afp-levels] ",name);
    fprintf(stderr,"[-n name] [-t packets] [-s] [-V afpvols] [-X usrfile]\n"); /* budd */
+   fprintf(stderr,"[-A appl-log]\n");	/* koreth */
    fprintf(stderr,"\t-d for CAP debugging flags:\n");
    fprintf(stderr,"\t   l = lap, d = ddp, a = atp, n = nbp, p = pap,");
    fprintf(stderr,"i = ini, s = asp\n");
***************
*** 180,185 ****
--- 182,188 ----
    fprintf(stderr,"\t-S <n> limit responses to <n> packets\n");
    fprintf(stderr,"\t-R <n> limit remote to sending <n> packets\n");
    fprintf(stderr,"\t-X datafile of logged in users\n"); /* budd */
+   fprintf(stderr,"\t-A <filename> to log application launching\n");
    fprintf(stderr,"\nExample: %s -t 'bdelete irename' -a 'file fork dir' -s\n",
  	  name);
    exit(1);
***************
*** 211,218 ****
    extern char *optarg;
    extern int optind;
    
!   while ((c = getopt(argc,argv,"a:d:D:n:N:t:sV:U:G:P:c:l:z:S:R:X:")) != EOF) {
      switch (c) {
      case 'z':
        strncpy(zonetorun, optarg, 32);
        break;
--- 214,224 ----
    extern char *optarg;
    extern int optind;
    
!   while ((c = getopt(argc,argv,"a:A:d:D:n:N:t:sV:U:G:P:c:l:z:S:R:X:")) != EOF) {
      switch (c) {
+     case 'A':
+       appl_logfile = optarg;
+       break;
      case 'z':
        strncpy(zonetorun, optarg, 32);
        break;
***************
*** 398,403 ****
--- 404,412 ----
    if( userlogindir != NULL ) {		/* budd... */
        log("Aufs: user login database in %s", userlogindir );
    } /* ...budd */
+   if (appl_logfile != NULL) 
+     log("Application logfile in %s", appl_logfile);
+   log_appl(NULL, NULL);	/* open the application logfile */
  
    ctp_stack_cnt = 0;
    { int i;
***************
*** 1024,1029 ****
--- 1033,1064 ----
  #endif /* USEVPRINTF */
    putc('\n', fp);
    fflush(fp);
+ }
+ 
+ /*
+  * if appropriate, log the server pid, time, and application name to
+  * the application logfile, so that accounting can be done
+  *   -koreth@ssyx.ucsc.edu
+  */
+ log_appl(finderinfo, file)
+ char *finderinfo, *file;
+ {
+   static FILE *fp = NULL;
+ 
+   if ((appl_logfile != NULL) && ((finderinfo == NULL) ||
+ 			(! strncmp(finderinfo, "APPL", 4))))
+   {
+     if (fp == NULL)
+       if ((fp = fopen(appl_logfile, "a+")) == NULL)
+         log("Couldn't open application logfile %s", appl_logfile);
+     if ((fp != NULL) && (finderinfo != NULL))
+     {
+       fprintf(fp, "%05d: ", mypid);
+       tmprt(fp);
+       fprintf(fp, "%s\n", file);
+       fflush(fp);
+     }
+   }
  }
  
  tmprt(fp)
*** afpfork.c.old	Fri Mar 24 16:03:16 1989
--- afpfork.c	Sat Mar 25 16:36:26 1989
***************
*** 312,320 ****
    if (err == aeObjectNotFound)
      ofn->ofn_flgs |= OF_NOTOPEN;
  
    if (flg == F_DATA) {
      /* Never translate resource fork */
-     OSGetFNDR(ipdir, file, finderinfo); /* check file type */
      if ((ttidx = ncs_istrans(finderinfo, file)) >= 0) {
        ofn->ofn_trans_table = ttidx;
        if (DBFRK)
--- 312,320 ----
    if (err == aeObjectNotFound)
      ofn->ofn_flgs |= OF_NOTOPEN;
  
+   OSGetFNDR(ipdir, file, finderinfo); /* check file type */
    if (flg == F_DATA) {
      /* Never translate resource fork */
      if ((ttidx = ncs_istrans(finderinfo, file)) >= 0) {
        ofn->ofn_trans_table = ttidx;
        if (DBFRK)
***************
*** 321,326 ****
--- 321,328 ----
  	printf("Open fork: translation table: %s\n", ncs_tt_name(ttidx));
      }
    }
+ 
+   log_appl(finderinfo, file);
  
    strcpy(ofn->ofn_fnam,file);	/* remember file name (UGH!!!!) */