summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>1998-05-10 08:24:38 +0000
committerAndrew Tridgell <tridge@samba.org>1998-05-10 08:24:38 +0000
commitff8b29b8c62f377ede40fbf0cbbaa428bd8df60a (patch)
tree7a4ff6222f9d13c287884fdb8b3e53ec68c38b5a
parent8ef4ffd6987bb566c268d2a353d5fea1cfd9e430 (diff)
downloadrsync-ff8b29b8c62f377ede40fbf0cbbaa428bd8df60a.tar.gz
use syslog instead of /var/adm/rsyncd.log
-rw-r--r--clientserver.c5
-rw-r--r--log.c41
-rw-r--r--main.c2
-rw-r--r--rsync.h2
-rw-r--r--socket.c47
-rw-r--r--util.c1
6 files changed, 77 insertions, 21 deletions
diff --git a/clientserver.c b/clientserver.c
index 95ca7b6c..71188e97 100644
--- a/clientserver.c
+++ b/clientserver.c
@@ -100,6 +100,9 @@ static int rsync_module(int fd, int i)
gid_t gid;
char *p;
+ rprintf(FINFO,"rsync on module %s from %s (%s)\n",
+ lp_name(i), client_name(fd), client_addr(fd));
+
module_id = i;
if (lp_read_only(i))
@@ -123,8 +126,6 @@ static int rsync_module(int fd, int i)
gid = atoi(p);
}
- rprintf(FERROR,"rsyncd starting\n");
-
if (chroot(lp_path(i))) {
io_printf(fd,"@ERROR: chroot failed\n");
return -1;
diff --git a/log.c b/log.c
index 20dc702a..e047d96f 100644
--- a/log.c
+++ b/log.c
@@ -33,10 +33,11 @@ void rprintf(int fd, const char *format, ...)
extern int am_daemon;
if (am_daemon) {
- static FILE *logf;
- if (!logf) logf = fopen(RSYNCD_LOG, "a");
- f = logf;
- if (!f) return;
+#ifdef LOG_DAEMON
+ openlog("rsyncd", LOG_PID, LOG_DAEMON);
+#else /* for old systems that have no facility codes. */
+ openlog("rsyncd", LOG_PID);
+#endif
}
va_start(ap, format);
@@ -50,20 +51,28 @@ void rprintf(int fd, const char *format, ...)
if (len < 0) exit_cleanup(1);
- if (!am_daemon) {
- if (fd == FERROR) {
- f = stderr;
- }
-
- if (fd == FINFO) {
- extern int am_server;
- if (am_server)
- f = stderr;
- else
- f = stdout;
- }
+ buf[len] = 0;
+
+ if (am_daemon) {
+ int priority = LOG_INFO;
+ if (fd == FERROR) priority = LOG_WARNING;
+
+ syslog(priority, "%s", buf);
+ return;
}
+ if (fd == FERROR) {
+ f = stderr;
+ }
+
+ if (fd == FINFO) {
+ extern int am_server;
+ if (am_server)
+ f = stderr;
+ else
+ f = stdout;
+ }
+
if (!f) exit_cleanup(1);
if (fwrite(buf, len, 1, f) != 1) exit_cleanup(1);
diff --git a/main.c b/main.c
index e9a00397..638dd75d 100644
--- a/main.c
+++ b/main.c
@@ -222,8 +222,6 @@ static void do_server_sender(int f_in, int f_out, int argc,char *argv[])
argv[0] = ".";
}
- rprintf(FINFO,"sending file list\n");
-
flist = send_file_list(f_out,argc,argv);
send_files(flist,f_out,f_in);
report(f_out);
diff --git a/rsync.h b/rsync.h
index 62c03467..692584ab 100644
--- a/rsync.h
+++ b/rsync.h
@@ -22,7 +22,6 @@
#define RSYNC_NAME "rsync"
#define RSYNCD_CONF "/etc/rsyncd.conf"
-#define RSYNCD_LOG "/var/adm/rsyncd.log"
#define BACKUP_SUFFIX "~"
@@ -179,6 +178,7 @@
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
+#include <syslog.h>
#ifndef S_IFLNK
#define S_IFLNK 0120000
diff --git a/socket.c b/socket.c
index a92cccdf..5ee31f6d 100644
--- a/socket.c
+++ b/socket.c
@@ -294,3 +294,50 @@ void become_daemon(void)
close(1);
close(2);
}
+
+/*******************************************************************
+ return the IP addr of the client as a string
+ ******************************************************************/
+char *client_addr(int fd)
+{
+ struct sockaddr sa;
+ struct sockaddr_in *sockin = (struct sockaddr_in *) (&sa);
+ int length = sizeof(sa);
+ static char addr_buf[100];
+
+ if (getpeername(fd, &sa, &length)) {
+ exit(1);
+ }
+
+ strlcpy(addr_buf,(char *)inet_ntoa(sockin->sin_addr), sizeof(addr_buf)-1);
+
+ return addr_buf;
+}
+
+
+/*******************************************************************
+ return the DNS name of the client
+ ******************************************************************/
+char *client_name(int fd)
+{
+ struct sockaddr sa;
+ struct sockaddr_in *sockin = (struct sockaddr_in *) (&sa);
+ int length = sizeof(sa);
+ static char name_buf[100];
+ struct hostent *hp;
+
+ strcpy(name_buf,"UNKNOWN");
+
+ if (getpeername(fd, &sa, &length)) {
+ exit(1);
+ }
+
+ /* Look up the remote host name. */
+ if ((hp = gethostbyaddr((char *) &sockin->sin_addr,
+ sizeof(sockin->sin_addr),
+ AF_INET))) {
+ strlcpy(name_buf,(char *)hp->h_name,sizeof(name_buf) - 1);
+ }
+
+ return name_buf;
+}
diff --git a/util.c b/util.c
index 67308cd2..346d58af 100644
--- a/util.c
+++ b/util.c
@@ -482,3 +482,4 @@ int name_to_gid(char *name, gid_t *gid)
return 0;
}
+