diff options
Diffstat (limited to 'contrib/cvs/src/server.c')
-rw-r--r-- | contrib/cvs/src/server.c | 190 |
1 files changed, 131 insertions, 59 deletions
diff --git a/contrib/cvs/src/server.c b/contrib/cvs/src/server.c index 9a0c132..00852e9 100644 --- a/contrib/cvs/src/server.c +++ b/contrib/cvs/src/server.c @@ -8,6 +8,10 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ +/* + * $FreeBSD$ + */ + #include <assert.h> #include "cvs.h" #include "watch.h" @@ -710,7 +714,17 @@ serve_valid_responses (arg) cause deadlock, as noted in server_cleanup. */ buf_flush (buf_to_net, 1); - error_exit (); + /* I'm doing this manually rather than via error_exit () + because I'm not sure whether we want to call server_cleanup. + Needs more investigation.... */ + +#ifdef SYSTEM_CLEANUP + /* Hook for OS-specific behavior, for example socket subsystems on + NT and OS2 or dealing with windows and arguments on Mac. */ + SYSTEM_CLEANUP (); +#endif + + exit (EXIT_FAILURE); } else if (rs->status == rs_optional) rs->status = rs_not_supported; @@ -772,6 +786,9 @@ E Protocol error: Root says \"%s\" but pserver says \"%s\"", nothing. But for rsh, we need to do it now. */ parse_config (current_parsed_root->directory); + /* Now is a good time to read CVSROOT/options too. */ + parseopts(current_parsed_root->directory); + path = malloc (strlen (current_parsed_root->directory) + sizeof (CVSROOTADM) + 2); @@ -852,10 +869,7 @@ outside_root (repos) /* I think isabsolute (repos) should always be true, and that any RELATIVE_REPOS stuff should only be in CVS/Repository files, not the protocol (for compatibility), but I'm putting - in the isabsolute check just in case. - - This is a good security precaution regardless. -DRP - */ + in the isabsolute check just in case. */ if (!isabsolute (repos)) { if (alloc_pending (repos_len + 80)) @@ -2908,10 +2922,10 @@ error \n"); fd_set readfds; fd_set writefds; int numfds; - struct timeval *timeout_ptr; - struct timeval timeout; #ifdef SERVER_FLOWCONTROL int bufmemsize; + struct timeval *timeout_ptr; + struct timeval timeout; /* * See if we are swamping the remote client and filling our VM. @@ -3203,13 +3217,10 @@ E CVS locks may need cleaning up.\n"); buf_flush (buf_to_net, 1); buf_shutdown (protocol_inbuf); buf_free (protocol_inbuf); - protocol_inbuf = NULL; buf_shutdown (stderrbuf); buf_free (stderrbuf); - stderrbuf = NULL; buf_shutdown (stdoutbuf); buf_free (stdoutbuf); - stdoutbuf = NULL; } if (errs) @@ -3708,7 +3719,7 @@ static void serve_watch_on (arg) char *arg; { - do_cvs_command ("watch", watch_on); + do_cvs_command ("watch_on", watch_on); } static void serve_watch_off PROTO ((char *)); @@ -3717,7 +3728,7 @@ static void serve_watch_off (arg) char *arg; { - do_cvs_command ("watch", watch_off); + do_cvs_command ("watch_off", watch_off); } static void serve_watch_add PROTO ((char *)); @@ -3726,7 +3737,7 @@ static void serve_watch_add (arg) char *arg; { - do_cvs_command ("watch", watch_add); + do_cvs_command ("watch_add", watch_add); } static void serve_watch_remove PROTO ((char *)); @@ -3735,7 +3746,7 @@ static void serve_watch_remove (arg) char *arg; { - do_cvs_command ("watch", watch_remove); + do_cvs_command ("watch_remove", watch_remove); } static void serve_watchers PROTO ((char *)); @@ -4884,9 +4895,9 @@ server_cleanup (sig) status = buf_shutdown (buf_from_net); if (status != 0) + { error (0, status, "shutting down buffer from client"); - buf_free (buf_from_net); - buf_from_net = NULL; + } } if (dont_delete_temp) @@ -4895,9 +4906,6 @@ server_cleanup (sig) { (void) buf_flush (buf_to_net, 1); (void) buf_shutdown (buf_to_net); - buf_free (buf_to_net); - buf_to_net = NULL; - error_use_protocol = 0; } return; } @@ -4999,9 +5007,6 @@ server_cleanup (sig) { (void) buf_flush (buf_to_net, 1); (void) buf_shutdown (buf_to_net); - buf_free (buf_to_net); - buf_to_net = NULL; - error_use_protocol = 0; } } @@ -5012,8 +5017,6 @@ server (argc, argv) int argc; char **argv; { - char *error_prog_name; /* Used in error messages */ - if (argc == -1) { static const char *const msg[] = @@ -5070,7 +5073,18 @@ server (argc, argv) printf ("E Fatal server error, aborting.\n\ error ENOMEM Virtual memory exhausted.\n"); - error_exit (); + /* I'm doing this manually rather than via error_exit () + because I'm not sure whether we want to call server_cleanup. + Needs more investigation.... */ + +#ifdef SYSTEM_CLEANUP + /* Hook for OS-specific behavior, for example socket + subsystems on NT and OS2 or dealing with windows + and arguments on Mac. */ + SYSTEM_CLEANUP (); +#endif + + exit (EXIT_FAILURE); } strcpy (server_temp_dir, Tmpdir); @@ -5134,23 +5148,63 @@ error ENOMEM Virtual memory exhausted.\n"); } } +#ifdef SIGABRT + (void) SIG_register (SIGABRT, server_cleanup); +#endif +#ifdef SIGHUP + (void) SIG_register (SIGHUP, server_cleanup); +#endif +#ifdef SIGINT + (void) SIG_register (SIGINT, server_cleanup); +#endif +#ifdef SIGQUIT + (void) SIG_register (SIGQUIT, server_cleanup); +#endif +#ifdef SIGPIPE + (void) SIG_register (SIGPIPE, server_cleanup); +#endif +#ifdef SIGTERM + (void) SIG_register (SIGTERM, server_cleanup); +#endif + /* Now initialize our argument vector (for arguments from the client). */ /* Small for testing. */ argument_vector_size = 1; argument_vector = - (char **) xmalloc (argument_vector_size * sizeof (char *)); + (char **) malloc (argument_vector_size * sizeof (char *)); + if (argument_vector == NULL) + { + /* + * Strictly speaking, we're not supposed to output anything + * now. But we're about to exit(), give it a try. + */ + printf ("E Fatal server error, aborting.\n\ +error ENOMEM Virtual memory exhausted.\n"); + + /* I'm doing this manually rather than via error_exit () + because I'm not sure whether we want to call server_cleanup. + Needs more investigation.... */ + +#ifdef SYSTEM_CLEANUP + /* Hook for OS-specific behavior, for example socket subsystems on + NT and OS2 or dealing with windows and arguments on Mac. */ + SYSTEM_CLEANUP (); +#endif + + exit (EXIT_FAILURE); + } + argument_count = 1; /* This gets printed if the client supports an option which the server doesn't, causing the server to print a usage message. + FIXME: probably should be using program_name here. FIXME: just a nit, I suppose, but the usage message the server prints isn't literally true--it suggests "cvs server" followed by options which are for a particular command. Might be nice to say something like "client apparently supports an option not supported by this server" or something like that instead of usage message. */ - error_prog_name = xmalloc( strlen(program_name) + 8 ); - sprintf(error_prog_name, "%s server", program_name); - argument_vector[0] = error_prog_name; + argument_vector[0] = "cvs server"; while (1) { @@ -5223,7 +5277,6 @@ error ENOMEM Virtual memory exhausted.\n"); } free (orig_cmd); } - free(error_prog_name); server_cleanup (0); return 0; } @@ -5373,8 +5426,8 @@ check_repository_password (username, password, repository, host_user_ptr) int found_it = 0; int namelen; - /* We don't use current_parsed_root->directory because it hasn't been - * set yet -- our `repository' argument came from the authentication + /* We don't use current_parsed_root->directory because it hasn't been set yet + * -- our `repository' argument came from the authentication * protocol, not the regular CVS protocol. */ @@ -5515,7 +5568,10 @@ check_password (username, password, repository) password file. If so, that's enough to authenticate with. If not, we'll check /etc/passwd. */ - rc = check_repository_password (username, password, repository, + if (require_real_user) + rc = 0; /* "not found" */ + else + rc = check_repository_password (username, password, repository, &host_user); if (rc == 2) @@ -5532,7 +5588,7 @@ check_password (username, password, repository) { /* No cvs password found, so try /etc/passwd. */ - char *found_passwd = NULL; + const char *found_passwd = NULL; struct passwd *pw; #ifdef HAVE_GETSPNAM struct spwd *spw; @@ -5554,23 +5610,18 @@ check_password (username, password, repository) printf ("E Fatal error, aborting.\n\ error 0 %s: no such user\n", username); - error_exit (); - } + /* I'm doing this manually rather than via error_exit () + because I'm not sure whether we want to call server_cleanup. + Needs more investigation.... */ - /* Allow for dain bramaged HPUX passwd aging - * - Basically, HPUX adds a comma and some data - * about whether the passwd has expired or not - * on the end of the passwd field. - * - This code replaces the ',' with '\0'. - * - * FIXME - our workaround is brain damaged too. I'm - * guessing that HPUX WANTED other systems to think the - * password was wrong so logins would fail if the - * system didn't handle expired passwds and the passwd - * might be expired. I think the way to go here - * is with PAM. - */ - strtok (found_passwd, ","); +#ifdef SYSTEM_CLEANUP + /* Hook for OS-specific behavior, for example socket subsystems on + NT and OS2 or dealing with windows and arguments on Mac. */ + SYSTEM_CLEANUP (); +#endif + + exit (EXIT_FAILURE); + } if (*found_passwd) { @@ -5604,7 +5655,16 @@ error 0 %s: no such user\n", username); outweighs this. */ printf ("error 0 no such user %s in CVSROOT/passwd\n", username); - error_exit (); + /* I'm doing this manually rather than via error_exit () + because I'm not sure whether we want to call server_cleanup. + Needs more investigation.... */ + +#ifdef SYSTEM_CLEANUP + /* Hook for OS-specific behavior, for example socket subsystems on + NT and OS2 or dealing with windows and arguments on Mac. */ + SYSTEM_CLEANUP (); +#endif + exit (EXIT_FAILURE); } else { @@ -5861,8 +5921,12 @@ kserver_authenticate_connection () { printf ("E Fatal error, aborting.\n\ error %s getpeername or getsockname failed\n", strerror (errno)); - - error_exit (); +#ifdef SYSTEM_CLEANUP + /* Hook for OS-specific behavior, for example socket subsystems on + NT and OS2 or dealing with windows and arguments on Mac. */ + SYSTEM_CLEANUP (); +#endif + exit (EXIT_FAILURE); } #ifdef SO_KEEPALIVE @@ -5888,8 +5952,12 @@ error %s getpeername or getsockname failed\n", strerror (errno)); { printf ("E Fatal error, aborting.\n\ error 0 kerberos: %s\n", krb_get_err_text(status)); - - error_exit (); +#ifdef SYSTEM_CLEANUP + /* Hook for OS-specific behavior, for example socket subsystems on + NT and OS2 or dealing with windows and arguments on Mac. */ + SYSTEM_CLEANUP (); +#endif + exit (EXIT_FAILURE); } memcpy (kblock, auth.session, sizeof (C_Block)); @@ -5900,8 +5968,12 @@ error 0 kerberos: %s\n", krb_get_err_text(status)); { printf ("E Fatal error, aborting.\n\ error 0 kerberos: can't get local name: %s\n", krb_get_err_text(status)); - - error_exit (); +#ifdef SYSTEM_CLEANUP + /* Hook for OS-specific behavior, for example socket subsystems on + NT and OS2 or dealing with windows and arguments on Mac. */ + SYSTEM_CLEANUP (); +#endif + exit (EXIT_FAILURE); } /* Switch to run as this user. */ @@ -6290,12 +6362,12 @@ cvs_output (str, len) if (len == 0) len = strlen (str); #ifdef SERVER_SUPPORT - if (error_use_protocol && buf_to_net != NULL) + if (error_use_protocol) { buf_output (saved_output, str, len); buf_copy_lines (buf_to_net, saved_output, 'M'); } - else if (server_active && protocol != NULL) + else if (server_active) { buf_output (saved_output, str, len); buf_copy_lines (protocol, saved_output, 'M'); |