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>


   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.


  24  */
  25 
  26 /*
  27  * Support routines for building audit records.
  28  */
  29 
  30 #include <sys/param.h>
  31 #include <sys/systm.h>            /* for rval */
  32 #include <sys/time.h>
  33 #include <sys/types.h>
  34 #include <sys/vnode.h>
  35 #include <sys/mode.h>
  36 #include <sys/user.h>
  37 #include <sys/session.h>
  38 #include <sys/acl.h>
  39 #include <sys/ipc_impl.h>
  40 #include <netinet/in_systm.h>
  41 #include <netinet/in.h>
  42 #include <netinet/ip.h>
  43 #include <sys/socket.h>
  44 #include <net/route.h>
  45 #include <netinet/in_pcb.h>
  46 #include <c2/audit.h>
  47 #include <c2/audit_kernel.h>
  48 #include <c2/audit_record.h>
  49 #include <sys/model.h>            /* for model_t */
  50 #include <sys/vmparam.h>  /* for USRSTACK/USRSTACK32 */
  51 #include <sys/vfs.h>              /* for sonode */
  52 #include <sys/socketvar.h>        /* for sonode */
  53 #include <sys/zone.h>
  54 #include <sys/tsol/label.h>

  55 
  56 /*
  57  * These are the control tokens
  58  */
  59 
  60 /*
  61  * au_to_header
  62  * returns:
  63  *      pointer to au_membuf chain containing a header token.
  64  */
  65 token_t *
  66 au_to_header(int byte_count, au_event_t e_type, au_emod_t e_mod)
  67 {
  68         adr_t adr;                      /* adr memory stream header */
  69         token_t *m;                     /* au_membuf pointer */
  70 #ifdef _LP64
  71         char data_header = AUT_HEADER64;        /* header for this token */
  72         static int64_t zerotime[2];
  73 #else
  74         char data_header = AUT_HEADER32;


 588         adr_char(&adr, &data_header, 1);
 589         adr_short(&adr, &bytes, 1);
 590         m->len = adr_count(&adr);
 591 
 592         /* append path string */
 593         token = m;
 594         (void) au_append_buf(path, bytes, token);
 595 
 596         if (app->audp_cnt > 1) {
 597                 /* generate attribute path strings token */
 598                 m = au_to_strings(AUT_XATPATH, app->audp_sect[1],
 599                     app->audp_cnt - 1);
 600 
 601                 token = au_append_token(token, m);
 602         }
 603 
 604         return (token);
 605 }
 606 
 607 /*






























 608  * au_to_ipc
 609  * returns:
 610  *      pointer to au_membuf chain containing a System V IPC token.
 611  */
 612 token_t *
 613 au_to_ipc(char type, int id)
 614 {
 615         token_t *m;                     /* local au_membuf */
 616         adr_t adr;                      /* adr memory stream header */
 617         char data_header = AUT_IPC;     /* header for this token */
 618 
 619         m = au_getclr();
 620 
 621         adr_start(&adr, memtod(m, char *));
 622         adr_char(&adr, &data_header, 1);
 623         adr_char(&adr, &type, 1);               /* type of IPC object */
 624         adr_int32(&adr, (int32_t *)&id, 1);
 625 
 626         m->len = adr_count(&adr);
 627 


1187  * au_to_label
1188  * returns:
1189  *      pointer to au_membuf chain containing a label token.
1190  */
1191 token_t *
1192 au_to_label(bslabel_t *label)
1193 {
1194         token_t *m;                     /* local au_membuf */
1195         adr_t adr;                      /* adr memory stream header */
1196         char data_header = AUT_LABEL;   /* header for this token */
1197 
1198         m = au_getclr();
1199 
1200         adr_start(&adr, memtod(m, char *));
1201         adr_char(&adr, &data_header, 1);
1202         adr_char(&adr, (char *)label, sizeof (_mac_label_impl_t));
1203 
1204         m->len = adr_count(&adr);
1205 
1206         return (m);












































1207 }


   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  *
  25  * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
  26  */
  27 
  28 /*
  29  * Support routines for building audit records.
  30  */
  31 
  32 #include <sys/param.h>
  33 #include <sys/systm.h>            /* for rval */
  34 #include <sys/time.h>
  35 #include <sys/types.h>
  36 #include <sys/vnode.h>
  37 #include <sys/mode.h>
  38 #include <sys/user.h>
  39 #include <sys/session.h>
  40 #include <sys/acl.h>
  41 #include <sys/ipc_impl.h>
  42 #include <netinet/in_systm.h>
  43 #include <netinet/in.h>
  44 #include <netinet/ip.h>
  45 #include <sys/socket.h>
  46 #include <net/route.h>
  47 #include <netinet/in_pcb.h>
  48 #include <c2/audit.h>
  49 #include <c2/audit_kernel.h>
  50 #include <c2/audit_record.h>
  51 #include <sys/model.h>            /* for model_t */
  52 #include <sys/vmparam.h>  /* for USRSTACK/USRSTACK32 */
  53 #include <sys/vfs.h>              /* for sonode */
  54 #include <sys/socketvar.h>        /* for sonode */
  55 #include <sys/zone.h>
  56 #include <sys/tsol/label.h>
  57 #include <sys/cmn_err.h>
  58 
  59 /*
  60  * These are the control tokens
  61  */
  62 
  63 /*
  64  * au_to_header
  65  * returns:
  66  *      pointer to au_membuf chain containing a header token.
  67  */
  68 token_t *
  69 au_to_header(int byte_count, au_event_t e_type, au_emod_t e_mod)
  70 {
  71         adr_t adr;                      /* adr memory stream header */
  72         token_t *m;                     /* au_membuf pointer */
  73 #ifdef _LP64
  74         char data_header = AUT_HEADER64;        /* header for this token */
  75         static int64_t zerotime[2];
  76 #else
  77         char data_header = AUT_HEADER32;


 591         adr_char(&adr, &data_header, 1);
 592         adr_short(&adr, &bytes, 1);
 593         m->len = adr_count(&adr);
 594 
 595         /* append path string */
 596         token = m;
 597         (void) au_append_buf(path, bytes, token);
 598 
 599         if (app->audp_cnt > 1) {
 600                 /* generate attribute path strings token */
 601                 m = au_to_strings(AUT_XATPATH, app->audp_sect[1],
 602                     app->audp_cnt - 1);
 603 
 604                 token = au_append_token(token, m);
 605         }
 606 
 607         return (token);
 608 }
 609 
 610 /*
 611  * au_to_path_string
 612  * returns:
 613  *      pointer to au_membuf chain containing a path token.
 614  */
 615 token_t *
 616 au_to_path_string(const char *path)
 617 {
 618         token_t *token;                 /* local au_membuf */
 619         adr_t adr;                      /* adr memory stream header */
 620         char data_header = AUT_PATH;    /* header for this token */
 621         short bytes;                    /* length of string */
 622 
 623         bytes = strlen(path) + 1;
 624 
 625         /*
 626          * generate path token header
 627          */
 628         token = au_getclr();
 629         adr_start(&adr, memtod(token, char *));
 630         adr_char(&adr, &data_header, 1);
 631         adr_short(&adr, &bytes, 1);
 632         token->len = adr_count(&adr);
 633 
 634         /* append path string */
 635         (void) au_append_buf(path, bytes, token);
 636 
 637         return (token);
 638 }
 639 
 640 /*
 641  * au_to_ipc
 642  * returns:
 643  *      pointer to au_membuf chain containing a System V IPC token.
 644  */
 645 token_t *
 646 au_to_ipc(char type, int id)
 647 {
 648         token_t *m;                     /* local au_membuf */
 649         adr_t adr;                      /* adr memory stream header */
 650         char data_header = AUT_IPC;     /* header for this token */
 651 
 652         m = au_getclr();
 653 
 654         adr_start(&adr, memtod(m, char *));
 655         adr_char(&adr, &data_header, 1);
 656         adr_char(&adr, &type, 1);               /* type of IPC object */
 657         adr_int32(&adr, (int32_t *)&id, 1);
 658 
 659         m->len = adr_count(&adr);
 660 


1220  * au_to_label
1221  * returns:
1222  *      pointer to au_membuf chain containing a label token.
1223  */
1224 token_t *
1225 au_to_label(bslabel_t *label)
1226 {
1227         token_t *m;                     /* local au_membuf */
1228         adr_t adr;                      /* adr memory stream header */
1229         char data_header = AUT_LABEL;   /* header for this token */
1230 
1231         m = au_getclr();
1232 
1233         adr_start(&adr, memtod(m, char *));
1234         adr_char(&adr, &data_header, 1);
1235         adr_char(&adr, (char *)label, sizeof (_mac_label_impl_t));
1236 
1237         m->len = adr_count(&adr);
1238 
1239         return (m);
1240 }
1241 
1242 token_t *
1243 au_to_access_mask(uint32_t access)
1244 {
1245         token_t *m;                             /* local au_membuf */
1246         adr_t adr;                              /* adr memory stream header */
1247         char data_header = AUT_ACCESS_MASK;     /* header for this token */
1248 
1249         m = au_getclr();
1250 
1251         adr_start(&adr, memtod(m, char *));
1252         adr_char(&adr, &data_header, 1);
1253 
1254         adr_uint32(&adr, &access, 1);
1255 
1256         m->len = adr_count(&adr);
1257         return (m);
1258 }
1259 
1260 token_t *
1261 au_to_wsid(ksid_t *ks)
1262 {
1263         token_t *token;                 /* local au_membuf */
1264         adr_t adr;                      /* adr memory stream header */
1265         char data_header = AUT_WSID;    /* header for this token */
1266         short bytes;                    /* length of string */
1267         char sidbuf[256]; /* SMB_SID_STRSZ */
1268 
1269         sidbuf[0] = '\0';
1270         (void) snprintf(sidbuf, sizeof (sidbuf), "%s-%u",
1271             ksid_getdomain(ks), ksid_getrid(ks));
1272 
1273         token = au_getclr();
1274 
1275         bytes = (short)strlen(sidbuf) + 1;
1276         adr_start(&adr, memtod(token, char *));
1277         adr_char(&adr, &data_header, 1);
1278         adr_short(&adr, &bytes, 1);
1279 
1280         token->len = (char)adr_count(&adr);
1281         (void) au_append_buf(sidbuf, bytes, token);
1282 
1283         return (token);
1284 }