home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / qinfo.exe / GETQINFO.C next >
Text File  |  1995-01-11  |  9KB  |  294 lines

  1. /****************************************************************************
  2. **      DISCLAIMER
  3. **
  4. **   Novell, Inc. makes no representations or warranties with respect to
  5. **   any NetWare software, and specifically disclaims any express or
  6. **   implied warranties of merchantability, title, or fitness for a
  7. **   particular purpose.
  8. **
  9. **   Distribution of any NetWare software is forbidden without the
  10. **   express written consent of Novell, Inc.  Further, Novell reserves
  11. **   the right to discontinue distribution of any NetWare software.
  12. **
  13. **   Novell is not responsible for lost profits or revenue, loss of use
  14. **   of the software, loss of data, costs of re-creating lost data, the
  15. **   cost of any substitute equipment or program, or claims by any party
  16. **   other than you.  Novell strongly recommends a backup be made before
  17. **   any software is installed.   Technical support for this software
  18. **   may be provided at the discretion of Novell.
  19. ****************************************************************************
  20. **
  21. **   File: GETQINFO.C
  22. **
  23. **   Desc: This program will read the bindery of the default server into
  24. **         a linked list.  It will then (using the linked list) read the
  25. **         servers one at a time and attach to each server in the list and
  26. **         find the print servers on that server.  It will write the server
  27. **         names to a file call SERVERS.TXT and the print servers to
  28. **         QUEINFO.TXT along with the print servers object ID.
  29. **
  30. **   Programmers:
  31. **   Ini   Who         Firm
  32. **   ------------------------------------------------------------------
  33. **   ARM   A. Ray Maxwell     Novell Developer Support.
  34. **
  35. **   History:
  36. **
  37. **   ------------------------------------------------------------------
  38. **   1-10-95   ARM   First code.
  39. */
  40.  
  41. /***************************************************************************
  42. **   Include headers, macros, function prototypes, etc.
  43. */
  44.  
  45.     /*------------------------------------------------------------------
  46.     **   ANSI
  47.     */
  48.     #include <stdlib.h>          /* exit(), atol()        */
  49.     #include <stdio.h>           /* fprintf()             */
  50.     #include <string.h>
  51.     #include <malloc.h>
  52.     #include <mem.h>
  53.    #include <conio.h>           /* kbhit()               */
  54.     #define  slot  100
  55.  
  56.     /*------------------------------------------------------------------
  57.     **   NetWare
  58.     */
  59.     #include <nwcalls.h>
  60.    #include <nwlocale.h>
  61.    #include <nwnet.h>
  62.    #include <nwndscon.h>
  63.     #include <nwerror.h>
  64.     #define NWDOS
  65.  
  66.  
  67.  
  68.     /*------------------------------------------------------------------
  69.     ** Gobal parameters
  70.     */
  71.     struct {
  72.       BYTE accountExpiraionDate[3];
  73.       BYTE accountDisableFlag;
  74.       BYTE passwordExpiraionDate[3];
  75.       BYTE graceLogin;
  76.       WORD passwordExpirationIntervals;
  77.       BYTE graceLoginResetValue;
  78.       BYTE minPasswordLength;
  79.       WORD maxConcurrentConnections;
  80.      BYTE allowedLoginTimeBitmap[42];
  81.      BYTE lastLoginDateTime[6];
  82.      BYTE restrictionFlags;
  83.      BYTE reserved;
  84.      DWORD maxDiskUsageInBlocks;
  85.      WORD badLoginCount;
  86.      DWORD nextResetTime;
  87.      BYTE badLoginAddr[12];
  88.      BYTE padding[43];
  89.    } loginControl;
  90.  
  91.    typedef struct list {
  92.       char        Fserver[48];
  93.       NWOBJ_ID    ObjectID;
  94.       struct list *link;
  95.     } Slist;
  96.  
  97.    typedef Slist *fptr;         // struct variable ServerList
  98.    fptr ptr = NULL;
  99.    fptr p1  = NULL;
  100.     fptr p2  = NULL;
  101. /*****************************************************************************
  102. ** Program Start
  103. */
  104. void main(void)
  105. {
  106.     WORD           ccode;                        /* value for return code    */
  107.     WORD           defaultID, connID1,connID2,connID3,tempConn;
  108.     NWOBJ_ID       objectID = -1;                /* same as unsigned int     */
  109.     char           objectName[48];
  110.     char           searchObjectName[48];
  111.     NWOBJ_TYPE     objType;
  112.     NWFLAGS NWFAR  *hasPropertiesFlag;
  113.     NWFLAGS        objFlag;
  114.     NWFLAGS        objSec;
  115.     NWLOCAL_MODE   mode = 0;                    /* NWGetConnectionList stuff */
  116.     NWCONN_HANDLE  *connListBuffer;
  117.     NWSTRUCT_SIZE  connListSize;
  118.     NWNUMBER NWFAR *numConnections;
  119.     NWNUMBER       maxConns = 8;
  120.     WORD           connType;
  121.     CONNECT_INFO   connInfo;
  122.     NWSTRUCT_SIZE  connInfoSize;
  123.     DWORD NWFAR    *seq = -1;
  124.     char NWFAR     *queueName;
  125.     int            True = 0;
  126.     int            n = 0;
  127.     FILE *fp, *fp1;
  128.  
  129.     ptr       =  (fptr)calloc(sizeof(Slist),1);
  130.     ptr->link = NULL;
  131.     p1        = ptr;
  132.  
  133.     fp=fopen("servers.txt","w+");
  134.     fp1=fopen("queinfo.txt","w+");
  135.  
  136.     ccode = NWCallsInit(NULL,NULL);
  137.     if (ccode)
  138.         printf("NWCallsInit failed\n");
  139.  
  140.     ccode = NWGetDefaultConnectionID(&defaultID);
  141.  
  142.     if(ccode){
  143.         printf("\n Error in getting connection ID: %x\n", ccode);
  144.         exit(0);
  145.    }
  146.    /*-----------------------------------------------------------------------
  147.    ** Get the print server names and object ID's.
  148.     */
  149.     while ( !ccode) {
  150.       ccode = NWScanObject (defaultID,
  151.                                     "*",
  152.                                     OT_FILE_SERVER,
  153.                                     &objectID,
  154.                                     objectName,
  155.                                     &objType,
  156.                                     &hasPropertiesFlag,
  157.                                     &objFlag,
  158.                                     &objSec );
  159.  
  160.       if (ccode) {
  161.           printf("NWScanObject failed: %x\n", ccode);
  162.           break;  // exit(0);
  163.       }
  164.  
  165.  
  166.      if(objType == OT_FILE_SERVER) {
  167.           printf("Server  Name: %s  ObjectID: %08lX\n",
  168.                      objectName,NWLongSwap(objectID));
  169.  
  170.           strcpy(p1->Fserver,objectName);
  171.  
  172.           p1->ObjectID = objectID;
  173.           p2 = (fptr)malloc(sizeof(struct list));
  174.           p2->link = NULL;
  175.           p1->link = p2;
  176.           p1 = p2;
  177.       }
  178.     }/* end while */
  179.  
  180.     /*-----------------------------------------------------------------------
  181.    **  Check the linklist and print it to the file server.txt
  182.    */
  183.  
  184.     printf("\n\n");
  185.     p1 = ptr;
  186.     do {
  187.         printf("ServerName : %s , ID : %08lX\n",p1->Fserver, NWLongSwap(p1->ObjectID));
  188.         fprintf(fp,"ServerName : %s , ID : %08lX\n",p1->Fserver, NWLongSwap(p1->ObjectID));
  189.         p1 = p1->link;
  190.     } while(p1->link != NULL);
  191.     fclose(fp);
  192.     printf("\n\n");
  193.  
  194.     // Preparing for Scan
  195.     objectID = -1L;
  196.     printf("\nPRNCODE  ...ver 1.3d\n");
  197.     ccode = 0;
  198.     p1 = ptr;
  199.  
  200.     while (p1->link != NULL && (!kbhit())) {
  201.  
  202.         ccode = NWAttachToFileServer( p1->Fserver,
  203.                                                 NULL,
  204.                                                 &connID1);
  205.       printf("\nNWAttach... %s, %x",p1->Fserver,ccode);
  206.       switch(ccode){
  207.          case 0x0000 : printf("Attach Successful on %s\n",p1->Fserver);
  208.                               break;
  209.          case 0x8800 : printf("Already attached to %s\n",p1->Fserver);
  210.                        break;
  211.             case 0x8801 : printf("Invalid Connection to %s\n",p1->Fserver);
  212.                        break;
  213.          case 0x8847 : 
  214.          case 0x89FC : printf("Unknown or no server found\n");
  215.                        break;
  216.          default :   break;
  217.       }
  218.       if(ccode==0x0000){
  219.            ccode = NWGetConnectionHandle(p1->Fserver,
  220.                                                    NULL,
  221.                                                    &connID1,
  222.                                                    NULL);
  223.  
  224.            if (ccode)
  225.                printf("\nNWGetConnHandle failed... %x on %s\n",ccode,p1->Fserver);
  226.                                     
  227.       }
  228.  
  229.       if (ccode==0x0000  || ccode==0x8800){
  230.            ccode = NWGetConnectionStatus(connID1,
  231.                                                 &connInfo,
  232.                                                 connInfoSize);
  233.  
  234.            if (ccode) 
  235.             printf("\nGet Conn Status failed... %x\n",ccode);
  236.            if (connInfo.connectFlags & CONNECTION_NDS) {
  237.                printf("\nAn NDS connection is already established to %s.\n",
  238.                p1->Fserver);
  239.                exit(0);
  240.            }
  241.            while ( True == 0  && (!kbhit()))  {
  242.                ccode = NWScanObject (  connID1,
  243.                                                 "*",
  244.                                                OT_WILD,
  245.                                                &objectID,
  246.                                                 objectName,
  247.                                                 &objType,
  248.                                                 &hasPropertiesFlag,
  249.                                                 &objFlag,
  250.                                                 &objSec );
  251.  
  252.                 if (objType == OT_PRINT_QUEUE)
  253.                     fprintf(fp1,"PrnQ: %s  Server: %s  ccode: %4x Object ID %08Xl\n",
  254.                             objectName,p1->Fserver,ccode,NWLongSwap(objectID));
  255.                 else if(ccode){
  256.                             fprintf(fp1,"NWScanObject failed : %X\n",ccode);
  257.                             True=-1;
  258.                         }
  259.             }
  260.  
  261.             ccode = NWGetConnectionStatus(connID1,
  262.                                                 &connInfo,
  263.                                                 sizeof(CONNECT_INFO));
  264.  
  265.             if (ccode)
  266.                 printf("\nGet Conn Status failed... %x\n",ccode);
  267.             if (connInfo.connectFlags & CONNECTION_NDS) {
  268.                 printf("\nAn NDS connection is already established to %s.\n",
  269.                 p1->Fserver);
  270.                 exit(0);
  271.             }
  272.             if (connInfo.connectFlags & CONNECTION_LOGGED_IN)
  273.                 printf("this is the default server\n");
  274.             else
  275.                 ccode = NWDetachFromFileServer(connID1);
  276.         }
  277.         else
  278.             fprintf(fp,"\nserver %s could not be found\n",p1->Fserver);
  279.  
  280.         p1 = p1->link;
  281.         objectID = -1L;
  282.         True = 0;
  283.  
  284.     }
  285.     if (p1->link == NULL)
  286.         printf("\nEndOfLList, NULL encountered");
  287.     else printf("\n leavingPGM.. last server used: %s, ccode: %4x" ,
  288.         p1->Fserver,ccode);
  289.  
  290.     free(ptr);
  291.     fcloseall();
  292.  
  293.  } /* end of main */
  294.