Diff for /servers/slapd/overlays/auditlog.c between versions 1.1.2.9 and 1.2

version 1.1.2.9, 2008/02/11 23:24:24 version 1.2, 2005/11/25 11:43:51
Line 1 Line 1
 /* auditlog.c - log modifications for audit/history purposes */  /* auditlog.c - log modifications for audit/history purposes */
 /* $OpenLDAP: pkg/ldap/servers/slapd/overlays/auditlog.c,v 1.1.2.8 2007/02/08 12:31:24 hyc Exp $ */  /* $OpenLDAP: pkg/ldap/servers/slapd/overlays/auditlog.c,v 1.1 2005/06/07 01:03:18 hyc Exp $ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.  /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *   *
  * Copyright 2005-2008 The OpenLDAP Foundation.   * Copyright 2005 The OpenLDAP Foundation.
  * Portions copyright 2004-2005 Symas Corporation.   * Portions copyright 2004-2005 Symas Corporation.
  * All rights reserved.   * All rights reserved.
  *   *
Line 29 Line 29
 #include <ac/ctype.h>  #include <ac/ctype.h>
   
 #include "slap.h"  #include "slap.h"
 #include "config.h"  
 #include "ldif.h"  #include "ldif.h"
   
 typedef struct auditlog_data {  typedef struct auditlog_data {
Line 37  typedef struct auditlog_data { Line 36  typedef struct auditlog_data {
         char *ad_logfile;          char *ad_logfile;
 } auditlog_data;  } auditlog_data;
   
 static ConfigTable auditlogcfg[] = {  int fprint_ldif(FILE *f, char *name, char *val, ber_len_t len) {
         { "auditlog", "filename", 2, 2, 0,  
           ARG_STRING|ARG_OFFSET,  
           (void *)offsetof(auditlog_data, ad_logfile),  
           "( OLcfgOvAt:15.1 NAME 'olcAuditlogFile' "  
           "DESC 'Filename for auditlogging' "  
           "SYNTAX OMsDirectoryString )", NULL, NULL },  
         { NULL, NULL, 0, 0, 0, ARG_IGNORED }  
 };  
   
 static ConfigOCs auditlogocs[] = {  
         { "( OLcfgOvOc:15.1 "  
           "NAME 'olcAuditlogConfig' "  
           "DESC 'Auditlog configuration' "  
           "SUP olcOverlayConfig "  
           "MAY ( olcAuditlogFile ) )",  
           Cft_Overlay, auditlogcfg },  
         { NULL, 0, NULL }  
 };  
   
 static int fprint_ldif(FILE *f, char *name, char *val, ber_len_t len) {  
         char *s;          char *s;
         if((s = ldif_put(LDIF_PUT_VALUE, name, val, len)) == NULL)          if((s = ldif_put(LDIF_PUT_VALUE, name, val, len)) == NULL)
                 return(-1);                  return(-1);
Line 66  static int fprint_ldif(FILE *f, char *na Line 45  static int fprint_ldif(FILE *f, char *na
         return(0);          return(0);
 }  }
   
 static int auditlog_response(Operation *op, SlapReply *rs) {  int auditlog_response(Operation *op, SlapReply *rs) {
         slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;          slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
         auditlog_data *ad = on->on_bi.bi_private;          auditlog_data *ad = on->on_bi.bi_private;
         FILE *f;          FILE *f;
         Attribute *a;          Attribute *a;
         Modifications *m;          Modifications *m;
         struct berval *b, *who = NULL;          struct berval *b;
         char *what, *suffix;          char *what, *subop, *suffix, *who = NULL;
         long stamp = slap_get_time();          long stamp = slap_get_time();
         int i;          int i;
   
         if ( rs->sr_err != LDAP_SUCCESS ) return SLAP_CB_CONTINUE;          if ( rs->sr_err != LDAP_SUCCESS ) return SLAP_CB_CONTINUE;
   
         if ( !ad->ad_logfile ) return SLAP_CB_CONTINUE;          if ( !op->o_bd || !ad->ad_logfile ) return SLAP_CB_CONTINUE;
   
 /*  /*
 ** add or modify: use modifiersName if present  ** add or modify: use modifiersName if present
Line 92  static int auditlog_response(Operation * Line 71  static int auditlog_response(Operation *
                         what = "add";                          what = "add";
                         for(a = op->ora_e->e_attrs; a; a = a->a_next)                          for(a = op->ora_e->e_attrs; a; a = a->a_next)
                                 if( a->a_desc == slap_schema.si_ad_modifiersName ) {                                  if( a->a_desc == slap_schema.si_ad_modifiersName ) {
                                         who = &a->a_vals[0];                                          who = a->a_vals[0].bv_val;
                                         break;                                          break;
                                 }                                  }
                         break;                          break;
                 case LDAP_REQ_MODIFY:                  case LDAP_REQ_MODIFY:
                         what = "modify";                          what = "modify";
                         for(m = op->orm_modlist; m; m = m->sml_next)                          for(m = op->orm_modlist; m; m = m->sml_next)
                                 if( m->sml_desc == slap_schema.si_ad_modifiersName &&                                  if( m->sml_desc == slap_schema.si_ad_modifiersName ) {
                                         ( m->sml_op == LDAP_MOD_ADD ||                                          who = m->sml_values[0].bv_val;
                                         m->sml_op == LDAP_MOD_REPLACE )) {  
                                         who = &m->sml_values[0];  
                                         break;                                          break;
                                 }                                  }
                         break;                          break;
Line 117  static int auditlog_response(Operation * Line 94  static int auditlog_response(Operation *
 ** note: this means requestor's dn when modifiersName is null  ** note: this means requestor's dn when modifiersName is null
 */  */
         if ( !who )          if ( !who )
                 who = &op->o_dn;                  who = op->o_dn.bv_val;
   
         ldap_pvt_thread_mutex_lock(&ad->ad_mutex);          ldap_pvt_thread_mutex_lock(&ad->ad_mutex);
         if((f = fopen(ad->ad_logfile, "a")) == NULL) {          if((f = fopen(ad->ad_logfile, "a")) == NULL) {
Line 125  static int auditlog_response(Operation * Line 102  static int auditlog_response(Operation *
                 return SLAP_CB_CONTINUE;                  return SLAP_CB_CONTINUE;
         }          }
   
         fprintf(f, "# %s %ld %s%s%s\n",          fprintf(f, "# %s %ld %s%s%s\ndn: %s\nchangetype: %s\n",
                 what, stamp, suffix, who ? " " : "", who ? who->bv_val : "");                  what, stamp, suffix, who ? " " : "", who ? who : "",
   
         if ( !BER_BVISEMPTY( &op->o_conn->c_dn ) &&  
                 (!who || !dn_match( who, &op->o_conn->c_dn )))  
                 fprintf(f, "# realdn: %s\n", op->o_conn->c_dn.bv_val );  
   
         fprintf(f, "dn: %s\nchangetype: %s\n",  
                 op->o_req_dn.bv_val, what);                  op->o_req_dn.bv_val, what);
   
         switch(op->o_tag) {          switch(op->o_tag) {
           case LDAP_REQ_ADD:            case LDAP_REQ_ADD:
                 for(a = op->ora_e->e_attrs; a; a = a->a_next)                  for(a = op->ora_e->e_attrs; a; a = a->a_next)
                   if((b = a->a_vals) != NULL)                      if(b = a->a_vals)
                         for(i = 0; b[i].bv_val; i++)                          for(i = 0; b[i].bv_val; i++)
                                 fprint_ldif(f, a->a_desc->ad_cname.bv_val, b[i].bv_val, b[i].bv_len);                                  fprint_ldif(f, a->a_desc->ad_cname.bv_val, b[i].bv_val, b[i].bv_len);
                 break;                  break;
Line 155  static int auditlog_response(Operation * Line 126  static int auditlog_response(Operation *
                                         continue;                                          continue;
                         }                          }
                         fprintf(f, "%s: %s\n", what, m->sml_desc->ad_cname.bv_val);                          fprintf(f, "%s: %s\n", what, m->sml_desc->ad_cname.bv_val);
                         if((b = m->sml_values) != NULL)                          if(b = m->sml_values) for(i = 0; b[i].bv_val; i++)
                           for(i = 0; b[i].bv_val; i++)  
                                 fprint_ldif(f, m->sml_desc->ad_cname.bv_val, b[i].bv_val, b[i].bv_len);                                  fprint_ldif(f, m->sml_desc->ad_cname.bv_val, b[i].bv_val, b[i].bv_len);
                         fprintf(f, "-\n");                          fprintf(f, "-\n");
                 }                  }
Line 188  auditlog_db_init( Line 158  auditlog_db_init(
 )  )
 {  {
         slap_overinst *on = (slap_overinst *)be->bd_info;          slap_overinst *on = (slap_overinst *)be->bd_info;
         auditlog_data *ad = ch_calloc(1, sizeof(auditlog_data));          auditlog_data *ad = ch_malloc(sizeof(auditlog_data));
   
         on->on_bi.bi_private = ad;          on->on_bi.bi_private = ad;
         ldap_pvt_thread_mutex_init( &ad->ad_mutex );          ldap_pvt_thread_mutex_init( &ad->ad_mutex );
Line 205  auditlog_db_close( Line 175  auditlog_db_close(
   
         free( ad->ad_logfile );          free( ad->ad_logfile );
         ad->ad_logfile = NULL;          ad->ad_logfile = NULL;
         return 0;  
 }  }
   
 static int  static int
Line 218  auditlog_db_destroy( Line 187  auditlog_db_destroy(
   
         ldap_pvt_thread_mutex_destroy( &ad->ad_mutex );          ldap_pvt_thread_mutex_destroy( &ad->ad_mutex );
         free( ad );          free( ad );
         return 0;  
 }  }
   
 static int  static int
Line 248  auditlog_config( Line 216  auditlog_config(
 }  }
   
 int auditlog_initialize() {  int auditlog_initialize() {
         int rc;  
   
         auditlog.on_bi.bi_type = "auditlog";          auditlog.on_bi.bi_type = "auditlog";
         auditlog.on_bi.bi_db_init = auditlog_db_init;          auditlog.on_bi.bi_db_init = auditlog_db_init;
           auditlog.on_bi.bi_db_config = auditlog_config;
         auditlog.on_bi.bi_db_close = auditlog_db_close;          auditlog.on_bi.bi_db_close = auditlog_db_close;
         auditlog.on_bi.bi_db_destroy = auditlog_db_destroy;          auditlog.on_bi.bi_db_destroy = auditlog_db_destroy;
         auditlog.on_response = auditlog_response;          auditlog.on_response = auditlog_response;
   
         auditlog.on_bi.bi_cf_ocs = auditlogocs;  
         rc = config_register_schema( auditlogcfg, auditlogocs );  
         if ( rc ) return rc;  
   
         return overlay_register(&auditlog);          return overlay_register(&auditlog);
 }  }
   

Removed from v.1.1.2.9  
changed lines
  Added in v.1.2


______________
© Copyright 1998-2020, OpenLDAP Foundation, info@OpenLDAP.org