Print this page
NEX-13644 File access audit logging
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
Reviewed by: Saso Kiselkov <saso.kiselkov@nexenta.com>
Reviewed by: Rick McNeal <rick.mcneal@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/auditreduce/option.c
          +++ new/usr/src/cmd/auditreduce/option.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
       24 + *
       25 + * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
  24   26   */
  25   27  
  26   28  /*
  27   29   * Command line option processing for auditreduce.
  28   30   * The entry point is process_options(), which is called by main().
  29   31   * Process_options() is the only function visible outside this module.
  30   32   */
  31   33  
  32   34  #include <locale.h>
  33   35  #include <sys/zone.h>   /* for max zonename length */
↓ open down ↓ 28 lines elided ↑ open up ↑
  62   64                          { "pid", OBJ_PROC },
  63   65                          { "procgroup", OBJ_PGROUP },
  64   66                          { "procowner", OBJ_POWNER },
  65   67                          { "semid", OBJ_SEM  },
  66   68                          { "semgroup", OBJ_SEMGROUP  },
  67   69                          { "semowner", OBJ_SEMOWNER  },
  68   70                          { "shmid", OBJ_SHM  },
  69   71                          { "shmgroup", OBJ_SHMGROUP  },
  70   72                          { "shmowner", OBJ_SHMOWNER  },
  71   73                          { "sock", OBJ_SOCK },
  72      -                        { "user", OBJ_USER } };
       74 +                        { "user", OBJ_USER },
       75 +                        { "wsid", OBJ_WSID } };
  73   76  
  74   77  extern int      derive_date(char *, struct tm *);
  75   78  extern int      parse_time(char *, int);
  76   79  extern char     *re_comp2(char *);
  77   80  extern time_t   tm_to_secs(struct tm *);
  78   81  
  79   82  static int      a_isnum(char *, int);
  80   83  static int      check_file(audit_fcb_t *, int);
  81   84  static int      gather_dir(char *);
  82   85  static audit_pcb_t *get_next_pcb(char *);
↓ open down ↓ 6 lines elided ↑ open up ↑
  89   92  static int      proc_id(char *, int);
  90   93  static int      proc_object(char *);
  91   94  static void     proc_pcb(audit_pcb_t *, char *, int);
  92   95  static int      proc_label(char *);
  93   96  static int      proc_subject(char *);
  94   97  static int      proc_sid(char *);
  95   98  static int      proc_type(char *);
  96   99  static int      proc_user(char *, uid_t *);
  97  100  static int      proc_zonename(char *);
  98  101  static int      proc_fmri(char *);
      102 +static int      proc_wsid(char *);
  99  103  
 100  104  /*
 101  105   * .func        process_options - process command line options.
 102  106   * .desc        Process the user's command line options. These are of two types:
 103  107   *      single letter flags that are denoted by '-', and filenames. Some
 104  108   *      of the flags have arguments. Getopt() is used to get the flags.
 105  109   *      When this is done it calls process_fileopt() to handle any filenames
 106  110   *      that were there.
 107  111   * .call        ret = process_options(argc, argv).
 108  112   * .arg argc    - the original value.
↓ open down ↓ 8 lines elided ↑ open up ↑
 117  121          int     error = FALSE;
 118  122          int     error_combo = FALSE;
 119  123          extern int      optind;         /* in getopt() */
 120  124          extern char     *optarg;        /* in getopt() - holds arg to flag */
 121  125  
 122  126          static char     *options = "ACD:M:NQR:S:VO:"
 123  127              "a:b:c:d:e:g:j:l:m:o:r:s:t:u:z:";
 124  128  
 125  129          error_str = gettext("general error");
 126  130  
      131 +        wsid = NULL;
 127  132          zonename = NULL;
 128  133          /*
 129  134           * Big switch to process the flags.
 130  135           * Start_over: is for handling the '-' for standard input. Getopt()
 131  136           * doesn't recognize it.
 132  137           */
 133  138  start_over:
 134  139          while ((opt = getopt(argc, argv, options)) != EOF) {
 135  140                  switch (opt) {
 136  141                  case 'A':               /* all records from the files */
↓ open down ↓ 266 lines elided ↑ open up ↑
 403  408          case OBJ_FOWNER:
 404  409          case OBJ_MSGOWNER:
 405  410          case OBJ_SEMOWNER:
 406  411          case OBJ_SHMOWNER:
 407  412          case OBJ_POWNER:
 408  413                  return (proc_user(obj_val, &obj_owner));
 409  414          case OBJ_FMRI:
 410  415                  return (proc_fmri(obj_val));
 411  416          case OBJ_USER:
 412  417                  return (proc_user(obj_val, &obj_user));
      418 +        case OBJ_WSID:
      419 +                return (proc_wsid(obj_val));
 413  420          case OBJ_LP: /* lp objects have not yet been defined */
 414  421          default: /* impossible */
 415  422                  (void) sprintf(errbuf, gettext("invalid object type (%s)"),
 416  423                      obj_str);
 417  424                  error_str = errbuf;
 418  425                  return (-1);
 419  426          } /* switch */
 420  427          /*NOTREACHED*/
 421  428  }
 422  429  
↓ open down ↓ 862 lines elided ↑ open up ↑
1285 1292                  }
1286 1293          } else {
1287 1294                  fmri.sp_type = PATTERN_PARTIAL;
1288 1295                  fmri.sp_arg = strdup(optstr);
1289 1296          }
1290 1297          if (fmri.sp_arg == NULL)
1291 1298                  return (-1);
1292 1299  
1293 1300          return (0);
1294 1301  }
     1302 +
     1303 +/*
     1304 + * proc_wsid - pick up Windows SID.
     1305 + *
     1306 + * ret 0:       non-empty string
     1307 + * ret -1:      empty string or string is too long.
     1308 + */
     1309 +static int
     1310 +proc_wsid(char *optstr)
     1311 +{
     1312 +        size_t  length = strlen(optstr);
     1313 +        if ((length < 1) || (length > 256) ||
     1314 +            strncmp(optstr, "S-1-", 4) != 0) { /* SMB_SID_STRSZ */
     1315 +                (void) snprintf(errbuf, ERRBUF_SZ,
     1316 +                    gettext("bad Windows SID: %s"), optstr);
     1317 +                error_str = errbuf;
     1318 +                return (-1);
     1319 +        }
     1320 +        wsid = strdup(optstr);
     1321 +        return (0);
     1322 +}
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX