summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjkar8572 <jkar8572>2001-09-21 12:45:22 +0000
committerjkar8572 <jkar8572>2001-09-21 12:45:22 +0000
commitd9b70c744b212ede06d4487e134c9aaca084e037 (patch)
tree499b5972dfb20eec26ae8c8add3a65496737a44a
parent04a1421bea066571fbeda0c764013fe1abd05fc9 (diff)
downloadlinuxquota-d9b70c744b212ede06d4487e134c9aaca084e037.tar.gz
Syslog support for rpc.rquotad by Jani Jaakkola; fixed some bugs by me...
-rw-r--r--common.c45
-rw-r--r--common.h4
-rw-r--r--quotacheck.c4
-rw-r--r--rquota_svc.c73
4 files changed, 90 insertions, 36 deletions
diff --git a/common.c b/common.c
index 576adb2..a53728f 100644
--- a/common.c
+++ b/common.c
@@ -3,26 +3,57 @@
* Common things for all utilities
*
* Jan Kara <jack@suse.cz> - sponsored by SuSE CR
+ *
+ * Jani Jaakkola <jjaakkol@cs.helsinki.fi> - syslog support
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
-
+#include <syslog.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "pot.h"
#include "common.h"
+static int enable_syslog=0;
+
+void use_syslog(void)
+{
+ openlog(progname,0,LOG_DAEMON);
+ enable_syslog=1;
+}
+
+static void do_syslog(int level, const char *format, va_list args)
+{
+ char buf[1024];
+ int i, j;
+
+ vsnprintf(buf,sizeof(buf),format,args);
+ /* This while removes newlines from the log, so that
+ * syslog() will be called once for every line */
+ for (i = 0; buf[i]; i = j) {
+ for (j = i; buf[j] && buf[j] != '\n'; j++);
+ if (buf[j] == '\n')
+ buf[j++] = '\0';
+ syslog(level, "%s", buf + i);
+ }
+}
+
void die(int ret, char *fmtstr, ...)
{
va_list args;
- fprintf(stderr, "%s: ", progname);
va_start(args, fmtstr);
- vfprintf(stderr, fmtstr, args);
+ if (enable_syslog) {
+ do_syslog(LOG_CRIT, fmtstr, args);
+ syslog(LOG_CRIT, "Exiting with status %d", ret);
+ } else {
+ fprintf(stderr, "%s: ", progname);
+ vfprintf(stderr, fmtstr, args);
+ }
va_end(args);
exit(ret);
}
@@ -31,9 +62,13 @@ void errstr(char *fmtstr, ...)
{
va_list args;
- fprintf(stderr, "%s: ", progname);
va_start(args, fmtstr);
- vfprintf(stderr, fmtstr, args);
+ if (enable_syslog)
+ do_syslog(LOG_ERR, fmtstr, args);
+ else {
+ fprintf(stderr, "%s: ", progname);
+ vfprintf(stderr, fmtstr, args);
+ }
va_end(args);
}
diff --git a/common.h b/common.h
index bd196cb..25eac55 100644
--- a/common.h
+++ b/common.h
@@ -18,6 +18,10 @@ void die(int, char *, ...);
/* Print an error */
void errstr(char *, ...);
+/* If use_syslog is called, all error reports using errstr() and die() are
+ * written to syslog instead of stderr */
+void use_syslog();
+
/* malloc() with error check */
void *smalloc(size_t);
diff --git a/quotacheck.c b/quotacheck.c
index 5bfb41a..08d62c6 100644
--- a/quotacheck.c
+++ b/quotacheck.c
@@ -8,7 +8,7 @@
* New quota format implementation - Jan Kara <jack@suse.cz> - Sponsored by SuSE CR
*/
-#ident "$Id: quotacheck.c,v 1.18 2001/09/04 16:21:58 jkar8572 Exp $"
+#ident "$Id: quotacheck.c,v 1.19 2001/09/21 12:45:22 jkar8572 Exp $"
#include <dirent.h>
#include <stdio.h>
@@ -360,7 +360,7 @@ static void parse_options(int argcnt, char **argstr)
#if defined(EXT2_DIRECT)
static int ext2_direct_scan(char *device)
{
- ino_t i_num;
+ ext2_ino_t i_num;
ext2_filsys fs;
errcode_t error;
ext2_inode_scan scan;
diff --git a/rquota_svc.c b/rquota_svc.c
index 53abaaf..431a1dc 100644
--- a/rquota_svc.c
+++ b/rquota_svc.c
@@ -9,8 +9,10 @@
* Rquota service handlers.
*
* Author: Marco van Wieringen <mvw@planets.elm.net>
+ * changes for new utilities by Jan Kara <jack@suse.cz>
+ * patches by Jani Jaakkola <jjaakkol@cs.helsinki.fi>
*
- * Version: $Id: rquota_svc.c,v 1.7 2001/09/17 15:02:51 jkar8572 Exp $
+ * Version: $Id: rquota_svc.c,v 1.8 2001/09/21 12:45:22 jkar8572 Exp $
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -21,6 +23,7 @@
#include <rpc/rpc.h>
#include <sys/socket.h>
#include <netinet/in.h>
+#include <arpa/inet.h>
#include <rpc/pmap_clnt.h> /* for pmap_unset */
#include <stdio.h>
#include <stdlib.h> /* getenv, exit */
@@ -31,7 +34,6 @@
#ifdef HOSTS_ACCESS
#include <tcpd.h>
#include <netdb.h>
-#include <arpa/inet.h>
#endif
#ifdef __STDC__
@@ -61,13 +63,13 @@ static struct option options[]= {
{ NULL, 0, NULL , 0 }
};
-static void show_help() {
- printf("Usage: %s [options]\n",progname);
- printf("Options are:\n");
- printf(" -h --help shows this text\n");
- printf(" -V --version show version information\n");
- printf(" -F --foreground starts the quota service in foreground\n");
- printf(" -s --no-setquota disables remote calls to setquota\n");
+static void show_help(void)
+{
+ errstr(_("Usage: %s [options]\nOptions are:\n\
+ -h --help shows this text\n\
+ -V --version shows version information\n\
+ -F --foreground starts the quota service in foreground\n\
+ -s --no-setquota disables remote calls to setquota\n"), progname);
}
static void parse_options(int argc, char **argv)
@@ -75,20 +77,21 @@ static void parse_options(int argc, char **argv)
char ostr[128]="";
int i,opt;
int j=0;
- for(i=0;options[i].name;i++) {
- ostr[j++]=options[i].val;
- if (options[i].has_arg) ostr[j++]=':';
+
+ for(i=0; options[i].name; i++) {
+ ostr[j++] = options[i].val;
+ if (options[i].has_arg) ostr[j++] = ':';
}
- while( (opt=getopt_long(argc, argv, ostr, options, NULL))>=0 ) {
+ while ((opt=getopt_long(argc, argv, ostr, options, NULL))>=0) {
switch(opt) {
- case 'V': version(); exit(0);
- case 'h': show_help(); exit(0);
- case 'F': disable_daemon=1; break;
- case 's': disable_setquota=1; break;
- default:
- fprintf(stderr,"Unknown option '%c'.\n",opt);
- show_help();
- exit(1);
+ case 'V': version(); exit(0);
+ case 'h': show_help(); exit(0);
+ case 'F': disable_daemon = 1; break;
+ case 's': disable_setquota = 1; break;
+ default:
+ errstr(_("Unknown option '%c'.\n"), opt);
+ show_help();
+ exit(1);
}
}
}
@@ -104,13 +107,21 @@ int good_client(struct sockaddr_in *addr, rpcproc_t rq_proc)
struct hostent *h;
char *name, **ad;
#endif
+ const char *remote=inet_ntoa(addr->sin_addr);
- if ( rq_proc==RQUOTAPROC_SETQUOTA ||
+ if (rq_proc==RQUOTAPROC_SETQUOTA ||
rq_proc==RQUOTAPROC_SETACTIVEQUOTA) {
/* If setquota is disabled, fail always */
- if (disable_setquota) return 0;
+ if (disable_setquota) {
+ errstr(_("host %s attempted to call setquota when disabled\n"),
+ remote);
+
+ return 0;
+ }
/* Require that SETQUOTA calls originate from port < 1024 */
if (ntohs(addr->sin_port)>=1024) {
+ errstr(_("host %s attempted to call setquota from port >= 1024\n"),
+ remote);
return 0;
}
/* Setquota OK */
@@ -121,22 +132,22 @@ int good_client(struct sockaddr_in *addr, rpcproc_t rq_proc)
* allow only some hosts to call setquota. */
/* Check IP address */
- if (hosts_ctl("rquotad", "", inet_ntoa(addr->sin_addr), ""))
+ if (hosts_ctl("rquotad", "", remote, ""))
return 1;
/* Get address */
if (!(h = gethostbyaddr((const char *)&(addr->sin_addr), sizeof(addr->sin_addr), AF_INET)))
- return 0;
+ goto denied;
if (!(name = alloca(strlen(h->h_name)+1)))
- return 0;
+ goto denied;
strcpy(name, h->h_name);
/* Try to resolve it back */
if (!(h = gethostbyname(name)))
- return 0;
+ goto denied;
for (ad = h->h_addr_list; *ad; ad++)
if (!memcmp(*ad, &(addr->sin_addr), h->h_length))
break;
if (!*ad) /* Our address not found? */
- return 0;
+ goto denied;
/* Check host name */
if (hosts_ctl("rquotad", "", h->h_name, ""))
return 1;
@@ -144,6 +155,8 @@ int good_client(struct sockaddr_in *addr, rpcproc_t rq_proc)
for (ad = h->h_aliases; *ad; ad++)
if (hosts_ctl("rquotad", "", *ad, ""))
return 1;
+denied:
+ errstr(_("Denied access to host %s\n"), remote);
return 0;
#else
/* If no access checking is available, OK always */
@@ -364,8 +377,10 @@ int main(int argc, char **argv)
exit(1);
}
- if (!disable_daemon)
+ if (!disable_daemon) {
+ use_syslog();
daemon(0, 0);
+ }
svc_run();
errstr(_("svc_run returned\n"));
exit(1);