Skip to contentSkip to conversation

RACF audit plugin - configuration files

RFC PATCH In review Klaus Heinrich Kiwi 1 participant 8 messages Sep 28, 2007 7 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

RFC PATCH 1/7 RACF audit plugin - configuration files

This patch adds the configuration files for the racf plugin. There is a need for two separate configuration files: one for the audit dispatcher and another for the plugin itself.
The plugin configuration includes server and authentication information, thus it should not be readable by anyone but root. The (large) default queue size is to allow event bursts avoiding events drop. The plugin comes disabled by default.

audisp/plugins/racf/audisp-racf.conf +13 -0
diff -purN audit-1.6.2/audisp/plugins/racf/audisp-racf.conf audit-1.6.2_racf/audisp/plugins/racf/audisp-racf.conf
@@ -0,0 +1,13 @@
+# This is the audit dispatcher configuration
+# for the RACF audit plugin
+# Note that this specific plugin has a configuration
+# file of its own. The complete path for this
+# file must be entered as the argument for the
+# plugin in the 'args' field below
+
+active = no
+direction = out
+path = /sbin/audisp-racf
+type = always 
+args = /etc/audisp/racf.conf
+format = string
audisp/plugins/racf/racf.conf +13 -0
diff -purN audit-1.6.2/audisp/plugins/racf/racf.conf audit-1.6.2_racf/audisp/plugins/racf/racf.conf
@@ -0,0 +1,13 @@
+# This is the configuration file for the audit-plugin-racf
+# server, user and password are required, everything else is
+# optional
+# Also note that user is in the format
+# 'racfid=${USER},cn=ictx'
+# where ${USER} is the RACF user with R_auditx authority
+
+server = racf.server
+port = 389
+user = racfid=RACFUSER,cn=ictx
+password = password
+timeout = 15
+q_depth = 256

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw

RFC PATCH 2/7 RACF audit plugin - configuration interface

This patch brings the configuration interface for the racf-plugin. This is taken directly from Steve's audit dispatcher code, only adapted for this specific plugin.

audisp/plugins/racf/racf-config.h +48 -0
diff -purN audit-1.6.2/audisp/plugins/racf/racf-config.h audit-1.6.2_racf/audisp/plugins/racf/racf-config.h
@@ -0,0 +1,48 @@
+/***************************************************************************
+ *   Copyright (C) 2007 International Business Machines  Corp.             *
+ *   All Rights Reserved.                                                  *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ *                                                                         *
+ * Authors:                                                                *
+ *   Klaus Heinrich Kiwi <[email protected]>                               *
+ *   based on code by Steve Grubb <[email protected]>                      *
+ ***************************************************************************/
+
+#ifndef _RACF_CONFIG_H
+#define _RACF_CONFIG_H
+
+
+/***************************************************************************
+ *   RACF Plugin configuration                                             *
+ ***************************************************************************/
+typedef struct racf_conf
+{
+        char *name;
+        char *server;
+        unsigned int port;
+        char *user;
+        char *password;
+        long timeout;
+        unsigned int q_depth;
+        unsigned int counter;
+} racf_conf_t;
+
+void clear_config(racf_conf_t *);
+int load_config(racf_conf_t *, char *);
+void free_config(racf_conf_t *);
+
+#endif                          /* _RACF_CONFIG_H */
audisp/plugins/racf/racf-config.c +437 -0

437 lines not on this page · raw message

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw

RFC PATCH 3/7 RACF audit plugin - LDAP interface

This patch brings the LDAP interface for the racf plugin. Functions here aim to initialize (read as: take necessary arguments), connect and submit the LDAP extended operation to the RACF server. There's also code to get the RACF server response, filling an internally-defined struct that is then checked for errors.
The connection itself can be reestablished if the plugin thinks it timed out, after trying to submit the event directly. In case of event bursts, this prevents the plugin of trying a connection upon every event arrival, avoiding at the same time a synchronous keepalive operation.

