home *** CD-ROM | disk | FTP | other *** search
/ Beijing Paradise BBS Backup / PARADISE.ISO / software / BBSDOORW / NETCLB35.ZIP / NETCLB35.EXE / EXAMPLES / TLIST.C < prev    next >
C/C++ Source or Header  |  1996-01-03  |  7KB  |  213 lines

  1. /***************************************************************************/
  2. /* File:             TLIST.C                                               */
  3. /*                                                                         */
  4. /* Function:         Output all trustee paths of all currently logged in   */
  5. /*                   users, or of the specified user.                      */
  6. /*                                                                         */
  7. /* Usage:            tlist <user>                                          */
  8. /*                                                                         */
  9. /* Functions Called: GetConnectionInformation                              */
  10. /*                   GetBinderyObjectID                                    */
  11. /*                   ReadPropertyValue                                     */
  12. /*                   GetBinderyObjectName                                  */
  13. /*                   ScanBinderyObjectTrusteePaths                         */
  14. /*                   GetPreferredConnectionID                              */
  15. /*                   GetDefaultConnectionID                                */
  16. /*                   GetPrimaryConnectionID                                */
  17. /*                   SetPreferredConnectionID                              */
  18. /*                   ISShellLoaded                                         */
  19. /*                                                                         */
  20. /***************************************************************************/
  21. #include <sys\types.h>
  22. #include <sys\stat.h>
  23. #include <io.h>
  24. #include <errno.h>
  25. #include <conio.h>
  26. #include <dos.h>
  27. #ifndef TURBOC
  28. #include <search.h>
  29. #endif
  30. #include <stdlib.h>
  31. #include <stdio.h>
  32. #include <string.h>
  33. #include <time.h>
  34. #include <fcntl.h>
  35.  
  36. #include "netware.h"
  37.  
  38. void get_paths(long id);
  39. void set_rights(char mask,char *rights);
  40. void get_ident(int object_type,char *object_name,char *ident);
  41.  
  42. void main(int argc,char *argv[])
  43. {
  44. int r;
  45. char uname[OBJECT_LENGTH];
  46. long uid;
  47. int segment;
  48. nw_long *o_ptr;
  49. int count;
  50. long gid;
  51. int ot;
  52. char on[OBJECT_LENGTH];
  53. byte ltime[7];
  54. char ident[128];
  55.  
  56. char pvalue[128];
  57. byte pmoresegments;
  58. byte pflag;
  59. int thisserver,prefserver;
  60.  
  61.     if (argc>2)
  62.     {
  63.        printf("Too many parameters supplied\n");
  64.        exit(1);
  65.     }
  66.     else
  67.     if (IsShellLoaded() != SUCCESS)
  68.     {
  69.        printf("*** No netware shell loaded ***\n");
  70.        exit(255);
  71.     }
  72.  
  73.     if ((prefserver = GetPreferredConnectionID()) == 0)
  74.     {
  75.        if ((thisserver = GetDefaultConnectionID()) == 0)
  76.           thisserver = GetPrimaryConnectionID();
  77.        SetPreferredConnectionID( thisserver );
  78.     }  
  79.     else
  80.        thisserver = prefserver;
  81.  
  82.     if (argc == 2)
  83.        strcpy(uname,argv[1]);
  84.     else
  85.     {
  86.        /* No user name supplied - so get current connection */
  87.  
  88.        r=GetConnectionInformation((word)GetConnectionNumber(),
  89.                                   uname,&ot,&uid,ltime);
  90.        if (r != SUCCESS)
  91.        {
  92.           printf("Failed getting connection user: %d\n",r);
  93.           if (thisserver != prefserver)   /* reset preferred server */
  94.              SetPreferredConnectionID( prefserver );
  95.           exit(4);
  96.        }
  97.     }
  98.  
  99.     if((r=GetBinderyObjectID(USER,uname,&uid)) == SUCCESS)
  100.     {
  101.         get_ident(USER,uname,ident);
  102.         printf("User: %s     %s\n",uname,ident);
  103.         get_paths(uid);
  104.  
  105.         /* search out all groups */
  106.  
  107.         pmoresegments=0xff;
  108.  
  109.         for(segment=1;
  110.             ((r==SUCCESS)&&(pmoresegments != 0));
  111.             segment++)
  112.         {
  113.            r=ReadPropertyValue(USER,uname,GROUPS_IN,segment,
  114.                                pvalue,&pmoresegments,&pflag);
  115.            if (r==0xec)
  116.            {
  117.               r=SUCCESS;
  118.               pmoresegments = 0;
  119.            }
  120.            else
  121.            if (r != SUCCESS)
  122.            {
  123.               printf("ReadPropertyValue failed: %02.2x\n",r);
  124.               if (thisserver != prefserver)   /* reset preferred server */
  125.                  SetPreferredConnectionID( prefserver );
  126.               exit(2);
  127.            }
  128.            else
  129.            {
  130.               o_ptr=(nw_long *)&pvalue[0];
  131.  
  132.               gid=-1L;
  133.  
  134.               for(count=0;
  135.                   ((count<32) && (r==SUCCESS) && (gid != 0));count++)
  136.                 if ((gid=ConvertNWLongToLong(o_ptr++)) != 0)
  137.                 {
  138.                    r=GetBinderyObjectName(gid,&ot,on);
  139.                    if (r==SUCCESS)
  140.                    {
  141.                       get_ident(USER_GROUP,on,ident);
  142.                       printf("  Group: %-32.32s     %s\n",on,ident);
  143.                       get_paths(gid);
  144.                    }
  145.                 }
  146.            }
  147.         }
  148.     }
  149.     if(r != SUCCESS)
  150.     {
  151.        printf("Failed res:%02.2x\n",r);
  152.        if (thisserver != prefserver)   /* reset preferred server */
  153.           SetPreferredConnectionID( prefserver );
  154.        exit(3);
  155.     }
  156.     if (thisserver != prefserver)   /* reset preferred server */
  157.        SetPreferredConnectionID( prefserver );
  158.     exit(0);
  159. }
  160.  
  161. void get_paths(long id)
  162. {
  163. int volume,r=SUCCESS;
  164. int sequence=0;
  165. char mask;
  166. char path[DIR_PATH_LENGTH];
  167. char m[9];
  168.  
  169.      for(volume=0;(volume<32)&&(r==SUCCESS);volume++)
  170.      {
  171.             while (r==SUCCESS)
  172.             {
  173.                r=ScanBinderyObjectTrusteePaths(id,(byte)volume,
  174.                                                &sequence,&mask,path);
  175.                if (r==SUCCESS)
  176.                {
  177.                  set_rights(mask,m);
  178.                  printf("        [%s] %s\n",m,path);
  179.                }
  180.             }
  181.             if (r==NO_MORE_PATHS)
  182.                r=SUCCESS;
  183.      }
  184. }
  185.  
  186. static char all_masks[]={RT_READ,RT_WRITE,RT_OPEN,RT_CREATE,
  187.                          RT_DELETE,RT_OWNERSHIP,RT_SEARCH,RT_MODIFY};
  188. static char all_rights[]="rwocdpsm";
  189.  
  190. void set_rights(char mask,char *rights)
  191. {
  192. int i;
  193.    for(i=0;i<8;i++)
  194.       if((mask & all_masks[i]) == 0)
  195.          *rights++=' ';
  196.       else
  197.          *rights++=all_rights[i];
  198.    *rights=0x00;
  199. }
  200.  
  201. void get_ident(int object_type,char *object_name,char *ident)
  202. {
  203. char pvalue[128];
  204. byte pmoresegments;
  205. byte pflag;
  206.  
  207.    if(ReadPropertyValue(object_type,object_name,
  208.                         IDENT,1,pvalue,&pmoresegments,&pflag) != SUCCESS)
  209.      *ident='\0';
  210.    else
  211.      strcpy(ident,pvalue);
  212. }
  213.