/* $Id: dspam_admin.c,v 1.26 2011/06/28 00:13:48 sbajic Exp $ */
/*
DSPAM
COPYRIGHT (C) 2002-2012 DSPAM PROJECT
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
*/
#ifdef HAVE_CONFIG_H
#include
#endif
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "config.h"
#include "libdspam.h"
#include "read_config.h"
#include "language.h"
#include "pref.h"
#define TSYNTAX "syntax: dspam_admin [function] [arguments] [--profile=PROFILE]"
/*
PREFERENCE FUNCTIONS
Add a Preference: dspam_admin add preference [user] [attr] [value]
Set a Preference: dspam_admin change preference [user] [attr] [value]
Delete a Preference: dspam_admin delete preference [user] [attr]
List Preferences: dspam_admin list preferences [user]
*/
int set_preference_attribute(const char *, const char *, const char *);
int del_preference_attribute(const char *, const char *);
int list_preference_attributes(const char *);
int list_aggregate_preference_attributes(const char *);
void dieout (int signal);
int usage (void);
int min_args(int argc, int min);
int
main (int argc, char **argv)
{
#ifdef TRUSTED_USER_SECURITY
struct passwd *p = getpwuid (getuid ());
#endif
int i, valid = 0;
int ret = EXIT_SUCCESS;
/* Read dspam.conf */
agent_config = read_config(NULL);
if (!agent_config) {
LOG(LOG_ERR, ERR_AGENT_READ_CONFIG);
fprintf (stderr, ERR_AGENT_READ_CONFIG "\n");
exit(EXIT_FAILURE);
}
if (!_ds_read_attribute(agent_config, "Home")) {
LOG(LOG_ERR, ERR_AGENT_DSPAM_HOME);
fprintf (stderr, ERR_AGENT_DSPAM_HOME "\n");
_ds_destroy_config(agent_config);
exit(EXIT_FAILURE);
}
if (libdspam_init(_ds_read_attribute(agent_config, "StorageDriver")) != 0) {
LOG(LOG_ERR, ERR_DRV_INIT);
fprintf (stderr, ERR_DRV_INIT "\n");
_ds_destroy_config(agent_config);
exit(EXIT_FAILURE);
}
#ifndef _WIN32
#ifdef TRUSTED_USER_SECURITY
if (!_ds_match_attribute(agent_config, "Trust", p->pw_name) && p->pw_uid) {
fprintf(stderr, ERR_TRUSTED_MODE "\n");
_ds_destroy_config(agent_config);
goto BAIL;
}
#endif
#endif
for(i=0;iattribute, pref->value);
}
_ds_pref_free(PTX);
free(PTX);
return 0;
}
int list_aggregate_preference_attributes(const char *username)
{
agent_pref_t PTX = NULL;
agent_pref_t STX = NULL;
agent_pref_t UTX = NULL;
agent_attrib_t pref;
int i;
STX = _ds_pref_load(agent_config,
NULL,
_ds_read_attribute(agent_config, "Home"), NULL);
if (STX == NULL || STX[0] == 0) {
if (STX) {
_ds_pref_free(STX);
}
LOGDEBUG("default preferences empty. reverting to dspam.conf preferences.");
STX = pref_config();
} else {
LOGDEBUG("loaded default preferences externally");
}
if (username[0] == 0 || !strncmp(username, "default", strlen(username)))
UTX = _ds_pref_load(agent_config, NULL, _ds_read_attribute(agent_config, "Home"), NULL);
else {
UTX = _ds_pref_load(agent_config, username, _ds_read_attribute(agent_config, "Home"), NULL);
}
PTX = _ds_pref_aggregate(STX, UTX);
_ds_pref_free(STX);
free(STX);
if (UTX != NULL) {
_ds_pref_free(UTX);
free(UTX);
}
for(i=0;PTX[i];i++) {
pref = PTX[i];
printf("%s=%s\n", pref->attribute, pref->value);
}
_ds_pref_free(PTX);
free(PTX);
return 0;
}