audisp/plugins/racf/racf-ldap.h +310 -0
diff -purN audit-1.6.2/audisp/plugins/racf/racf-ldap.h audit-1.6.2_racf/audisp/plugins/racf/racf-ldap.h
@@ -0,0 +1,310 @@
+/***************************************************************************
+ *   Copyright (C) 2007 International Business Machines  Corp.             *
+ *   All Rights Reserved.                                                  *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ *                                                                         *
+ * Authors:                                                                *
+ *   Klaus Heinrich Kiwi <[email protected]>                               *
+ ***************************************************************************/
+
+#ifndef _RACF_LDAP_H
+#define _RACF_LDAP_H
+
+#include <lber.h>
+#include <ldap.h>
+
+
+/***************************************************************************
+ *   LDAP Extended Op OID for ICTX Audit                                   *
+ ***************************************************************************/
+/* ICTX EIM component AUDIT Request OID */
+#define ICTX_OIDAUDITREQUEST     "1.3.18.0.2.12.68"
+
+/* The AUDIT Response OID */
+#define ICTX_OIDAUDITRESPONSE    "1.3.18.0.2.12.69"
+
+/* This implementation version
+   Request and response must match this */
+#define ICTX_REQUESTVER          0x1
+
+/* Needed for BER-encoding */
+#define ASN1_IA5STRING_TAG       0x16
+
+/***************************************************************************
+ *   the ASN.1 struct for the remote audit request and response:           *
+ *                                                                         *
+ *   RequestValue ::= SEQUENCE  {                                          *
+ *       RequestVersion    INTEGER,                                        *
+ *       ItemList    SEQUENCE OF                                           *
+ *           Item    SEQUENCE {                                            *
+ *               ItemVersion    INTEGER,                                   *
+ *               ItemTag        INTEGER,                                   *
+ *               LinkValue    OCTET STRING SIZE(8),                        *
+ *               Violation    BOOLEAN,                                     *
+ *               Event        INTEGER,                                     *
+ *               Qualifier    INTEGER,                                     *
+ *               Class        IA5String,                                   *
+ *               Resource    IA5String,                                    *
+ *               LogString    IA5String,                                   *
+ *               DatafieldList    SEQUENCE OF                              *
+ *                   DataField    SEQUENCE {                               *
+ *                       TYPE    INTEGER,                                  *
+ *                       VALUE    IA5STRING                                *
+ *                   }                                                     *
+ *           }                                                             *
+ *   }                                                                     *
+ *                                                                         *
+ *   Response ::= SEQUENCE {                                               *
+ *       Version        INTEGER,                                           *
+ *       ResponseCode    INTEGER,                                          *
+ *       ItemList    SEQUENCE OF                                           *
+ *           Item    SEQUENCE {                                            *
+ *               ItemVersion    INTEGER,                                   *
+ *               ItemTag        INTEGER,                                   *
+ *               MajorCode    INTEGER,                                     *
+ *               MinorCode1    INTEGER,                                    *
+ *               MinorCode2    INTEGER,                                    *
+ *               MinorCode3    INTEGER                                     *
+ *           }                                                             *
+ *   }                                                                     *
+ ***************************************************************************/
+
+/***************************************************************************
+ *   RACF Remote Audit Minor return codes meaning
+
+Major Code    Meaning
+----------    ---------------------------------------------------------
+0-14        - MinorCode1 is the SAF return code
+            - MinorCode2 is the RACF return code
+            - MinorCode3 is the RACF reason code
+
+16-20        - MinorCode1 identifies the extended operation request
+              parameter number (see audit request ASN.1 definition):
+               0 - Item
+               1 - ItemVersion
+               2 - ItemTag
+               3 - LinkValue
+               4 - Violation
+               5 - Event
+               6 - Qualifier
+               7 - Class
+               8 - Resource
+               9 - LogString
+              10 - DataFieldList
+              11 - DataField *
+              12 - TYPE *
+              13 - VALUE *
+            - MinorCode2 indicates one of the Following:
+              32 - incorrect length
+              36 - incorrect value
+              40 - encoding error
+            - MinorCode3 has no defined meaning
+
+24-100        - MinorCode1 has no defined meaning
+            - MinorCode2 has no defined meaning
+            - MinorCode3 has no defined meaning
+
+* There can be multiple DataField, TYPEs and VALUEs in a request. If any of them is bad
+  you get the same 11, 12 or 13 MinorCode1. There is no further breakdown of which one
+  is bad.
+
+ ***************************************************************************/
+
+/***************************************************************************
+ *   Audit Request 'event' field meaning                                   *
+ ***************************************************************************/
+#define RACF_EVENT_AUTHENTICATION            0x1
+#define RACF_EVENT_AUTHORIZATION             0x2
+#define RACF_EVENT_AUTHORIZATION_MAPPING     0x3
+#define RACF_EVENT_KEY_MGMT                  0x4
+#define RACF_EVENT_POLICY_MGMT               0x5
+#define RACF_EVENT_ADMIN_CONFIG              0x6
+#define RACF_EVENT_ADMIN_ACTION              0x7
+
+/***************************************************************************
+ *   Audit Request 'qualifier' field meaning                               *
+ ***************************************************************************/
+#define RACF_QUALIF_SUCCESS                  0x0
+#define RACF_QUALIF_INFO                     0x1
+#define RACF_QUALIF_WARN                     0x2
+#define RACF_QUALIF_FAIL                     0x3
+
+/***************************************************************************
+ *   Relocate types for Audit Request                                      *
+ ***************************************************************************/
+/* SAF identifier for bind user */
+#define RACF_RELOC_SAF_BIND_USER             100
+
+/* Reguestor's bind user identifier */
+#define RACF_RELOC_REQ_BIND_USER             101
+
+/* Originating security domain */
+#define RACF_RELOC_ORIG_SECURITY             102
+
+/* Originating registry / realm */
+#define RACF_RELOC_ORIG_REALM                103
+
+/* Originating user name */
+#define RACF_RELOC_ORIG_USER                 104
+
+/* Mapped security domain */
+#define RACF_RELOC_MAPPED_SECURITY           105
+
+/* Mapped registry / realm */
+#define RACF_RELOC_MAPPED_REALM              106
+
+/* Mapped user name */
+#define RACF_RELOC_MAPPED_USER               107
+
+/* Operation performed */
+#define RACF_RELOC_OPERATION                 108
+
+/* Mechanism / object name */
+#define RACF_RELOC_OBJECT                    109
+
+/* Method  / function used */
+#define RACF_RELOC_FUNCTION                  110
+
+/* Key / certificate name */
+#define RACF_RELOC_CERTIFICATE               111
+
+/* Caller subject initiating security event  */
+#define RACF_RELOC_INITIATING_EVENT          112
+
+/* Date and time security event occurred  */
+#define RACF_RELOC_TIMESTAMP                 113
+
+/* Application specific data. (i.e. Other) */
+#define RACF_RELOC_OTHER                     114
+
+/***************************************************************************
+ *   RACF Remote Audit Major return codes                                  *
+ ***************************************************************************/
+#define RACF_MAJOR_SUCCESS                   0
+
+/* Event was logged, with warnings */
+#define RACF_MAJOR_WARNINGMODE               2
+
+/* No logging required
+   No audit controls are set to require it */
+#define RACF_MAJOR_NOTREQ                    3
+
+/* Class not active/ractlisted, 
+   covering profile not found or 
+   RACF is not installed */
+#define RACF_MAJOR_UNDETERMINED              4
+
+/* The user does not have authority the R_auditx service.
+    The userid associated with the LDAP server must have
+    at least READ access to the FACILITY class profile IRR.RAUDITX. */
+#define RACF_MAJOR_UNAUTHORIZED              8
+
+
+/* The R_auditx service returned an unexpected error.
+   Compare the returned minor codes with the SAF  RACF codes
+   documented in Security Server Callable Services */
+#define RACF_MAJOR_RACROUTE                  12
+
+/* A value specified in the extended operation request is 
+   incorrect or unsupported. Check the returned minor codes
+   to narrow the reason */
+#define RACF_MAJOR_VAL_ERR                   16
+
+/* A DER decoding error was encountered in an item.
+   Processing Terminated. Partial results may be returned */
+#define RACF_MAJOR_ENC_ERR                   20
+
+/* The requestor does not have sufficient authority for the
+   requested function. The userid associated with the LDAP bind
+   user must have at least READ access to the FACILITY class
+   profile IRR.LDAP.REMOTE.AUDIT. */
+#define RACF_MAJOR_UNSUF_AUTH                24
+
+/* No items are found within the ItemList sequence of the extended
+   operation request, so no response items are returned */
+#define RACF_MAJOR_EMPTY                     28
+
+/* Invalid RequestVersion */
+#define RACF_MAJOR_INVALID_VER               61
+
+/* An internal error was encountered within the ICTX component */
+#define RACF_MAJOR_INTERNAL_ERR              100
+
+/***************************************************************************
+ *   Some standard sizes for remote audit request items                    *
+ ***************************************************************************/
+#define RACF_LINK_VALUE_SIZE                 8
+#define RACF_CLASS_SIZE                      8
+#define RACF_RESOURCE_SIZE                   240
+#define RACF_LOGSTRING_SIZE                  200
+
+
+/***************************************************************************
+ *   Some standard Error defines                                           *
+ ***************************************************************************/
+#define ICTX_SUCCESS                         0x00
+
+/* maybe a temporary failure? */
+#define ICTX_E_TRYAGAIN                      0x01
+
+/* permanent failure - abort event submission */
+#define ICTX_E_ABORT                         0x02
+
+/* Fatal failure - abort program */
+#define ICTX_E_FATAL                         0x03
+
+/* generic error */
+#define ICTX_E_ERROR                         0x10
+
+/***************************************************************************
+ *   structure representing an RACF session                                *
+ ***************************************************************************/
+typedef struct opaque
+{
+    char *server;
+    unsigned int port;
+    char *user;
+    char *password;
+    unsigned int timeout;
+    LDAP *ld;
+    int connected;
+} RACF;
+
+/***************************************************************************
+ *   LDAP XOP operations                                                   *
+ ***************************************************************************/
+/* 
+ * Initializes RACF connection, binds to RACF Server
+ * Args are:
+ * server, bind user, bind password, server port, timeout
+ * Caller must call racf_destroy() to free memory allocation
+ */
+int racf_init(RACF *, char *, int, char *, char *, int);
+
+/* 
+ * Uninitializes RACF connection
+ */
+void racf_destroy(RACF *);
+
+/* 
+ * sync submit request - possibly reconnect to server
+ * if the connection if found to be dead
+ */
+int submit_request_s(RACF *, BerElement *);
+
+
+#endif                          /* _RACF_LDAP_H */
audisp/plugins/racf/racf-ldap.c +606 -0

