-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, 23 Sep 2002 00:38, Brad Hards wrote:
> The attached patch adds "first draft" support for service location
> protocol, using OpenSLP  (http://www.openslp.org). This allows you to
> automagically discover all the rsync servers on your network (which is
> defined in terms of your SLP configuration - typically equal to multicast
> scope, but you can change it around with Directory agents).
<snip>

For those people that looked at the patch and found it so ugly that their eyes 
hurt - I apologise. Must have been a bad pizza that night :(


I've cleaned the service registration up a bit, and added some service 
location stuff. You can now do something like:
bradh@squirt rsync-2.5.5 $ ./rsync rsync://
  rsync://squirt.cuneata.net:5678:/ftp          whole ftp area (approx 6.1 GB)
  rsync://squirt.cuneata.net:5678:/sambawww     Samba WWW pages (approx 240 
MB)
  rsync://squirt.cuneata.net:5678:/cvs          CVS repository (requires 
authentication)
  rsync://squirt.cuneata.net:5678:/test3        Test3 ftp area (approx 0 MB)
  rsync://squirt.cuneata.net:5678:/newftp       (No description)


The service location code (srvloc.c) is pretty ugly - its basically only demo 
quality. But it runs.


In a GUI version, what other module attributes are people interested in 
(assuming that there is any interest at all in any of this)? The ones I 
thought about:
* read only
* auth users (which would indicate whether this module required authorisation, 
or not, rather than specifying the users)
* hosts deny and hosts allow (which would indicate if there were any hosts in 
such a list, rather than actually registering the list)

I need to specify this if there is ever going to be an SLP service template 
for rsync.

Brad
- -- 
http://conf.linux.org.au. 22-25Jan2003. Perth, Aust. Tickets booked.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE9kpgyW6pHgIdAuOMRAu8sAJ9GbUXqtnzm+Rq7iNNJnWR/t+TA5gCglCbi
MEdYhlpl9sdGCEEx4c69/Io=
=kvV2
-----END PGP SIGNATURE-----
diff -Naur -x configure -x rsync.h clean/rsync-2.5.5/Makefile.in rsync-2.5.5/Makefile.in
--- clean/rsync-2.5.5/Makefile.in	Mon Mar 25 15:36:56 2002
+++ rsync-2.5.5/Makefile.in	Mon Sep 23 22:14:12 2002
@@ -10,6 +10,8 @@
 CC=@CC@
 CFLAGS=@CFLAGS@
 LDFLAGS=@LDFLAGS@
+LIBSLP=@LIBSLP@
+SLPOBJ=@SLPOBJ@
 
 INSTALLCMD=@INSTALL@
 INSTALLMAN=@INSTALL@
@@ -32,7 +34,7 @@
 OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o main.o checksum.o match.o syscall.o log.o backup.o
 OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o fileio.o batch.o \
 	clientname.o
-DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
+DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o $(SLPOBJ)
 popt_OBJS=popt/findme.o  popt/popt.o  popt/poptconfig.o \
 	popt/popthelp.o popt/poptparse.o
 OBJS=$(OBJS1) $(OBJS2) $(DAEMON_OBJ) $(LIBOBJ) $(ZLIBOBJ) @BUILD_POPT@
@@ -65,7 +67,7 @@
 
 rsync: $(OBJS)
 	@echo "Please ignore warnings below about mktemp -- it is used in a safe way"
-	$(CC) $(CFLAGS) $(LDFLAGS) -o rsync $(OBJS) $(LIBS)
+	$(CC) $(CFLAGS) $(LDFLAGS) -o rsync $(OBJS) $(LIBS) $(LIBSLP)
 
 $(OBJS): config.h
 
diff -Naur -x configure -x rsync.h clean/rsync-2.5.5/clientserver.c rsync-2.5.5/clientserver.c
--- clean/rsync-2.5.5/clientserver.c	Wed Mar 27 12:03:13 2002
+++ rsync-2.5.5/clientserver.c	Mon Sep 23 22:09:53 2002
@@ -559,6 +559,12 @@
          * address too.  In fact, why not just do inet_ntop on the
          * local address??? */
 
