home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / binscn.exe / BINDERY.C next >
Text File  |  1995-01-25  |  12KB  |  311 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:    bindery.c
  22. **
  23. **   Desc:    Allows the user to scan the bindery for Objects Properties and
  24. **            values. These are then written to a file called Bindery.txt.
  25. **
  26. **
  27. **   Parameter descriptions:    > input
  28. **                              < output
  29. **
  30. **        
  31. **   Programmers:
  32. **   Init   Who               Firm
  33. **   ------------------------------------------------------------------
  34. **   ARM      A. Ray Maxwell  Novell Developer Support.
  35. **
  36. **   History:
  37. **       
  38. **   ------------------------------------------------------------------
  39. **   06-20-94  ARM   First code.
  40. **   09-29-94  ARM   Added the code to allow Object names and Type to be 
  41. **                   entered from the command line.
  42. */
  43.  
  44. /****************************************************************************
  45. **   Include headers, macros, function prototypes, etc.
  46. */
  47.  
  48.    /*------------------------------------------------------------------------
  49.    **   ANSI
  50.    */
  51.    #include <stdio.h>
  52.    #include <stdlib.h>
  53.    #include <string.h>    /* strupr() strcpy() */
  54.    #include <conio.h>     /* clrscr()           */
  55.  
  56.    /*------------------------------------------------------------------------
  57.    **   NetWare
  58.    */
  59.    #include <nwcalls.h>
  60.  
  61.    /*------------------------------------------------------------------------
  62.    **   Defines
  63.    */
  64.    #define NWDOS
  65.    #define SIZEOFOBJNAME  48
  66.    #define SIZEOFPROPNAME 15
  67.    #define SEGSIZE        128  /* size of the data segment to be read */
  68.  
  69.  
  70.  
  71.  
  72. /****************************************************************************
  73. **   Main program start
  74. */
  75. void main(int argc,char *argv[])
  76. {
  77.  
  78.    int i, j;
  79.    FILE *fp;
  80.  
  81.    NWCONN_HANDLE connHandle;
  82.    
  83.    /*--------------------------------------------------------------------------
  84.    ** NWScanObject perameter definitions
  85.    */
  86.    NWOBJ_TYPE    objectType,
  87.                  searchObjectType,
  88.                  temptype;
  89.    NWOBJ_ID      objectID,id1;
  90.    NWCCODE       ccode;
  91.    NWFLAGS       hasprops;
  92.    NWFLAGS       objectFlag;
  93.    NWFLAGS       objectSecurity;
  94.    char          objectName[SIZEOFOBJNAME],
  95.                  buff[SIZEOFOBJNAME],
  96.                  searchObjectName[SIZEOFOBJNAME];
  97.    char          servername[SIZEOFOBJNAME];
  98.    /*--------------------------------------------------------------------------
  99.    ** NWScanProperty perameter definitions
  100.    */
  101.  
  102.    long          sequenceNumber;
  103.    char          propertyName[SIZEOFPROPNAME];
  104.    char          searchPropertyName[SIZEOFPROPNAME];
  105.    NWFLAGS       propertyFlags;
  106.    NWFLAGS       propertySecurity;
  107.    NWFLAGS       hasValueFlag;
  108.    NWFLAGS       moreFlag;
  109.    NWSEGMENT_NUM dataSetIndex = 1;  /* init to one on the first pass */
  110.    NWSEGMENT_NUM dataBuffer[SEGSIZE];
  111.  
  112.    /*--------------------------------------------------------------------------
  113.    ** NWReadPropertyValue perameter definitions
  114.    */
  115.  
  116.    NWFLAGS valueMoreFlag;
  117.  
  118.  
  119.    ccode=NWCallsInit(NULL,NULL);
  120.    if (ccode)
  121.       exit(1);
  122.    if (argc > 1){
  123.       argv++;
  124.       strcpy(servername,strupr(*argv));
  125.       strcpy(searchObjectName,"*");
  126.       if (argc > 2){
  127.          argv++;
  128.          strcpy(searchObjectName,strupr(*argv));
  129.       }
  130.       else
  131.          strcpy(searchObjectName,"*");
  132.  
  133.  
  134.       if (argc > 3) {
  135.          ++argv;
  136.          if (!strcmp (*argv,"*"))
  137.             searchObjectType=OT_WILD;
  138.             else
  139.                 searchObjectType = (strtoul(*argv,(char**)NULL,0));
  140.                 searchObjectType = (NWWordSwap)(strtoul(*argv,(char**)NULL,0));
  141.         }
  142.       else
  143.          searchObjectType = OT_WILD;
  144.       if (argc > 4) {
  145.          argv++;
  146.          strcpy(searchPropertyName,strupr(*argv));
  147.       }
  148.       else
  149.          strcpy(searchPropertyName,"*");
  150.  
  151.    }
  152.    else {
  153.       clrscr();
  154.       printf ("USAGE: bindery <server name> [object name] [object type] [property name]\n");
  155.       printf ("               servername=name of the NetWare server.\n");
  156.       printf ("               object name= \"*\" if WILD otherwise SUPERVISOR, GUEST etc\n");
  157.       printf ("               object type= \"*\" if WILD otherwise 1,2,etc.\n");
  158.       printf ("               property Name= LOGIN_CONTROL etc.\n");
  159.       exit(1);
  160.    }
  161.  
  162.    ccode=NWCallsInit(NULL,NULL);
  163.  
  164.    ccode = NWGetConnectionHandle(
  165.            /* > servername        */ servername,
  166.            /*   Novell Reserved1  */ 0,
  167.            /* < connection Handle */ &connHandle,
  168.            /*   Novell Reserved2  */ NULL);
  169.  
  170.  
  171.    //ccode= NWGetDefaultConnectionID(&connHandle);
  172.    
  173.    if (ccode)
  174.       exit(1);
  175.  
  176.    fp=fopen("bindery.txt","w+");
  177.    if (fp==NULL)
  178.       exit(1);
  179.  
  180.    objectID=-1;
  181.  
  182.  
  183.    while(!(ccode = NWScanObject(
  184.                /* > conn Handle                       */ connHandle,
  185.                /* > pointer to object name            */ searchObjectName,
  186.                /* > object type                       */ searchObjectType,
  187.                /* < pointer obj id -1 to start        */ &objectID,
  188.                /* < pointer next name optional        */ objectName,
  189.                /* < pointer next type optional        */ &objectType,
  190.                /* < pointer Properties flag optional  */   &hasprops,
  191.                /* < pointer Object flag byte optional */   &objectFlag,
  192.                /* < pointer Security mask of matching
  193.                     object  optional                  */ &objectSecurity)) ){
  194.       if (ccode)
  195.          exit(1);
  196.       else{
  197.          fprintf(fp,"\nObject: %s\n",objectName);
  198.  
  199.          fprintf(fp,"\t\t-> ID: %08lX     Type: %X     Class: %-7s\n",
  200.                   NWLongSwap(objectID),
  201.                   NWWordSwap(objectType),
  202.                   (objectFlag ? "dynamic":"static"));
  203.  
  204.          fprintf(fp,"\t\tSecurity: %X     Has Properties: %s\n",
  205.                   objectSecurity,
  206.                   hasprops ? "Yes":"No");
  207.       }
  208.       if(hasprops){
  209.          sequenceNumber=-1;
  210.  
  211.          while (!(ccode = NWScanProperty (
  212.                         /* > conn Handle                  */ connHandle,
  213.                         /* > pointer set's object name    */ objectName,
  214.                         /* > Set's bindery object type    */ objectType,
  215.                         /* > pointer property name        */ searchPropertyName,
  216.                         /* < pointer for repeate calls 
  217.                             optional                     */ &sequenceNumber,
  218.                         /* < pointer next name optional   */ &propertyName,
  219.                         /* < pointer status flag optional */ &propertyFlags,
  220.                         /* < pointer security mask 
  221.                             optional                     */ &propertySecurity,
  222.                         /* < does property have value     */ &hasValueFlag,
  223.                         /* < are there more properties    */ &moreFlag))){
  224.             if(ccode){
  225.                printf("NWScanProperty failed: %X\n",ccode);
  226.                break;
  227.             }
  228.  
  229.             fprintf(fp,"\nPROPERTY:\n");
  230.             fprintf(fp,"\t%-15s\n",propertyName);
  231.  
  232.  
  233.  
  234.             fprintf(fp, "\t\tClass: %-7s Type: %-4s  Sec: %X  Val: %s\n\t\t",
  235.                      (propertyFlags & BF_DYNAMIC) ? "dynamic":"static",
  236.                      (propertyFlags & BF_SET) ? "set":"item",
  237.                      propertySecurity,
  238.                      (hasValueFlag) ? "Yes" : "No");
  239.  
  240.             if(hasValueFlag){
  241.                dataSetIndex=1;
  242.                do{
  243.                   ccode=NWReadPropertyValue(
  244.                         /* > conn HANDLE                 */ connHandle,
  245.                         /* > Pointer object name         */ &objectName,           
  246.                         /* > object type                 */ objectType,            
  247.                         /* > pointer name of property    */ &propertyName,
  248.                         /* > segment number of data      */ dataSetIndex,
  249.                         /* < pointer 128 byte receive buf*/ dataBuffer,
  250.                         /* < pointer to flag             */ &valueMoreFlag,
  251.                         /* < pointer property type   (opt) */ &propertyFlags);
  252.                   if (ccode){
  253.                      printf("NWReadPropertyValue failed: %d\n",ccode);
  254.                      break;
  255.                   }
  256.                   else if (propertyFlags & 2) {
  257.                      for (j=0,i=0;i<32;i++){
  258.  
  259.                      /*-----------------------------------------------------
  260.                      **    propertyValue is 128 bytes and the objectID is 4
  261.                      **    bytes long therefore 32X4=128
  262.                      */
  263.                         id1 = *(long *)&dataBuffer[i * 4];
  264.                         if(id1){
  265.                            if (ccode = NWGetObjectName(
  266.                                        /* > conn Handle         */ connHandle,
  267.                                        /* > object ID           */ id1,
  268.                                        /* < pointer Object name */ buff,
  269.                                        /* < pointer Object type */ &temptype)){
  270.                                 printf(buff,
  271.                                    "NWGetObjectName:failed %04x\n",ccode);
  272.                                 buff[0]= NULL;
  273.                              }
  274.  
  275.                              fprintf(fp,"%-20.20s ",buff);
  276.                              if (++j > 2) {
  277.                                 j = 0;
  278.                                 printf("\n\t\t");
  279.                              }
  280.                         }
  281.                      } /* for */
  282.                   }
  283.                   else {
  284.                     for (j=0, i=0; i<128; i++) {
  285.                       fprintf(fp,"%02x ",dataBuffer[i]);
  286.                       if (++j > 15) {
  287.                         j=0;
  288.                         fprintf(fp,"\n\t\t");
  289.                       }
  290.                     } /* for */
  291.                   }
  292.                   dataSetIndex++; /*index on each call to NWreadPropertyValue*/
  293.  
  294.                }while(valueMoreFlag!=0);
  295.                dataSetIndex=1;
  296.             }
  297.  
  298.          }/* end while */;
  299.       } /* end if */
  300.  
  301.    }
  302.    fclose(fp);            
  303. }
  304.  
  305.  
  306.  
  307.  
  308.  
  309.                                                                                                                                                               
  310.                                                                                                                      
  311.