606 lines not on this page · raw message

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw

RFC PATCH 4/7 RACF audit plugin - logging interface

This patch implements a simple logging interface for the racf plugin. There's also some debugging code that's completely disabled if 'DEBUG' symbol isn't defined.
Messages are logged to the syslog with info, warn and err priorities.

audisp/plugins/racf/racf-log.h +58 -0
diff -purN audit-1.6.2/audisp/plugins/racf/racf-log.h audit-1.6.2_racf/audisp/plugins/racf/racf-log.h
@@ -0,0 +1,58 @@
+/***************************************************************************
+ *   Copyright (C) 2007 International Business Machines  Corp.             *
+ *   All Rights Reserved.                                                  *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ *                                                                         *
+ * Authors:                                                                *
+ *   Klaus Heinrich Kiwi <[email protected]>                               *
+ ***************************************************************************/
+
+#ifndef _RACF_LOG_H
+#define _RACF_LOG_H
+
+#include "racf-ldap.h"
+
+#include <syslog.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <lber.h>
+
+extern pid_t mypid;
+
+void log_err(const char *, ...);
+void log_warn(const char *, ...);
+void log_info(const char *, ...);
+void _log_debug(const char *, ...);
+void _debug_bv(struct berval *);
+void _debug_ber(BerElement *);
+
+#ifdef DEBUG
+
+#define log_debug(fmt, ...)        _log_debug(fmt, ## __VA_ARGS__)
+#define debug_bv(bv)               _debug_bv(bv)
+#define debug_ber(ber)             _debug_ber(ber)
+
+#else
+
+#define log_debug(fmt, ...)
+#define debug_bv(bv)
+#define debug_ber(ber)
+
+#endif                 /* DEBUG */
+
+
+#endif                          /* _RACF_LOG_H */
audisp/plugins/racf/racf-log.c +109 -0