+#ifdef HAVE_LIBSLP
+	if (0 != register_services()) {
+		rprintf(FINFO, "Couldn't register with service discovery protocol, continuing anyway\n");
+	}
+#endif
+
 	if (((pid_file = lp_pid_file()) != NULL) && (*pid_file != '\0')) {
 		char pidbuf[16];
 		int fd;
diff -Naur -x configure -x rsync.h clean/rsync-2.5.5/config.h.in rsync-2.5.5/config.h.in
--- clean/rsync-2.5.5/config.h.in	Tue Apr  2 11:50:49 2002
+++ rsync-2.5.5/config.h.in	Sun Sep 22 21:34:55 2002
@@ -116,6 +116,9 @@
 /* Define if you have the `socket' library (-lsocket). */
 #undef HAVE_LIBSOCKET
 
+/* Define if you have the Service Location Protocol libraries (-lslp). */
+#undef HAVE_LIBSLP
+
 /* Define if you have the `link' function. */
 #undef HAVE_LINK
 
diff -Naur -x configure -x rsync.h clean/rsync-2.5.5/configure.in rsync-2.5.5/configure.in
--- clean/rsync-2.5.5/configure.in	Tue Apr  2 11:41:59 2002
+++ rsync-2.5.5/configure.in	Thu Sep 26 12:54:31 2002
@@ -364,6 +364,29 @@
 AC_CHECK_FUNCS(memmove lchown vsnprintf snprintf asprintf setsid glob strpbrk)
 AC_CHECK_FUNCS(strlcat strlcpy mtrace mallinfo setgroups)
 
+AC_ARG_ENABLE(slp, [  --disable-slp           turn off SLP support, defaults to on])
+AC_ARG_WITH(openslp-libs, [  --with-openslp-libs     set directory for OpenSLP library],
+    LDFLAGS="-L$withval $LDFLAGS"
+    DSOFLAGS="-L$withval $DSOFLAGS",)
+AC_ARG_WITH(openslp-includes, [  --with-openslp-includes set directory for OpenSLP includes],
+    CFLAGS="-I$withval $CFLAGS"
+    CXXFLAGS="-I$withval $CXXFLAGS"
+    CPPFLAGS="-I$withval $CPPFLAGS",)
+
+LIBSLP=""
+SLPOBJ=""
+
+if test x$enable_slp != xno; then
+    AC_CHECK_HEADER(slp.h,
+        AC_CHECK_LIB(slp, SLPOpen,
+            AC_DEFINE(HAVE_LIBSLP)
+	    SLPOBJ="srvreg.o srvloc.o"
+            LIBSLP="-lslp"))
+fi
+
+AC_SUBST(LIBSLP)
+AC_SUBST(SLPOBJ)
+
 AC_CACHE_CHECK([for working socketpair],rsync_cv_HAVE_SOCKETPAIR,[
 AC_TRY_RUN([
 #include <sys/types.h>
diff -Naur -x configure -x rsync.h clean/rsync-2.5.5/loadparm.c rsync-2.5.5/loadparm.c
--- clean/rsync-2.5.5/loadparm.c	Mon Mar 25 15:04:23 2002
+++ rsync-2.5.5/loadparm.c	Mon Sep 23 18:22:12 2002
@@ -103,6 +103,7 @@
 	char *pid_file;
 	int syslog_facility;
 	char *socket_options;
+	int slp_refresh;
 } global;
 
 static global Globals;
@@ -268,6 +269,7 @@
   {"socket options",   P_STRING,  P_GLOBAL, &Globals.socket_options,NULL,  0},
   {"log file",         P_STRING,  P_GLOBAL, &Globals.log_file,      NULL,  0},
   {"pid file",         P_STRING,  P_GLOBAL, &Globals.pid_file,      NULL,  0},
+  {"slp refresh",      P_INTEGER, P_GLOBAL, &Globals.slp_refresh,   NULL,  0},
 
   {"timeout",          P_INTEGER, P_LOCAL,  &sDefault.timeout,     NULL,  0},
   {"max connections",  P_INTEGER, P_LOCAL,  &sDefault.max_connections,NULL, 0},
@@ -347,6 +349,7 @@
 FN_GLOBAL_STRING(lp_pid_file, &Globals.pid_file)
 FN_GLOBAL_STRING(lp_socket_options, &Globals.socket_options)
 FN_GLOBAL_INTEGER(lp_syslog_facility, &Globals.syslog_facility)
+FN_GLOBAL_INTEGER(lp_slp_refresh, &Globals.slp_refresh)
 
 FN_LOCAL_STRING(lp_name, name)
 FN_LOCAL_STRING(lp_comment, comment)
diff -Naur -x configure -x rsync.h clean/rsync-2.5.5/main.c rsync-2.5.5/main.c
--- clean/rsync-2.5.5/main.c	Wed Mar 27 16:10:44 2002
+++ rsync-2.5.5/main.c	Thu Sep 26 14:44:49 2002
@@ -675,6 +675,18 @@
 		char *host, *path;
 
 		host = argv[0] + strlen(URL_PREFIX);
+
+		if (0 == host[0]) {
+#ifdef HAVE_LIBSLP
+                        /* user tried just rsync:/ / URI */
+			print_service_list();
+			exit_cleanup(0);
+#else /* No SLP, die here */
+			rprintf(FINFO, "No SLP support, cannot browse\n");
+			exit_cleanup(RERR_SYNTAX);
+#endif
+		}
+
 		p = strchr(host,'/');
 		if (p) {
 			*p = 0;
diff -Naur -x configure -x rsync.h clean/rsync-2.5.5/options.c rsync-2.5.5/options.c
--- clean/rsync-2.5.5/options.c	Wed Mar 20 07:16:42 2002
+++ rsync-2.5.5/options.c	Mon Sep 23 19:49:03 2002
@@ -135,6 +135,7 @@
         char const *hardlinks = "no ";
         char const *links = "no ";
 	char const *ipv6 = "no ";
+	char const *slp = "no ";
 	STRUCT_STAT *dumstat;
 
 #ifdef HAVE_SOCKETPAIR
@@ -151,7 +152,11 @@
 
 #if INET6
 	ipv6 = "";
-#endif       
+#endif
+
+#if HAVE_LIBSLP
+	slp = "";
+#endif
 
         rprintf(f, "%s  version %s  protocol version %d\n",
                 RSYNC_NAME, RSYNC_VERSION, PROTOCOL_VERSION);
@@ -166,10 +171,11 @@
 	/* Note that this field may not have type ino_t.  It depends
 	 * on the complicated interaction between largefile feature
 	 * macros. */
-	rprintf(f, "              %sIPv6, %d-bit system inums, %d-bit internal inums\n",
+	rprintf(f, "              %sIPv6, %d-bit system inums, %d-bit internal inums, %sSLP\n",
 		ipv6, 
 		(int) (sizeof(dumstat->st_ino) * 8),
-		(int) (sizeof(INO64_T) * 8));
+		(int) (sizeof(INO64_T) * 8),
+		slp);
 
 #ifdef NO_INT64
         rprintf(f, "WARNING: no 64-bit integers on this platform!\n");
diff -Naur -x configure -x rsync.h clean/rsync-2.5.5/proto.h rsync-2.5.5/proto.h
--- clean/rsync-2.5.5/proto.h	Mon Mar 25 14:51:17 2002
+++ rsync-2.5.5/proto.h	Thu Sep 26 13:12:40 2002
@@ -119,6 +119,7 @@
 char *lp_pid_file(void);
 char *lp_socket_options(void);
 int lp_syslog_facility(void);
+int lp_slp_refresh(void);
 char *lp_name(int );
 char *lp_comment(int );
 char *lp_path(int );
@@ -259,3 +260,8 @@
 int cmp_modtime(time_t file1, time_t file2);
 int _Insure_trap_error(int a1, int a2, int a3, int a4, int a5, int a6);
 int sys_gettimeofday(struct timeval *tv);
+
+/* This one from srvreg.c */
+int register_services(void);
+/* This one from srvloc.c */
+int print_service_list(void);
diff -Naur -x configure -x rsync.h clean/rsync-2.5.5/rsync.1 rsync-2.5.5/rsync.1
--- clean/rsync-2.5.5/rsync.1	Thu Feb  7 08:21:19 2002
+++ rsync-2.5.5/rsync.1	Thu Sep 26 14:59:30 2002
@@ -149,6 +149,13 @@
 this would list all the anonymous rsync modules available on the host
 somehost\&.mydomain\&.com\&.  (See the following section for more details\&.)
 .PP 
+.RS 
+rsync rsync://
+.RE 
+.PP 
+If Service Location Protocol is available, this will list available
+rsync servers\&.
+.PP 
 .SH "CONNECTING TO AN RSYNC SERVER" 
 .PP 
 It is also possible to use rsync without using rsh or ssh as the
@@ -165,7 +172,7 @@
 .PP 
 .IP o 
 you use a double colon :: instead of a single colon to
-separate the hostname from the path\&. 
+separate the hostname from the path\&.
 .IP 
 .IP o 
 the remote server may print a message of the day when you
diff -Naur -x configure -x rsync.h clean/rsync-2.5.5/rsync.yo rsync-2.5.5/rsync.yo
--- clean/rsync-2.5.5/rsync.yo	Thu Feb  7 08:20:49 2002
+++ rsync-2.5.5/rsync.yo	Thu Sep 26 14:58:02 2002
@@ -132,6 +132,10 @@
 this would list all the anonymous rsync modules available on the host
 somehost.mydomain.com.  (See the following section for more details.)
 
+quote(rsync rsync://)
+
+If Service Location Protocol is available, this will list available
+rsync servers.
 
 manpagesection(CONNECTING TO AN RSYNC SERVER)
 
@@ -149,7 +153,7 @@
 
 itemize(
 	it() you use a double colon :: instead of a single colon to
-	separate the hostname from the path. 
+	separate the hostname from the path.
 
 	it() the remote server may print a message of the day when you
 	connect.
diff -Naur -x configure -x rsync.h clean/rsync-2.5.5/rsyncd.conf.5 rsync-2.5.5/rsyncd.conf.5
--- clean/rsync-2.5.5/rsyncd.conf.5	Fri Aug 31 18:12:35 2001
+++ rsync-2.5.5/rsyncd.conf.5	Mon Sep 23 19:59:58 2002
@@ -117,6 +117,15 @@
 details on some of the options you may be able to set\&. By default no
 special socket options are set\&.
 .IP 
+.IP "\fBslp refresh\fP" 
+This option is used to determine how long service
+advertisements are valid for (in seconds), and is only applicable if you have 
+Service Location Protocol support compiled in\&. If this option is not set,
+or is set to zero, then service advertisements never time out\&. If this
+is set to less than 120 seconds, then 120 seconds are used\&. If it is
+set to more than 65535, then 65535 is used - this is a limitation of SLP\&.
+3600 (one hour) is a good number if you tend to change your configuration\&.
+.IP 
 .PP 
 .SH "MODULE OPTIONS" 
 .PP 
@@ -456,7 +465,9 @@
 .br 
 syslog facility = local5 
 .br 
-pid file = /var/run/rsyncd\&.pid
+pid file = /var/run/rsyncd\&.pid 
+.br 
+slp refresh = 3600
 .PP 
 
 .nf 
diff -Naur -x configure -x rsync.h clean/rsync-2.5.5/rsyncd.conf.yo rsync-2.5.5/rsyncd.conf.yo
--- clean/rsync-2.5.5/rsyncd.conf.yo	Fri Aug 31 18:12:35 2001
+++ rsync-2.5.5/rsyncd.conf.yo	Mon Sep 23 19:59:49 2002
@@ -109,6 +109,14 @@
 details on some of the options you may be able to set. By default no
 special socket options are set.
 
+dit(bf(slp refresh)) This option is used to determine how long service
+advertisements are valid for (in seconds), and is only applicable if you have 
+Service Location Protocol support compiled in. If this option is not set,
+or is set to zero, then service advertisements never time out. If this
+is set to less than 120 seconds, then 120 seconds are used. If it is
+set to more than 65535, then 65535 is used - this is a limitation of SLP.
+3600 (one hour) is a good number if you tend to change your configuration.
+
 enddit()
 
 
@@ -398,7 +406,8 @@
 use chroot = no nl()
 max connections = 4 nl()
 syslog facility = local5 nl()
-pid file = /var/run/rsyncd.pid
+pid file = /var/run/rsyncd.pid nl()
+slp refresh = 3600
 
 verb([ftp]
         path = /var/ftp/pub
diff -Naur -x configure -x rsync.h clean/rsync-2.5.5/srvloc.c rsync-2.5.5/srvloc.c
--- clean/rsync-2.5.5/srvloc.c	Thu Jan  1 10:00:00 1970
+++ rsync-2.5.5/srvloc.c	Thu Sep 26 14:50:57 2002
@@ -0,0 +1,120 @@
+/* -*- c-file-style: "linux"; -*-
+   
+   Copyright (C) 2002 by Brad Hards <[EMAIL PROTECTED]>
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 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 General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+/* This file implements the service location functionality */
+/* Basically, it uses normal Service Location Protocol API */
+
+/* It is really a cheap hack - just to show how it might work
+   in a real application.
+*/
+
+#include <slp.h> 
+#include <stdio.h>
+#include <string.h>
+
+#include "rsync.h"
+
+/* This one just prints out the attributes */
+SLPBoolean getAttrCallback(SLPHandle hslp, 
+			  const char* attrlist, 
+			  SLPError errcode, 
+			  void* cookie ) 
+{ 
+    char *cleanstr;
+ 
+    hslp=hslp; cookie=cookie; /* gcc, be quiet */
+
+    if(errcode == SLP_OK) { 
+	if (!strcmp(attrlist, "(comment=)")) {
+	    rprintf(FINFO, "\t(No description)\n");
+	} else { 
+	    cleanstr = strrchr(attrlist, ')') ;
+	    *cleanstr = ' '; /* remove last ) */
+	    rprintf(FINFO, "\t%s\n", (strchr(attrlist,'=')+1)); 
+	} 
+    }
+    return SLP_FALSE; 
+} 
+
+
+SLPBoolean getSLPSrvURLCallback( SLPHandle hslp, 
+                                const char* srvurl, 
+                                unsigned short lifetime, 
+                                SLPError errcode, 
+                                void* cookie ) 
+{ 
+    SLPError    result; 
+    SLPHandle   attrhslp;
+
+    hslp=hslp; lifetime=lifetime; /* gcc, be quiet */
+
+    if(errcode == SLP_OK) {
+	rprintf(FINFO, "  %s  ", (strchr(srvurl, ':')+1)); /* chop service: off the front */ 
+	/* check for any attributes */
+	if(SLPOpen("en",SLP_FALSE,&attrhslp) == SLP_OK) {
+	    result = SLPFindAttrs(attrhslp, 
+				  srvurl,
+				  "", /* return all attributes */ 
+				  "", /* use configured scopes */ 
+				  getAttrCallback, 
+				  NULL); 
+	    if(result != SLP_OK) { 
+		rprintf(FERROR, "errorcode: %i\n",result); 
+	    } 
+	    SLPClose(attrhslp); 
+	}
+	*(SLPError*)cookie = SLP_OK; 
+    }
+    else { 
+	*(SLPError*)cookie = errcode; 
+    } 
+
+
+    /* return SLP_TRUE because we want to be called again */ 
+    /* if more services were found                        */ 
+
+    return SLP_TRUE; 
+} 
+
+
+int print_service_list () 
+{ 
+    SLPError err; 
+    SLPError callbackerr; 
+    SLPHandle hslp; 
+
+    err = SLPOpen("en",SLP_FALSE,&hslp); 
+    if(err != SLP_OK) 
+	{ 
+	    rprintf(FERROR, "Error opening slp handle %i\n",err); 
+	    return err; 
+	} 
+
+    SLPFindSrvs( hslp, 
+		 "rsync", 
+		 0,                    /* use configured scopes */ 
+		 0,                    /* no attr filter        */ 
+		 getSLPSrvURLCallback, 
+		 &callbackerr ); 
+
+    /* Now that we're done using slp, close the slp handle */ 
+    SLPClose(hslp); 
+
+    return 0;
+}
diff -Naur -x configure -x rsync.h clean/rsync-2.5.5/srvreg.c rsync-2.5.5/srvreg.c
--- clean/rsync-2.5.5/srvreg.c	Thu Jan  1 10:00:00 1970
+++ rsync-2.5.5/srvreg.c	Mon Sep 23 23:16:53 2002
@@ -0,0 +1,153 @@
+/* -*- c-file-style: "linux"; -*-
+   
+   Copyright (C) 2002 by Brad Hards <[EMAIL PROTECTED]>
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 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 General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+/* This file implements the service registration functionality */
+
+/* Basically, it uses normal Service Location Protocol API */
+
+#include "rsync.h"
+#include "slp.h"
+
+/* this is the minimum we'll use, irrespective of config setting */
+/* definately don't set to less than about 30 seconds */
+#define SLP_MIN_TIMEOUT 120
+
+extern int rsync_port;
+
+void slp_callback(SLPHandle hslp, SLPError errcode, void* cookie) 
+{ 
+	/* return the error code in the cookie */ 
+	*(SLPError*)cookie = errcode; 
+	/* shut up compiler */
+	hslp = hslp;
+
+	/* You could do something else here like print out  */ 
+	/* the errcode, etc.  Remember, as a general rule,  */ 
+	/* do not try to do too much in a callback because  */ 
+	/* it is being executed by the same thread that is  */ 
+	/* reading slp packets from the wire.               */ 
+}
+
+void do_refresh()
+{
+	rprintf(FINFO, "Service registration almost expired, refreshing it\n");
+	register_services();
+}
+
+
+int register_services(void)
+{
+	SLPError err, callbackerr;
+	SLPHandle hslp;
+	int n;
+	int i;
+	char srv[120];
+	char attr[120];
+	char localhost[40];
+	char localdomain[40];
+	extern char *config_file;
+	short timeout;
+	struct sigaction act, oact;
+
+	if (!lp_load(config_file, 0)) {
+		exit_cleanup(RERR_SYNTAX);
+	}
+
+	n = lp_numservices();
+
+	if (0 == lp_slp_refresh())
+		timeout = SLP_LIFETIME_MAXIMUM; /* don't expire, ever */
+	else if (SLP_MIN_TIMEOUT > lp_slp_refresh()) 
+		timeout = SLP_MIN_TIMEOUT; /* use a reasonable minimum */
+	else if (SLP_LIFETIME_MAXIMUM <= lp_slp_refresh())
+		timeout = (SLP_LIFETIME_MAXIMUM - 1); /* as long as possible */
+	else
+		timeout = lp_slp_refresh();
+
+	rprintf(FINFO, "rsyncd registering %d service%s with slpd for %d seconds:\n", n, ((n==1)? "":"s"), timeout);
+	err = SLPOpen("en",SLP_FALSE,&hslp); 
+	if(err != SLP_OK) 
+	{ 
+		rprintf(FINFO, "Error opening slp handle %i\n",err); 
+		return err; 
+	}
+
+	if (0 != (err = gethostname(localhost, sizeof(localhost)))) {
+		rprintf(FINFO, "Could not get hostname: %s\n", strerror(err));
+		return err;
+	}
+	if (0 != (err = getdomainname(localdomain, sizeof(localdomain)))) {
+		rprintf(FINFO, "Could not get domain name: %s\n", strerror(err));
+		return err;
+	}
+	if (0 == strcmp(localhost, "(none)")) {
+		rprintf(FINFO, "Hostname is not set, not registering services\n");
+		return -1;
+	}
+	/* if multicast DNS ever takes off, could just register hostname in local.arpa */
+	if (0 == strcmp(localdomain, "(none)")) {
+		rprintf(FINFO, "Domain name is not set, not registering services\n");
+		return -1;
+	}
+		   
+	/* Register each service with SLP */ 
+	for (i=0;i<n;i++)
+		if (lp_list(i)) {
+			snprintf(srv, sizeof(srv), "service:rsync://%s.%s:%d:/%s",
+				 localhost,
+				 localdomain,
+				 rsync_port,
+				 lp_name(i));
+			rprintf(FINFO, "    %s\n", srv);
+			if (lp_comment(i)) 
+				snprintf(attr, sizeof(attr), "(comment=%s)",
+					 lp_comment(i));
+			err = SLPReg( hslp, 
+				      srv, /* service to register */
+				      timeout,
+				      0,  /* this is ignored */
+				      attr, /* attributes */
+				      SLP_TRUE, /* new registration - don't change this */
+				      slp_callback, /* callback */
+				      &callbackerr );
+
+			/* err may contain an error code that occurred as the slp library    */ 
+			/* _prepared_ to make the call.                                     */ 
+			if(( err != SLP_OK) || (callbackerr != SLP_OK)) 
+				rprintf(FINFO, "Error registering service with slp %i\n",err); 
+
+			/* callbackerr may contain an error code (that was assigned through */ 
+			/* the callback cookie) that occurred as slp packets were sent on    */ 
+			/* the wire */ 
+			if( callbackerr != SLP_OK) 
+				rprintf(FINFO, "Error registering service with slp %i\n",callbackerr); 
+		} 
+
+	/* Now that we're done using slp, close the slp handle */ 
+	SLPClose(hslp);
+
+	/* set up a timer to refresh the service records */
+	act.sa_handler = do_refresh;
+	if (0 != sigaction(SIGALRM, &act, &oact))
+		rprintf(FINFO, "Error establishing signal handler\n");
+
+	alarm(timeout - 15);
+
+	return 0;
+}

Reply via email to