From 31593dd6106cfef78fc88cbe9c831a51f00a4aa6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 13 May 1998 09:38:54 +0000 Subject: [PATCH 1/1] improved max connections code. Now use fcntl instead of flock. also started on authentication code (I'm doing a challenge response system initially) --- authenticate.c | 21 +++++++++++++ clientserver.c | 19 +++++++++++- connection.c | 81 ++------------------------------------------------ loadparm.c | 14 +++++++-- util.c | 16 ++++++---- 5 files changed, 62 insertions(+), 89 deletions(-) create mode 100644 authenticate.c diff --git a/authenticate.c b/authenticate.c new file mode 100644 index 00000000..28f777e1 --- /dev/null +++ b/authenticate.c @@ -0,0 +1,21 @@ +/* + Copyright (C) Andrew Tridgell 1998 + + 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. +*/ + +/* support rsync authentication */ +#include "rsync.h" + diff --git a/clientserver.c b/clientserver.c index 39e5b90d..173ca0c5 100644 --- a/clientserver.c +++ b/clientserver.c @@ -67,6 +67,14 @@ int start_socket_client(char *host, char *path, int argc, char *argv[]) if (!read_line(fd, line, sizeof(line)-1)) { return -1; } + +#if 0 + if (strncmp(line,"@RSYNCD: AUTHREQD ",18) == 0) { + auth_client(fd, line+18); + continue; + } +#endif + if (strcmp(line,"@RSYNCD: OK") == 0) break; rprintf(FINFO,"%s\n", line); } @@ -101,6 +109,7 @@ static int rsync_module(int fd, int i) char *p; char *addr = client_addr(fd); char *host = client_name(fd); + char *auth; if (!allow_access(addr, host, lp_hosts_allow(i), lp_hosts_deny(i))) { rprintf(FERROR,"rsync denied on module %s from %s (%s)\n", @@ -108,6 +117,14 @@ static int rsync_module(int fd, int i) return -1; } +#if 0 + if (!auth_server(fd, "@RSYNCD: AUTHREQD ")) { + rprintf(FERROR,"auth failed on module %s from %s (%s)\n", + lp_name(i), client_name(fd), client_addr(fd)); + return -1; + } +#endif + if (!claim_connection(lp_lock_file(), lp_max_connections())) { rprintf(FERROR,"ERROR: max connections reached\n"); return -1; @@ -115,7 +132,7 @@ static int rsync_module(int fd, int i) rprintf(FINFO,"rsync on module %s from %s (%s)\n", lp_name(i), host, addr); - + module_id = i; if (lp_read_only(i)) diff --git a/connection.c b/connection.c index fc7c6667..1025c8fc 100644 --- a/connection.c +++ b/connection.c @@ -19,59 +19,6 @@ /* support the max connections option */ #include "rsync.h" -int yield_connection(char *fname, int max_connections) -{ - int fd, i; - pid_t mypid=getpid(), pid=0; - - if (max_connections <= 0) - return 1; - - fd = open(fname,O_RDWR); - if (fd == -1) { - rprintf(FERROR,"Couldn't open lock file %s (%s)\n",fname,strerror(errno)); - return 0; - } - - if (!lock_file(fd)) { - rprintf(FERROR,"failed to lock %s\n", fname); - close(fd); - return 0; - } - - /* find the right spot */ - for (i=0;i