109 lines not on this page · raw message

A message that is not in the archive (sent off-list or not yet received): [email protected]

#9 lore raw

RFC PATCH 5/7 RACF audit plugin - queue interface

This patch implements a queue for already-encoded BER elements for the racf plugin.
This is entirely based on audit dispatcher code by Steve Grubb.

audisp/plugins/racf/racf-queue.h +38 -0
diff -purN audit-1.6.2/audisp/plugins/racf/racf-queue.h audit-1.6.2_racf/audisp/plugins/racf/racf-queue.h
@@ -0,0 +1,38 @@
+/***************************************************************************
+ *   Copyright (C) 2007 International Business Machines  Corp.             *
+ *   All Rights Reserved.                                                  *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ *                                                                         *
+ * Authors:                                                                *
+ *   Klaus Heinrich Kiwi <[email protected]>                               *
+ *   based on code by Steve Grubb <[email protected]>                      *
+ ***************************************************************************/
+
+#ifndef _RACF_QUEUE_H
+#define _RACF_QUEUE_H
+
+#include <lber.h>
+
+int init_queue(unsigned int size);
+void enqueue(BerElement *);
+BerElement *dequeue(void);
+void nudge_queue(void);
+void increase_queue_depth(unsigned int size);
+void destroy_queue(void);
+
+#endif       /* _RACF_QUEUE_H */
+
audisp/plugins/racf/racf-queue.c +144 -0

144 lines not on this page · raw message

A message that is not in the archive (sent off-list or not yet received): [email protected]

#11 lore raw

RFC PATCH 6/7 RACF audit plugin - plugin main code

This patch implements the main body for the racf plugin. It uses the auparse_feed() interface to add a callback interface that's called whenever a complete event is read from stdin.
The push_event() callback does the BER encoding and enqueues the encoded event.
The 'submission_thread' then dequeues it and synchronously submits it to the RACF server (using the ldap interface).

SIGHUP is supposed to trigger a configuration file re-read and flush queues and network connections, but seems like there's still a bit of a problem when the submission thread is blocked on dequeueing events and a SIGHUP is caught.

