home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / S12381.ZIP / NETACADD.C
C/C++ Source or Header  |  1989-09-01  |  4KB  |  167 lines

  1. /*  Compilation and  Linking
  2.  
  3.     cl -Alfw -Zl -Gs -c netacadd.c
  4.     link netacadd,,,netapi
  5.  
  6.     Usage:
  7.        netacadd -n<number of users> -s<\\servername>
  8.     Comments:
  9.     This program demonstrates the usage of NetAccessAdd.
  10.     1.   The following parameter should be set in lanman.ini
  11.           [server]
  12.           security = user
  13.     2.   All users for whom an access record will be added by netacadd.c
  14.          should be added in users account before running the program.
  15.          (Net admin ->Accounts->add)
  16.  
  17.     DisClaimer:
  18.        THIS PROGRAM IS FOR DEMONSTRATION ONLY. MICROSOFT MAKES NO WARRANTY
  19.        , EITHER EXPRESSED OR IMPLIED, AS TO IT'S USABILITY IN ANY GIVEN
  20.        SITUATION.
  21. */
  22.  
  23.  
  24.  
  25.  
  26. #define INCL_BASE
  27. #include <os2.h>
  28.  
  29. #include <netcons.h>
  30. #include <access.h>
  31. #include <neterr.h>
  32.  
  33. #include <stdio.h>
  34. #include <malloc.h>
  35.  
  36. /*
  37.  * Defines
  38.  */
  39. #define ckerr(rcode,mess) { \
  40.     if (rcode) { \
  41.         printf (error, __LINE__, #rcode, rcode, mess);  \
  42.         exit (rcode); \
  43.         } \
  44.     }
  45.  
  46. #define MAXLISTSIZE    10
  47. #define AUDIT        0x01
  48. #define NOAUDIT     0x00
  49. #define SERVERNAME    "\\\\SERVER"
  50.  
  51. typedef struct access_info_1 InfAccess;
  52. typedef struct access_list   InfList;
  53.  
  54. /*
  55.  * Global Values
  56.  */
  57. char  error[] = "ERROR at line %d, %s = %d, %s";
  58. char  MEMERR[]= "Malloc failed. Out of memory?";
  59.  
  60.  /*** main
  61.  *
  62.  *
  63.  */
  64.  main (int argc, char *argv[])
  65.  {
  66.  
  67.  INT suser, i;
  68.  CHAR server[UNLEN+2], c;
  69.  CHAR *buffer;
  70.  USHORT buflen;
  71.  SHORT level=1 ;                /* Level 1 */
  72.  InfAccess *access_header;            /* pointer to access_info_1 */
  73.  InfList   *access_list;            /* pointer to access_list    */
  74.  USHORT rc;
  75.  CHAR    Resource[20];                /* Resource Name        */
  76.     /*
  77.     *    Default Values
  78.     */
  79.     suser = MAXLISTSIZE;
  80.     strcpy(server, SERVERNAME);
  81.  
  82.     /***
  83.     *  Find out Number of Users and Server Name  from Command Line
  84.     */
  85.  
  86.     if (argc > 1) {
  87.  
  88.        for (i = 1; i <argc ; i++) {
  89.      if (argv[i][0]=='-') {
  90.         switch ( argv[i][1] ) {
  91.  
  92.            case 'n': sscanf(argv[i], "%c%c%i",&c,&c, &suser);
  93.  
  94.              break;
  95.            case 's': sscanf(argv[i], "%c%c%s",&c,&c, server);
  96.  
  97.  
  98.              break;
  99.  
  100.            default : printf("Usage: netacadd -n -s\n");
  101.              printf("Taking default values\n");
  102.              break;
  103.          }
  104.  
  105.       }
  106.     }
  107.  
  108.      }
  109.      /*
  110.      *    Allocate buffer for access_info_1 and acces_list
  111.      *    Assign values to the structure fields
  112.      */
  113.  
  114.      buflen = sizeof(InfAccess) + sizeof(InfList) * suser;
  115.      buffer = (CHAR  *) malloc(buflen);
  116.      if (buffer==NULL) {
  117.         printf("%s", MEMERR);
  118.         exit(0);
  119.       }
  120.      access_header = (InfAccess *) buffer;
  121.      access_list   = (InfList *) (buffer + sizeof(InfAccess));
  122.  
  123.      printf("Name of the Resource:");
  124.      scanf("%s", Resource);
  125.      c = getchar();
  126.      printf("\n");
  127.      access_header->acc1_resource_name = (CHAR *) Resource;
  128.  
  129.      printf("\n Auditing on this resource:[y]");
  130.  
  131.      if ((c = getchar())=='n')
  132.     access_header->acc1_attr = NOAUDIT;
  133.      else
  134.     access_header->acc1_attr = AUDIT;
  135.  
  136.      access_header->acc1_count = suser;
  137.  
  138.      /*
  139.       *   Get User Names
  140.      */
  141.  
  142.  
  143.      for (i=0; i< suser; i++) {
  144.  
  145.     printf("[%i] User Name: ", i+1);
  146.     scanf("%s", access_list->acl_ugname);
  147.     printf("\n");
  148.     /*
  149.      *  Assume ACCESS_READ permissions.
  150.     */
  151.  
  152.     access_list->acl_access = ACCESS_READ;
  153.     access_list += 1;
  154.      }
  155.  
  156.      rc =  NetAccessAdd( (CHAR FAR *) server,           /* Name of the server */
  157.              level,                /* Level of detail    */
  158.              (CHAR FAR *) buffer,           /* Buffer         */
  159.              buflen);               /* Buffer Length      */
  160.      if (rc)
  161.        ckerr(rc, "NetAccessAdd");
  162.  
  163.      printf("User Access addedd successfully\n");
  164.  
  165.  
  166. }
  167.