home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / N / TCPIP / BWNFSD.TAR / bwnfsd / bwprint.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-14  |  5.2 KB  |  233 lines

  1. /*
  2. VERSION  2.3a
  3. MODIFIED 02/10/92
  4.  
  5.     BWNFSD is an RPC daemon used in conjunction with BWNFS ( a client NFS
  6. for DOS based PCs. BWNFSD provides Authentication, Print Spooling, 
  7. DOS 3.1 Locking, DOS 3.1 Sharing, GID name mapping, UID name mapping services
  8. for BWNFS and associated applications on the PC. BWNFSD is being used also
  9. by Macintosh NFS clients.
  10.  
  11.     The BWNFSD code is originally copyright Beame & Whiteside Software Ltd.
  12. and now is released to the Public Domain. The intent is that all server vendors
  13. included a version of BWNFSD with their operating system. BWNFSD can run
  14. simultantiously as PCNFSD, but provides many more features.
  15.  
  16.     Please send modifications to:
  17.  
  18.         Beame & Whiteside Software Ltd.
  19.         P.O. Box 8130 
  20.         Dundas, Ontario
  21.         Canada L9H 5E7
  22.         +1 (416) 765-0822
  23.  
  24.     Please modify by including "ifdefs" for your particular operating 
  25. system, with appropriate modifications to the "makefile".
  26.  
  27. BWPRINT.C provides the print spool services for BWNFS. This is where most
  28. modification needs to be done as it is coded mainly for BSD systems, not
  29. System V.
  30.  
  31. */
  32. #include <stdio.h>
  33. #include <sys/types.h>
  34. #include <sys/stat.h>
  35. #ifdef SCO
  36. #include <signal.h>
  37. #endif
  38. #ifdef SYSV32
  39. #ifndef SCO
  40. #define sgi
  41. #endif
  42. #include <string.h>
  43. #else
  44. #include <strings.h>
  45. #endif
  46.  
  47. int     debugmode;
  48.  
  49.  
  50. void print_it(file,printer,jobname)
  51. char    *file,*printer,*jobname;
  52. {
  53.     struct printies
  54.     {
  55.         char *name;
  56.         void (*routine)();
  57.     };
  58.     
  59.     void    default_print();
  60.  
  61.     static    struct printies    print_list[] = {
  62.         "lp" , default_print,
  63. /*
  64.         "your printer" , your_printer_routine,
  65. */
  66.         };
  67.  
  68. #define PRINT_COUNT sizeof(print_list)/sizeof(struct printies)
  69.  
  70.     int    i;
  71.  
  72.     struct stat buf;
  73.  
  74.         if (debugmode)
  75.     {
  76.           (void) fprintf( stdout, "bwnfsd: [print_it] called\n" );
  77.           (void) fprintf( stdout, "bwnfsd: Filename = %s\nbwnfsd: Jobname = %s\nbwnfsd: Printer = %s\n",
  78.                           file, jobname, printer );
  79.     }
  80.     if ( stat(file,&buf) == 0 )
  81.     {
  82.         setuid(buf.st_uid);
  83.         setgid(buf.st_gid);
  84.     }
  85.  
  86.  
  87.     for ( i = 0 ; i < PRINT_COUNT; i++)
  88.       if ( strcmp(printer,print_list[i].name) == 0)
  89.       {
  90.             if (debugmode)
  91.               (void) fprintf( stdout, "bwnfsd: [print_it] using %s\n", printer );
  92.         (*print_list[i].routine)(file,printer,jobname);
  93.           return;
  94.       }
  95.         if (debugmode)
  96.           (void) fprintf( stdout, "bwnfsd: [print_it] using default_print\n" );
  97.     default_print(file,printer,jobname);
  98. }
  99.  
  100.  
  101. void default_print(file,printer,jobname)
  102. char    *file,*printer,*jobname;
  103. {
  104.     char    *argys[20];
  105.     int    ac;
  106. #ifdef sgi
  107.     char zots[255], zoots[255];
  108. #endif
  109. #ifdef SCO
  110.     int    pid;
  111. #endif
  112.  
  113.     ac=0;
  114. #ifndef sgi
  115. #ifdef SCO
  116.            argys[ac++]="/usr/bin/lp";
  117.     argys[ac++]="lp";
  118.     argys[ac++]="-d";
  119.     argys[ac++]=printer;
  120.     argys[ac++]="-c";
  121.     argys[ac++]="-s";
  122. #else
  123. #ifdef LINUX
  124.            argys[ac++]="/usr/bin/lp";
  125.     argys[ac++]="lp";
  126.     argys[ac++]="-d";
  127.     argys[ac++]=printer;
  128.     argys[ac++]="-c";
  129.     argys[ac++]="-s";
  130. #else
  131.            argys[ac++]="/usr/ucb/lpr";
  132.     argys[ac++]="lpr";
  133.     argys[ac++]="-P";
  134.     argys[ac++]=printer;
  135.     argys[ac++]="-r";
  136. #endif    /* LINUX */
  137. #endif
  138. #else
  139. #ifdef AIX
  140.            argys[ac++]="/bin/enq";
  141.     argys[ac++]="enq";
  142.     strcpy(zots,"-P");
  143. #else
  144.            argys[ac++]="/usr/bin/lp";
  145.     argys[ac++]="lp";
  146.     strcpy(zots,"-d");
  147. #endif
  148.     strcat(zots,printer);
  149.     argys[ac++]=zots;
  150.     argys[ac++]="-c";
  151. #ifndef AIX
  152.     argys[ac++]="-s";
  153. #endif
  154. #endif
  155.         if (debugmode)
  156.           (void) fprintf( stdout, "bwnfsd: [default_print] called\n" );
  157.  
  158.     if ( jobname != NULL)
  159.     {
  160. #ifndef sgi
  161. #ifdef SCO
  162.         argys[ac++]="-t";
  163. #else
  164.         argys[ac++]="-T";
  165. #endif
  166.         argys[ac++]=jobname;
  167.         argys[ac++]=file;
  168.         argys[ac++]=NULL;
  169. #else
  170.         strcpy(zoots,"-T");
  171.         strcat(zoots,jobname);
  172.         argys[ac++]=zoots;
  173.         argys[ac++]=file;
  174.         argys[ac++]=NULL;
  175. #endif
  176.     }
  177.     else
  178.     {
  179.         argys[ac++]=file;
  180.         argys[ac++]=NULL;
  181.     }
  182. #ifndef sgi
  183. #ifdef SCO
  184.     chmod( file, 0777 );
  185.     signal( SIGCLD, SIG_IGN );
  186.     if ((pid = fork()) == 0)
  187.     {
  188.       if (debugmode)
  189.         (void) fprintf( stdout, "bwnfsd: [default_print] execv %s, %s\n",
  190.                         argys[0], argys[1] );
  191.           execv(argys[0],&argys[1]);
  192.           exit(1);
  193.     }
  194.         if (debugmode)
  195.           (void) fprintf( stdout, "bwnfsd: [default_print] calling waitpid %u\n", uid );
  196.     waitpid(pid,NULL,0);
  197. #else
  198.         if (debugmode)
  199.       (void) fprintf( stdout, "bwnfsd: [default_print] execv %s, %s\n",
  200.                       argys[0], argys[1] );
  201.            execv(argys[0],&argys[1]);
  202. #endif
  203. /***
  204.    * If we get here, it means that the print failed. We unlink the
  205.    * printfile to prevent lots of queued files. This may not be appropriate
  206.    * for your application or for debugging purposes.
  207.    ***/
  208.    if (debugmode)
  209.      (void) fprintf( stdout, "bwnfsd: [default_print] print failed, unlinking print-file\n" );
  210. #else
  211.     chmod(file,0777);
  212.     if (fork() == 0)
  213.     {
  214.           if (debugmode)
  215.             (void) fprintf( stdout, "bwnfsd: [default_print] execv %s, %s\n",
  216.                             argys[0], argys[1] );
  217.           execv(argys[0],&argys[1]);
  218.         }
  219.     wait(NULL);
  220.  
  221. /* --------------------------------------------------------
  222.    If you are encountering defunct (zombie) processes, then
  223.    this might be a good place to start looking
  224.    -------------------------------------------------------- */
  225. #endif
  226.         if (debugmode)
  227.           (void) fprintf( stdout, "bwnfsd: [default_print] unlinking %s\n", file );
  228.     (void) unlink(file);
  229.  
  230. }
  231.  
  232.  
  233.