audisp/plugins/racf/racf-plugin.c +483 -0
diff -purN audit-1.6.2/audisp/plugins/racf/racf-plugin.c audit-1.6.2_racf/audisp/plugins/racf/racf-plugin.c
@@ -0,0 +1,483 @@
+/***************************************************************************
+*   Copyright (C) 2007 International Business Machines  Corp.             *
+*   All Rights Reserved.                                                  *
+*                                                                         *
+*   This program is free software; you can redistribute it and/or modify  *
+*   it under the terms of the GNU General Public License as published by  *
+*   the Free Software Foundation; either version 2 of the License, or     *
+*   (at your option) any later version.                                   *
+*                                                                         *
+*   This program is distributed in the hope that it will be useful,       *
+*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+*   GNU General Public License for more details.                          *
+*                                                                         *
+*   You should have received a copy of the GNU General Public License     *
+*   along with this program; if not, write to the                         *
+*   Free Software Foundation, Inc.,                                       *
+*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+*                                                                         *
+* Authors:                                                                *
+*   Klaus Heinrich Kiwi <[email protected]>                               *
+***************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <signal.h>
+#include <limits.h>
+#include <string.h>
+#include <time.h>
+#include <errno.h>
+#include <string.h>
+#include <pthread.h>
+#include <lber.h>
+#include <netinet/in.h>
+#include "auparse.h"
+#include "racf-log.h"
+#include "racf-ldap.h"
+#include "racf-config.h"
+#include "racf-queue.h"
+
+/*
+ * Global vars 
+ */
+volatile int stop = 0;
+volatile int hup = 0;
+volatile RACF racf_inst;
+static racf_conf_t conf;
+static const char *def_config_file = "/etc/audisp/racf.conf";
+static pthread_t submission_thread;
+pid_t mypid = 0;
+
+/*
+ * SIGTERM handler 
+ */
+static void term_handler(int sig)
+{
+        log_info("Got SIGTERM - Exiting");
+        stop = 1;
+        nudge_queue();
+}
+
+/*
+ * SIGHUP handler - re-read config, reconnect to RACF
+ */
+static void hup_handler(int sig)
+{
+        log_info("Got SIGHUP - flushing configuration");
+        hup = 1;
+        nudge_queue();
+}
+
+/*
+ * SIGALRM handler - help force exit when terminating daemon
+ */
+static void alarm_handler(int sig)
+{
+        log_err("Aborting submission thread");
+        pthread_cancel(submission_thread);
+        abort();
+}
+
+/*
+ * The submission thread
+ * It's job is to dequeue the events from the queue
+ * and sync submit them to RACF
+ */
+static void *submission_thread_main(void *arg)
+{
+        int rc;
+        
+        rc = racf_init(&racf_inst, conf.server, 
+                          conf.port, conf.user,
+                          conf.password,
+                          conf.timeout);
+                          
+        if (rc != ICTX_SUCCESS) {
+                log_err("Error - RACF instance initialization failed");
+                stop = 1;
+                return 0;
+        }
+        
+        while (stop == 0) {
+                /* block until we have an event */
+                BerElement *ber = dequeue();
+
+                if (ber == NULL) {
+                        if (hup) {
+                                break;
+                        }
+                        continue;
+                }
+                debug_ber(ber);
+                rc = submit_request_s(&racf_inst, ber);
+                if (rc == ICTX_E_FATAL) {
+                        log_err("Error - Fatal error in event submission");
+                        stop = 1;
+                } else if (rc != ICTX_SUCCESS) {
+                        log_err("Event submission failure - event dropped");
+                }
+                else {
+                        log_debug("Event submission success");
+                }
+                ber_free(ber, 1);        /* also free BER buffer */
+        }
+        log_debug("Stopping event submission thread");
+        racf_destroy(&racf_inst);
+        
+        return 0;
+}
+            
+
+/* 
+ * auparse library callback that's called when an event is ready
+ */
+void
+push_event(auparse_state_t * au, auparse_cb_event_t cb_event_type,
+           void *user_data)
+{
+        int rc;
+        BerElement *ber;
+        int qualifier;
+        char timestamp[26];
+        char linkValue[RACF_LINK_VALUE_SIZE];
+        char logString[RACF_LOGSTRING_SIZE];
+        unsigned long linkValue_tmp;
+
+        if (cb_event_type != AUPARSE_CB_EVENT_READY)
+                return;
+                
+        const au_event_t *e = auparse_get_timestamp(au);
+        if (e == NULL)
+                return;
+        /*
+         * we have an event. Each record will result in a different 'Item'
+         * (refer ASN.1 definition in racf-ldap.h) 
+         */
+        
+        /*
+         * Create a new BER element to encode the request
+         */
+        ber = ber_alloc_t(LBER_USE_DER);
+        if (ber == NULL) {
+            log_err("Error allocating memory for BER element");
+            goto fatal;
+        }
+
+        /*
+         * Collect some information to fill in every item
+         */
+        const char *node = auparse_get_node(au);
+        const char *success = auparse_find_field(au, "success");
+        /* roll back event to get 'res' */
+        auparse_first_record(au);
+        const char *res = auparse_find_field(au, "res");
+        
+        /* check if this event is a success or failure one */
+        if (success) {
+                if (strncmp(success, "0", 1) == 0 ||
+                    strncmp(success, "no", 2) == 0)
+                        qualifier = RACF_QUALIF_FAIL;
+                else
+                        qualifier = RACF_QUALIF_SUCCESS;
+        } else if (res) {
+                if (strncmp(res, "0", 1) == 0
+                    || strncmp(res, "failed", 6) == 0)
+                        qualifier = RACF_QUALIF_FAIL;
+                else
+                        qualifier = RACF_QUALIF_SUCCESS;
+        } else
+                qualifier = RACF_QUALIF_INFO;
+                
+        /* get timestamp text */
+        ctime_r(&e->sec, timestamp);
+        timestamp[24] = '\0';    /* strip \n' */
+        
+        /* prepare linkValue which will be used for every item */
+        linkValue_tmp = htonl(e->serial);        /* padronize to use network
+                                                  * byte order 
+                                                  */
+        memset(&linkValue, 0, RACF_LINK_VALUE_SIZE);
+        memcpy(&linkValue, &linkValue_tmp, sizeof(unsigned long));        
+
+        /* 
+         * Prepare the logString with some meaningful text
+         */
+        sprintf(logString, "Linux (%s):", node);
+
+        /* 
+         * Start writing to BER element.
+         * There's only one field (version) out of the item sequence.
+         * Also open item sequence
+         */
+        rc = ber_printf(ber, "{i{", ICTX_REQUESTVER);
+        if (rc < 0)
+                goto skip_event;
+
+        /* 
+         * Roll back to first record and iterate through all records
+         */
+        auparse_first_record(au);
+        do {
+                const char *type = auparse_find_field(au, "type");
+                if (type == NULL)
+                        goto skip_event;
+                
+                log_debug("got record: %s", auparse_get_record_text(au));
+
+                /* 
+                 * First field is item Version, same as global version
+                 */
+                rc = ber_printf(ber, "{i", ICTX_REQUESTVER);
+
+                /*
+                 * Second field is the itemTag
+                 * use our internal event counter, increasing it
+                 */
+                rc |= ber_printf(ber, "i", conf.counter++);
+
+                /*
+                 * Third field is the linkValue
+                 * using ber_put_ostring since it is not null-terminated
+                 */
+                rc |= ber_put_ostring(ber, linkValue,
+                                      RACF_LINK_VALUE_SIZE,
+                                      LBER_OCTETSTRING);
+                /*
+                 * Fourth field is the violation
+                 * Don't have anything better yet to put here
+                 */
+                rc |= ber_printf(ber, "b", 0);
+                
+                /* 
+                 * Fifth field is the event.
+                 * FIXME: this might be the place to switch on the
+                 * audit record type and map to a more meaningful
+                 * RACF event here
+                 */
+                rc |= ber_printf(ber, "i", RACF_EVENT_AUTHORIZATION);
+                
+                /*
+                 * Sixth field is the qualifier. We map 'success' or
+                 * 'res' to this field
+                 */
+                rc |= ber_printf(ber, "i", qualifier);
+                
+                /* 
+                 * Seventh field is the Class
+                 * always use '@LINUX' for this version
+                 * max size RACF_CLASS_SIZE
+                 */
+                rc |= ber_printf(ber, "t", ASN1_IA5STRING_TAG);
+                rc |= ber_printf(ber, "s", "@LINUX");
+                
+                /* 
+                 * Eighth field is the resource
+                 * use the record type (name) as the resource
+                 * max size RACF_RESOURCE_SIZE
+                 */
+                rc |= ber_printf(ber, "t", ASN1_IA5STRING_TAG);
+                rc |= ber_printf(ber, "s", type);
+                
+                /* 
+                 * Nineth field is the LogString
+                 * we try to put something meaningful here
+                 * we also start the relocations sequence
+                 */
+                strcat(logString, type);    /* concatenate the event type */
+                rc |= ber_printf(ber, "t", ASN1_IA5STRING_TAG);
+                rc |= ber_printf(ber, "s{", logString);
+
+                /*
+                 * Now we start adding the relocations.
+                 * Let's add the timestamp as the first one
+                 * so it's out of the field loop
+                 */
+                rc |= ber_printf(ber, "{i", RACF_RELOC_TIMESTAMP);
+                rc |= ber_printf(ber, "t", ASN1_IA5STRING_TAG);
+                rc |= ber_printf(ber, "s}", timestamp);
+
+                /* 
+                 * Check that encoding is going OK until now
+                 */
+                if (rc < 0)
+                        goto skip_event;
+
+                /* 
+                 * Now go to first field,
+                 * and iterate through all fields
+                 */
+                auparse_first_field(au);
+                do {
+                        /* 
+                         * we set a maximum of 1024 chars for
+                         * relocation data (field=value pairs)
+                         * Hopefuly this wont overflow too often
+                         */
+                        char data[1024];
+                        const char *name = auparse_get_field_name(au);
+                        const char *value = auparse_get_field_str(au);
+                        if (name == NULL || value == NULL)
+                                goto skip_event;
+                        
+                        /*
+                         * First reloc field is the Relocation type
+                         * We use 'OTHER' here since we don't have
+                         * anything better
+                         */
+                        rc |= ber_printf(ber, "{i", RACF_RELOC_OTHER);
+                        
+                        /*
+                         * Second field is the relocation data
+                         * We use a 'name=value' pair here
+                         * Use up to 1023 chars (one char left for '\0')
+                         */
+                        snprintf(data, 1023, "%s=%s", name, value);
+                        rc |= ber_printf(ber, "t", ASN1_IA5STRING_TAG);
+                        rc |= ber_printf(ber, "s}", data);
+                        
+                        /*
+                         * Check encoding status
+                         */
+                        if (rc < 0)
+                                goto skip_event;
+                } while (auparse_next_field(au) > 0);
+                
+                /* 
+                 * After adding all relocations we are done with
+                 * this item - finalize relocs and item 
+                 */
+                rc |= ber_printf(ber, "}}");
+                
+                /*
+                 * Check if we are doing well with encoding
+                 */
+                if (rc < 0)
+                        goto skip_event;            
+
+        } while (auparse_next_record(au) > 0);
+        
+        /*
+         * We have all items in - finalize item sequence & request
+         */
+        rc |= ber_printf(ber, "}}");
+
+        /*
+         * Check if everything went alright with encoding
+         */
+        if (rc < 0)
+                goto skip_event;
+
+        /* 
+         * finally, enqueue request and let the other
+         * thread process it
+         */
+        log_debug("Encoding done, enqueuing event");
+        enqueue(ber);
+
+        return;
+        
+skip_event:
+        log_warn("Warning - error encoding request, skipping event");
+        ber_free(ber, 1);        /* free it since we're not enqueuing it */
+        return;
+
+fatal:
+        log_err("Fatal error while encoding request - aborting");
+        stop = 1;
+}
+
+int main(int argc, char *argv[])
+{
+        int rc;
+        char *cpath;
+        char buf[1024];
+        struct sigaction sa;
+        auparse_state_t *au;
+
+        mypid = getpid();
+
+        log_info("starting");
+
+        /*
+         * sighandlers 
+         */
+        sa.sa_flags = 0;
+        sigemptyset(&sa.sa_mask);
+        sa.sa_handler = term_handler;
+        sigaction(SIGTERM, &sa, NULL);
+        sa.sa_handler = hup_handler;
+        sigaction(SIGHUP, &sa, NULL);
+        sa.sa_handler = alarm_handler;
+        sigaction(SIGALRM, &sa, NULL);
+
+        /* 
+         * the main program accepts a single (optional) argument:
+         * it's configuration file (this is NOT the plugin configuration
+         * usually located at /etc/audisp/plugin.d)
+         * We use the default (def_config_file) if no arguments are given
+         */
+        if (argc == 1) {
+                cpath = def_config_file;
+                log_warn("No configuration file specified - using default (%s)", cpath);
+        } else if (argc == 2) {
+                cpath = argv[1];
+                log_info("Configuration file: %s", cpath);
+        } else {
+                log_err("Error - invalid number of parameters");
+                return 1;
+        }
+
+        /* initialize record counter */
+        conf.counter = 1;
+
+        do {
+                hup = 0;        /* don't flush unless hup==1 */
+                
+                /* initialization is done in 5 steps: */
+                rc = load_config(&conf, cpath);                    /* 1 */
+                if (rc != 0) {
+                        log_err("Error - Can't load configuration");
+                        return -1;
+                }
+
+                /* initialize auparse */
+                au = auparse_init(AUSOURCE_FEED, 0);               /* 2 */
+                
+                /* initialize the submission queue */              /* 3 */
+                if (init_queue(conf.q_depth) != 0) {
+                        log_err("Error - Can't initialize event queue");
+                        return -1;
+                }
+                
+                /* Initialize submission thread */
+                 pthread_create(&submission_thread, NULL, 
+                                submission_thread_main, NULL);     /* 4 */
+
+                /* add our event consumer callback */
+                auparse_add_callback(au, push_event, NULL, NULL);  /* 5 */
+
+                /* loop reading stdin */
+                while (fgets(buf, 1024, stdin) && hup == 0 && stop == 0) {
+                        /* let our callback know of the new data */
+                        auparse_feed(au, buf, strlen(buf));
+                }
+                /* flush everything, in order */
+                auparse_flush_feed(au);                            /* 5 */
+                nudge_queue();
+                alarm(5);               /* 5 seconds to clear the queue */
+                pthread_join(submission_thread, NULL);             /* 4 */
+                destroy_queue();                                   /* 3 */
+                auparse_destroy(au);                               /* 2 */
+                free_config(&conf);                                /* 1 */
+        }
+        while (hup && stop == 0);
+
+        
+        return 0;
+}

