vs_stats.c revision bfc848c632c9eacb2a640246d96e198f1b185c03
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Implementation of the vscan statistics interface
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <syslog.h>
#include <pthread.h>
#include <door.h>
#include <pwd.h>
#include <auth_attr.h>
#include <secdb.h>
#include <fcntl.h>
#include "vs_incl.h"
/* local data */
static vs_stats_t vscan_stats;
static int vs_stats_door_cookie;
static int vs_stats_door_fd = -1;
/* function prototype */
static int vs_stats_check_auth(void);
static void vs_stats_reset(void);
/*
* vs_stats_init
*
* Invoked on daemon load and unload
*/
int
vs_stats_init(void)
{
(void) pthread_mutex_lock(&vs_stats_mutex);
/* door initialization */
vs_stats_door_fd = -1;
} else {
(void) fdetach(VS_STATS_DOOR_NAME);
(void) door_revoke(vs_stats_door_fd);
vs_stats_door_fd = -1;
}
}
(void) pthread_mutex_unlock(&vs_stats_mutex);
}
/*
* vs_stats_fini
*
* Invoked on daemon unload
*/
void
vs_stats_fini(void)
{
(void) pthread_mutex_lock(&vs_stats_mutex);
/* door termination */
if (vs_stats_door_fd != -1)
(void) door_revoke(vs_stats_door_fd);
vs_stats_door_fd = -1;
(void) fdetach(VS_STATS_DOOR_NAME);
(void) unlink(VS_STATS_DOOR_NAME);
(void) pthread_mutex_unlock(&vs_stats_mutex);
}
/*
* vs_stats_check_auth
*
* Returns: 0 caller authorized to reset stats
* -1 caller not authorized to reset stats
*/
static int
{
if (door_ucred(&uc) != 0)
return (-1);
ucred_free(uc);
return (-1);
}
ucred_free(uc);
return (0);
}
/*
* vs_stats_door_call
*/
/* ARGSUSED */
static void
{
/* LINTED E_BAD_PTR_CAST_ALIGN */
if ((cookie != &vs_stats_door_cookie) ||
(size != sizeof (vs_stats_req_t)) ||
return;
}
case VS_STATS_GET:
(void) pthread_mutex_lock(&vs_stats_mutex);
(void) pthread_mutex_unlock(&vs_stats_mutex);
NULL, 0);
break;
case VS_STATS_RESET:
break;
default:
return;
}
}
/*
* vs_stats_reset
*
* Reset totals and per-engine statistics to 0
*/
static void
{
int i;
if (vs_stats_check_auth() != 0)
return;
(void) pthread_mutex_lock(&vs_stats_mutex);
vscan_stats.vss_scanned = 0;
vscan_stats.vss_infected = 0;
vscan_stats.vss_cleaned = 0;
vscan_stats.vss_failed = 0;
for (i = 0; i < VS_SE_MAX; i++)
(void) pthread_mutex_unlock(&vs_stats_mutex);
}
/*
* vs_stats_set
*
* Update scan request stats
*/
void
vs_stats_set(int retval)
{
(void) pthread_mutex_lock(&vs_stats_mutex);
switch (retval) {
case VS_RESULT_CLEAN:
break;
case VS_RESULT_CLEANED:
break;
case VS_RESULT_FORBIDDEN:
break;
case VS_RESULT_SE_ERROR:
case VS_RESULT_ERROR:
default:
break;
}
(void) pthread_mutex_unlock(&vs_stats_mutex);
}
/*
* vs_stats_eng_err
*
* Increment the error count stat for eng
*/
void
vs_stats_eng_err(char *engid)
{
int i;
(void) pthread_mutex_lock(&vs_stats_mutex);
for (i = 0; i < VS_SE_MAX; i++) {
break;
break;
}
}
(void) pthread_mutex_unlock(&vs_stats_mutex);
}
/*
* vs_stats_config
*/
void
{
int i, j;
(void) pthread_mutex_lock(&vs_stats_mutex);
for (i = 0; i < VS_SE_MAX; i++) {
if (*engid == 0)
break;
/* find previous error count for engid */
for (j = 0; j < VS_SE_MAX; j++) {
break;
}
}
}
(void) pthread_mutex_unlock(&vs_stats_mutex);
}