A message that is not in the archive (sent off-list or not yet received): [email protected]

#13 lore raw

RFC PATCH 7/7 RACF audit plugin - build and packaging integration

This patch adds the racf plugin to the audit package build system, with some additions to the spec file as well (the audit plugins package is still disabled).

audisp/plugins/Makefile.am +1 -1
diff -purN audit-1.6.2/audisp/plugins/Makefile.am audit-1.6.2_racf/audisp/plugins/Makefile.am
@@ -22,5 +22,5 @@
 
 CONFIG_CLEAN_FILES = Makefile.in *.loT *.rej *.orig
 
-SUBDIRS = builtins ids remote
+SUBDIRS = builtins ids remote racf
 
audisp/plugins/racf/Makefile.am +46 -0

46 lines not on this page · raw message

audit.spec +6 -0
diff -purN audit-1.6.2/audit.spec audit-1.6.2_racf/audit.spec
@@ -124,7 +124,10 @@ touch -r ./audit.spec $RPM_BUILD_ROOT/et
 # Remove the plugin stuff for now
 rm -f $RPM_BUILD_ROOT/etc/audisp/plugins.d/au-ids.conf
 rm -f $RPM_BUILD_ROOT/etc/audisp/plugins.d/remote.conf
+rm -f $RPM_BUILD_ROOT/etc/audisp/plugins.d/audisp-racf.conf
+rm -f $RPM_BUILD_ROOT/etc/audisp/racf.conf
 rm -f $RPM_BUILD_ROOT/sbin/audisp-ids
+rm -f $RPM_BUILD_ROOT/sbin/audisp-racf
 
 %clean
 rm -rf $RPM_BUILD_ROOT
@@ -214,7 +217,10 @@ fi
 ##%defattr(-,root,root,-)
 ##%attr(640,root,root) /etc/audisp/plugins.d/au-ids.conf
 ##%attr(640,root,root) /etc/audisp/plugins.d/remote.conf
+##%attr(640,root,root) /etc/audisp/plugins.d/audit-plugin-racf.conf
+##%attr(640,root,root) /etc/audisp/racf.conf
 ##%attr(750,root,root) /sbin/audisp-ids
+##%attr(750,root,root) /sbin/audit-plugin-racf
 
 %files -n system-config-audit -f system-config-audit.lang
 %defattr(-,root,root,-)
configure.ac +1 -1
diff -purN audit-1.6.2/configure.ac audit-1.6.2_racf/configure.ac
@@ -109,7 +109,7 @@ if test x$use_apparmor != xno ; then
       AC_DEFINE(WITH_APPARMOR,1,[Define if you want to enable AppArmor events.])fi
 
 AC_CONFIG_SUBDIRS([system-config-audit])
-AC_OUTPUT(Makefile lib/Makefile auparse/Makefile auparse/test/Makefile src/Makefile src/mt/Makefile swig/Makefile docs/Makefile init.d/Makefile audisp/Makefile audisp/plugins/Makefile audisp/plugins/builtins/Makefile audisp/plugins/ids/Makefile audisp/plugins/remote/Makefile bindings/Makefile bindings/python/Makefile)
+AC_OUTPUT(Makefile lib/Makefile auparse/Makefile auparse/test/Makefile src/Makefile src/mt/Makefile swig/Makefile docs/Makefile init.d/Makefile audisp/Makefile audisp/plugins/Makefile audisp/plugins/builtins/Makefile audisp/plugins/ids/Makefile audisp/plugins/remote/Makefile audisp/plugins/racf/Makefile bindings/Makefile bindings/python/Makefile)
 
 echo .
 echo "
#14 lore raw

Re: [PATCH 07/07][RFC] RACF audit plugin - build and packaging integration

Quoted 5 lines · Klaus Heinrich Kiwi

This patch adds the racf plugin to the audit package build system, with some additions to the spec file as well (the audit plugins package is still disabled).

Noted that there are some minor things out of place for this patch. Below is the same patch, fixed.

audisp/plugins/Makefile.am 2007-09-28 09:37:07.000000000 -0300 renamed from audisp/plugins/Makefile.am 2007-09-12 14:25:13.000000000 -0300 +1 -1
diff -purN audit-1.6.2/audisp/plugins/Makefile.am audit-1.6.2_racf2/audisp/plugins/Makefile.am
@@ -22,5 +22,5 @@
 
 CONFIG_CLEAN_FILES = Makefile.in *.loT *.rej *.orig
 
-SUBDIRS = builtins ids remote
+SUBDIRS = builtins ids remote racf
 
audisp/plugins/racf/Makefile.am 2007-09-28 16:53:46.000000000 -0300 renamed from audisp/plugins/racf/Makefile.am 1969-12-31 21:00:00.000000000 -0300 +46 -0

46 lines not on this page · raw message

audit.spec 2007-09-28 17:25:42.000000000 -0300 renamed from audit.spec 2007-09-25 08:46:49.000000000 -0300 +8 -1
diff -purN audit-1.6.2/audit.spec audit-1.6.2_racf2/audit.spec
@@ -9,7 +9,7 @@ Group: System Environment/Daemons
 URL: http://people.redhat.com/sgrubb/audit/
 Source0: %{name}-%{version}.tar.gz
 BuildRoot: %{_tmppath}/%{name}-%{version}-root
-BuildRequires: gettext-devel intltool libtool swig python-devel
+BuildRequires: gettext-devel intltool libtool swig python-devel openldap-devel
 BuildRequires: kernel-headers >= 2.6.18
 BuildRequires: automake >= 1.9
 BuildRequires: autoconf >= 2.59
@@ -59,6 +59,7 @@ and libauparse can be used by python.
 ##Group: System Environment/Daemons
 ##Requires: %{name} = %{version}-%{release}
 ##Requires: %{name}-libs = %{version}-%{release}
+##Requires: openldap
 
 ##%description -n audispd-plugins
 ##The audispd-plugins package provides plugins for the real-time
@@ -124,7 +125,10 @@ touch -r ./audit.spec $RPM_BUILD_ROOT/et
 # Remove the plugin stuff for now
 rm -f $RPM_BUILD_ROOT/etc/audisp/plugins.d/au-ids.conf
 rm -f $RPM_BUILD_ROOT/etc/audisp/plugins.d/remote.conf
+rm -f $RPM_BUILD_ROOT/etc/audisp/plugins.d/audisp-racf.conf
+rm -f $RPM_BUILD_ROOT/etc/audisp/racf.conf
 rm -f $RPM_BUILD_ROOT/sbin/audisp-ids
+rm -f $RPM_BUILD_ROOT/sbin/audisp-racf
 
 %clean
 rm -rf $RPM_BUILD_ROOT
@@ -214,7 +218,10 @@ fi
 ##%defattr(-,root,root,-)
 ##%attr(640,root,root) /etc/audisp/plugins.d/au-ids.conf
 ##%attr(640,root,root) /etc/audisp/plugins.d/remote.conf
+##%config(noreplace) %attr(640,root,root) /etc/audisp/plugins.d/audisp-racf.conf
+##%config(noreplace) %attr(640,root,root) /etc/audisp/racf.conf
 ##%attr(750,root,root) /sbin/audisp-ids
+##%attr(750,root,root) /sbin/audisp-racf
 
 %files -n system-config-audit -f system-config-audit.lang
 %defattr(-,root,root,-)
configure.ac 2007-09-28 09:37:07.000000000 -0300 renamed from configure.ac 2007-09-12 14:26:41.000000000 -0300 +1 -1
diff -purN audit-1.6.2/configure.ac audit-1.6.2_racf2/configure.ac
@@ -109,7 +109,7 @@ if test x$use_apparmor != xno ; then
       AC_DEFINE(WITH_APPARMOR,1,[Define if you want to enable AppArmor events.])fi
 
 AC_CONFIG_SUBDIRS([system-config-audit])
-AC_OUTPUT(Makefile lib/Makefile auparse/Makefile auparse/test/Makefile src/Makefile src/mt/Makefile swig/Makefile docs/Makefile init.d/Makefile audisp/Makefile audisp/plugins/Makefile audisp/plugins/builtins/Makefile audisp/plugins/ids/Makefile audisp/plugins/remote/Makefile bindings/Makefile bindings/python/Makefile)
+AC_OUTPUT(Makefile lib/Makefile auparse/Makefile auparse/test/Makefile src/Makefile src/mt/Makefile swig/Makefile docs/Makefile init.d/Makefile audisp/Makefile audisp/plugins/Makefile audisp/plugins/builtins/Makefile audisp/plugins/ids/Makefile audisp/plugins/remote/Makefile audisp/plugins/racf/Makefile bindings/Makefile bindings/python/Makefile)
 
 echo .
 echo "
Signature · 1 line
.:klaus h kiwi <[email protected]>:.