1 /* CVS client-related stuff.
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details. */
15 #endif /* HAVE_CONFIG_H */
27 #if defined(AUTH_CLIENT_SUPPORT) || HAVE_KERBEROS || defined(SOCK_ERRNO) || defined(SOCK_STRERROR)
28 # ifdef HAVE_WINSOCK_H
30 # else /* No winsock.h */
31 # include <sys/socket.h>
32 # include <netinet/in.h>
34 # endif /* No winsock.h */
37 /* If SOCK_ERRNO is defined, then send()/recv() and other socket calls
38 do not set errno, but that this macro should be used to obtain an
39 error code. This probably doesn't make sense unless
40 NO_SOCKET_TO_FD is also defined. */
42 #define SOCK_ERRNO errno
45 /* If SOCK_STRERROR is defined, then the error codes returned by
46 socket operations are not known to strerror, and this macro must be
47 used instead to convert those error codes to strings. */
49 # define SOCK_STRERROR strerror
56 extern char *strerror ();
58 #endif /* ! SOCK_STRERROR */
66 extern char *krb_realmofhost ();
67 #ifndef HAVE_KRB_GET_ERR_TEXT
68 #define krb_get_err_text(status) krb_err_txt[status]
69 #endif /* HAVE_KRB_GET_ERR_TEXT */
71 /* Information we need if we are going to use Kerberos encryption. */
72 static C_Block kblock;
73 static Key_schedule sched;
75 #endif /* HAVE_KERBEROS */
77 #endif /* HAVE_KERBEROS */
81 #include <gssapi/gssapi.h>
82 #include <gssapi/gssapi_generic.h>
84 /* This is needed for GSSAPI encryption. */
85 static gss_ctx_id_t gcontext;
87 static int connect_to_gserver PROTO((int, struct hostent *));
89 #endif /* HAVE_GSSAPI */
91 static void add_prune_candidate PROTO((char *));
93 /* All the commands. */
94 int add PROTO((int argc, char **argv));
95 int admin PROTO((int argc, char **argv));
96 int checkout PROTO((int argc, char **argv));
97 int commit PROTO((int argc, char **argv));
98 int diff PROTO((int argc, char **argv));
99 int history PROTO((int argc, char **argv));
100 int import PROTO((int argc, char **argv));
101 int cvslog PROTO((int argc, char **argv));
102 int patch PROTO((int argc, char **argv));
103 int release PROTO((int argc, char **argv));
104 int cvsremove PROTO((int argc, char **argv));
105 int rtag PROTO((int argc, char **argv));
106 int status PROTO((int argc, char **argv));
107 int tag PROTO((int argc, char **argv));
108 int update PROTO((int argc, char **argv));
110 /* All the response handling functions. */
111 static void handle_ok PROTO((char *, int));
112 static void handle_error PROTO((char *, int));
113 static void handle_valid_requests PROTO((char *, int));
114 static void handle_checked_in PROTO((char *, int));
115 static void handle_new_entry PROTO((char *, int));
116 static void handle_checksum PROTO((char *, int));
117 static void handle_copy_file PROTO((char *, int));
118 static void handle_updated PROTO((char *, int));
119 static void handle_merged PROTO((char *, int));
120 static void handle_patched PROTO((char *, int));
121 static void handle_rcs_diff PROTO((char *, int));
122 static void handle_removed PROTO((char *, int));
123 static void handle_remove_entry PROTO((char *, int));
124 static void handle_set_static_directory PROTO((char *, int));
125 static void handle_clear_static_directory PROTO((char *, int));
126 static void handle_set_sticky PROTO((char *, int));
127 static void handle_clear_sticky PROTO((char *, int));
128 static void handle_set_checkin_prog PROTO((char *, int));
129 static void handle_set_update_prog PROTO((char *, int));
130 static void handle_module_expansion PROTO((char *, int));
131 static void handle_m PROTO((char *, int));
132 static void handle_e PROTO((char *, int));
133 static void handle_f PROTO((char *, int));
134 static void handle_notified PROTO((char *, int));
136 static void buf_memory_error PROTO((struct buffer *));
137 static size_t try_read_from_server PROTO ((char *, size_t));
138 #endif /* CLIENT_SUPPORT */
140 #if defined(CLIENT_SUPPORT) || defined(SERVER_SUPPORT)
142 /* Shared with server. */
145 * Return a malloc'd, '\0'-terminated string
146 * corresponding to the mode in SB.
150 mode_to_string (mode_t mode)
151 #else /* ! __STDC__ */
152 mode_to_string (mode)
154 #endif /* __STDC__ */
156 char buf[18], u[4], g[4], o[4];
160 if (mode & S_IRUSR) u[i++] = 'r';
161 if (mode & S_IWUSR) u[i++] = 'w';
162 if (mode & S_IXUSR) u[i++] = 'x';
166 if (mode & S_IRGRP) g[i++] = 'r';
167 if (mode & S_IWGRP) g[i++] = 'w';
168 if (mode & S_IXGRP) g[i++] = 'x';
172 if (mode & S_IROTH) o[i++] = 'r';
173 if (mode & S_IWOTH) o[i++] = 'w';
174 if (mode & S_IXOTH) o[i++] = 'x';
177 sprintf(buf, "u=%s,g=%s,o=%s", u, g, o);
182 * Change mode of FILENAME to MODE_STRING.
183 * Returns 0 for success or errno code.
186 change_mode (filename, mode_string)
194 /* We can only distinguish between
197 3) Picasso's "Blue Period"
198 We handle the first two. */
202 if ((p[0] == 'u' || p[0] == 'g' || p[0] == 'o') && p[1] == '=')
205 while (*q != ',' && *q != '\0')
212 /* Skip to the next field. */
213 while (*p != ',' && *p != '\0')
219 xchmod (filename, writeable);
222 #else /* ! CHMOD_BROKEN */
230 if ((p[0] == 'u' || p[0] == 'g' || p[0] == 'o') && p[1] == '=')
232 int can_read = 0, can_write = 0, can_execute = 0;
234 while (*q != ',' && *q != '\0')
253 else if (p[0] == 'g')
262 else if (p[0] == 'o')
272 /* Skip to the next field. */
273 while (*p != ',' && *p != '\0')
279 if (chmod (filename, mode) < 0)
282 #endif /* ! CHMOD_BROKEN */
285 #endif /* CLIENT_SUPPORT or SERVER_SUPPORT */
287 #ifdef CLIENT_SUPPORT
289 int client_prune_dirs;
291 static List *ignlist = (List *) NULL;
293 /* Buffer to write to the server. */
294 static struct buffer *to_server;
295 /* The stream underlying to_server, if we are using a stream. */
296 static FILE *to_server_fp;
298 /* Buffer used to read from the server. */
299 static struct buffer *from_server;
300 /* The stream underlying from_server, if we are using a stream. */
301 static FILE *from_server_fp;
303 /* Process ID of rsh subprocess. */
304 static int rsh_pid = -1;
307 /* This routine is called when one of the buffer routines runs out of
311 buf_memory_error (buf)
314 error (1, 0, "out of memory");
317 /* We want to be able to log data sent between us and the server. We
318 do it using log buffers. Each log buffer has another buffer which
319 handles the actual I/O, and a file to log information to.
321 This structure is the closure field of a log buffer. */
325 /* The underlying buffer. */
327 /* The file to log information to. */
331 static struct buffer *log_buffer_initialize
332 PROTO((struct buffer *, FILE *, int, void (*) (struct buffer *)));
333 static int log_buffer_input PROTO((void *, char *, int, int, int *));
334 static int log_buffer_output PROTO((void *, const char *, int, int *));
335 static int log_buffer_flush PROTO((void *));
336 static int log_buffer_block PROTO((void *, int));
337 static int log_buffer_shutdown PROTO((void *));
339 /* Create a log buffer. */
341 static struct buffer *
342 log_buffer_initialize (buf, fp, input, memory)
346 void (*memory) PROTO((struct buffer *));
348 struct log_buffer *n;
350 n = (struct log_buffer *) xmalloc (sizeof *n);
353 return buf_initialize (input ? log_buffer_input : NULL,
354 input ? NULL : log_buffer_output,
355 input ? NULL : log_buffer_flush,
362 /* The input function for a log buffer. */
365 log_buffer_input (closure, data, need, size, got)
372 struct log_buffer *lb = (struct log_buffer *) closure;
376 if (lb->buf->input == NULL)
379 status = (*lb->buf->input) (lb->buf->closure, data, need, size, got);
386 if (fwrite (data, 1, n_to_write, lb->log) != n_to_write)
387 error (0, errno, "writing to log file");
393 /* The output function for a log buffer. */
396 log_buffer_output (closure, data, have, wrote)
402 struct log_buffer *lb = (struct log_buffer *) closure;
406 if (lb->buf->output == NULL)
409 status = (*lb->buf->output) (lb->buf->closure, data, have, wrote);
416 if (fwrite (data, 1, n_to_write, lb->log) != n_to_write)
417 error (0, errno, "writing to log file");
423 /* The flush function for a log buffer. */
426 log_buffer_flush (closure)
429 struct log_buffer *lb = (struct log_buffer *) closure;
431 if (lb->buf->flush == NULL)
434 /* We don't really have to flush the log file here, but doing it
435 will let tail -f on the log file show what is sent to the
436 network as it is sent. */
437 if (fflush (lb->log) != 0)
438 error (0, errno, "flushing log file");
440 return (*lb->buf->flush) (lb->buf->closure);
443 /* The block function for a log buffer. */
446 log_buffer_block (closure, block)
450 struct log_buffer *lb = (struct log_buffer *) closure;
453 return set_block (lb->buf);
455 return set_nonblock (lb->buf);
458 /* The shutdown function for a log buffer. */
461 log_buffer_shutdown (closure)
464 struct log_buffer *lb = (struct log_buffer *) closure;
467 retval = buf_shutdown (lb->buf);
468 if (fclose (lb->log) < 0)
469 error (0, errno, "closing log file");
473 #ifdef NO_SOCKET_TO_FD
475 /* Under certain circumstances, we must communicate with the server
476 via a socket using send() and recv(). This is because under some
477 operating systems (OS/2 and Windows 95 come to mind), a socket
478 cannot be converted to a file descriptor -- it must be treated as a
479 socket and nothing else.
481 We may also need to deal with socket routine error codes differently
482 in these cases. This is handled through the SOCK_ERRNO and
483 SOCK_STRERROR macros. */
485 static int use_socket_style = 0;
486 static int server_sock;
488 /* These routines implement a buffer structure which uses send and
489 recv. The buffer is always in blocking mode so we don't implement
490 the block routine. */
492 /* Note that it is important that these routines always handle errors
493 internally and never return a positive errno code, since it would in
494 general be impossible for the caller to know in general whether any
495 error code came from a socket routine (to decide whether to use
496 SOCK_STRERROR or simply strerror to print an error message). */
498 /* We use an instance of this structure as the closure field. */
502 /* The socket number. */
506 static struct buffer *socket_buffer_initialize
507 PROTO ((int, int, void (*) (struct buffer *)));
508 static int socket_buffer_input PROTO((void *, char *, int, int, int *));
509 static int socket_buffer_output PROTO((void *, const char *, int, int *));
510 static int socket_buffer_flush PROTO((void *));
512 /* Create a buffer based on a socket. */
514 static struct buffer *
515 socket_buffer_initialize (socket, input, memory)
518 void (*memory) PROTO((struct buffer *));
520 struct socket_buffer *n;
522 n = (struct socket_buffer *) xmalloc (sizeof *n);
524 return buf_initialize (input ? socket_buffer_input : NULL,
525 input ? NULL : socket_buffer_output,
526 input ? NULL : socket_buffer_flush,
527 (int (*) PROTO((void *, int))) NULL,
528 (int (*) PROTO((void *))) NULL,
533 /* The buffer input function for a buffer built on a socket. */
536 socket_buffer_input (closure, data, need, size, got)
543 struct socket_buffer *sb = (struct socket_buffer *) closure;
546 /* I believe that the recv function gives us exactly the semantics
547 we want. If there is a message, it returns immediately with
548 whatever it could get. If there is no message, it waits until
549 one comes in. In other words, it is not like read, which in
550 blocking mode normally waits until all the requested data is
558 /* Note that for certain (broken?) networking stacks, like
559 VMS's UCX (not sure what version, problem reported with
560 recv() in 1997), and (according to windows-NT/config.h)
561 Windows NT 3.51, we must call recv or send with a
562 moderately sized buffer (say, less than 200K or something),
563 or else there may be network errors (somewhat hard to
564 produce, e.g. WAN not LAN or some such). buf_read_data
565 makes sure that we only recv() BUFFER_DATA_SIZE bytes at
568 nbytes = recv (sb->socket, data, size, 0);
570 error (1, 0, "reading from server: %s", SOCK_STRERROR (SOCK_ERRNO));
573 /* End of file (for example, the server has closed
574 the connection). If we've already read something, we
575 just tell the caller about the data, not about the end of
576 file. If we've read nothing, we return end of file. */
592 /* The buffer output function for a buffer built on a socket. */
595 socket_buffer_output (closure, data, have, wrote)
601 struct socket_buffer *sb = (struct socket_buffer *) closure;
605 /* See comment in socket_buffer_input regarding buffer size we pass
608 #ifdef SEND_NEVER_PARTIAL
609 /* If send() never will produce a partial write, then just do it. This
610 is needed for systems where its return value is something other than
611 the number of bytes written. */
612 if (send (sb->socket, data, have, 0) < 0)
613 error (1, 0, "writing to server socket: %s", SOCK_STRERROR (SOCK_ERRNO));
619 nbytes = send (sb->socket, data, have, 0);
621 error (1, 0, "writing to server socket: %s", SOCK_STRERROR (SOCK_ERRNO));
631 /* The buffer flush function for a buffer built on a socket. */
635 socket_buffer_flush (closure)
638 /* Nothing to do. Sockets are always flushed. */
642 #endif /* NO_SOCKET_TO_FD */
645 * Read a line from the server. Result does not include the terminating \n.
647 * Space for the result is malloc'd and should be freed by the caller.
649 * Returns number of bytes read.
659 status = buf_flush (to_server, 1);
661 error (1, status, "writing to server");
663 status = buf_read_line (from_server, &result, &len);
667 error (1, 0, "end of file from server (consult above messages if any)");
668 else if (status == -2)
669 error (1, 0, "out of memory");
671 error (1, status, "reading from server");
682 #endif /* CLIENT_SUPPORT */
685 #if defined(CLIENT_SUPPORT) || defined(SERVER_SUPPORT)
688 * Zero if compression isn't supported or requested; non-zero to indicate
689 * a compression level to request from gzip.
694 * Level of compression to use when running gzip on a single file.
698 int filter_through_gzip (fd, dir, level, pidp)
702 static char buf[5] = "-";
703 static char *gzip_argv[3] = { "gzip", buf };
705 sprintf (buf+1, "%d", level);
706 return filter_stream_through_program (fd, dir, &gzip_argv[0], pidp);
709 int filter_through_gunzip (fd, dir, pidp)
713 static char *gunzip_argv[3] = { "gzip", "-d" };
714 return filter_stream_through_program (fd, dir, &gunzip_argv[0], pidp);
717 #endif /* CLIENT_SUPPORT or SERVER_SUPPORT */
719 #ifdef CLIENT_SUPPORT
722 * The Repository for the top level of this command (not necessarily
723 * the CVSROOT, just the current directory at the time we do it).
725 static char *toplevel_repos;
727 /* Working directory when we first started. Note: we could speed things
728 up on some systems by using savecwd.h here instead of just always
733 handle_ok (args, len)
741 handle_error (args, len)
745 int something_printed;
748 * First there is a symbolic error code followed by a space, which
751 char *p = strchr (args, ' ');
754 error (0, 0, "invalid data from cvs server");
759 something_printed = 0;
760 for (; len > 0; --len)
762 something_printed = 1;
765 if (something_printed)
770 handle_valid_requests (args, len)
782 for (rq = requests; rq->name != NULL; ++rq)
784 if (strcmp (rq->name, p) == 0)
787 if (rq->name == NULL)
789 * It is a request we have never heard of (and thus never
790 * will want to use). So don't worry about it.
795 if (rq->status == rq_enableme)
798 * Server wants to know if we have this, to enable the
801 send_to_server (rq->name, 0);
802 send_to_server ("\012", 0);
805 rq->status = rq_supported;
809 for (rq = requests; rq->name != NULL; ++rq)
811 if (rq->status == rq_essential)
812 error (1, 0, "request `%s' not supported by server", rq->name);
813 else if (rq->status == rq_optional)
814 rq->status = rq_not_supported;
818 /* This variable holds the result of Entries_Open, so that we can
819 close Entries_Close on it when we move on to a new directory, or
821 static List *last_entries;
824 * Do all the processing for PATHNAME, where pathname consists of the
825 * repository and the filename. The parameters we pass to FUNC are:
826 * DATA is just the DATA parameter which was passed to
827 * call_in_directory; ENT_LIST is a pointer to an entries list (which
828 * we manage the storage for); SHORT_PATHNAME is the pathname of the
829 * file relative to the (overall) directory in which the command is
830 * taking place; and FILENAME is the filename portion only of
831 * SHORT_PATHNAME. When we call FUNC, the curent directory points to
832 * the directory portion of SHORT_PATHNAME. */
834 static char *last_dir_name;
837 call_in_directory (pathname, func, data)
839 void (*func) PROTO((char *data, List *ent_list, char *short_pathname,
845 /* This is what we get when we hook up the directory (working directory
846 name) from PATHNAME with the filename from REPOSNAME. For example:
848 reposname: /u/src/master/ccvs/foo/ChangeLog
849 short_pathname: ccvs/src/ChangeLog
851 char *short_pathname;
855 * Do the whole descent in parallel for the repositories, so we
856 * know what to put in CVS/Repository files. I'm not sure the
857 * full hair is necessary since the server does a similar
858 * computation; I suspect that we only end up creating one
859 * directory at a time anyway.
861 * Also note that we must *only* worry about this stuff when we
862 * are creating directories; `cvs co foo/bar; cd foo/bar; cvs co
863 * CVSROOT; cvs update' is legitimate, but in this case
864 * foo/bar/CVSROOT/CVS/Repository is not a subdirectory of
865 * foo/bar/CVS/Repository.
871 int reposdirname_absolute;
874 read_line (&reposname);
875 assert (reposname != NULL);
877 reposdirname_absolute = 0;
878 if (strncmp (reposname, toplevel_repos, strlen (toplevel_repos)) != 0)
880 reposdirname_absolute = 1;
881 short_repos = reposname;
885 short_repos = reposname + strlen (toplevel_repos) + 1;
886 if (short_repos[-1] != '/')
888 reposdirname_absolute = 1;
889 short_repos = reposname;
892 reposdirname = xstrdup (short_repos);
893 p = strrchr (reposdirname, '/');
896 reposdirname = xrealloc (reposdirname, 2);
897 reposdirname[0] = '.'; reposdirname[1] = '\0';
902 dir_name = xstrdup (pathname);
903 p = strrchr (dir_name, '/');
906 dir_name = xrealloc (dir_name, 2);
907 dir_name[0] = '.'; dir_name[1] = '\0';
911 if (client_prune_dirs)
912 add_prune_candidate (dir_name);
914 filename = strrchr (short_repos, '/');
915 if (filename == NULL)
916 filename = short_repos;
920 short_pathname = xmalloc (strlen (pathname) + strlen (filename) + 5);
921 strcpy (short_pathname, pathname);
922 strcat (short_pathname, filename);
924 if (last_dir_name == NULL
925 || strcmp (last_dir_name, dir_name) != 0)
929 if (strcmp (command_name, "export") != 0)
931 Entries_Close (last_entries);
934 free (last_dir_name);
935 last_dir_name = dir_name;
937 if (toplevel_wd == NULL)
939 toplevel_wd = xgetwd ();
940 if (toplevel_wd == NULL)
941 error (1, errno, "could not get working directory");
944 if (CVS_CHDIR (toplevel_wd) < 0)
945 error (1, errno, "could not chdir to %s", toplevel_wd);
948 /* Create the CVS directory at the top level if needed.
949 The isdir seems like an unneeded system call, but it *does*
950 need to be called both if the CVS_CHDIR below succeeds (e.g.
951 "cvs co .") or if it fails (e.g. basicb-1a in testsuite). */
952 if (/* I think the reposdirname_absolute case has to do with
953 things like "cvs update /foo/bar". In any event, the
954 code below which tries to put toplevel_repos into
955 CVS/Repository is almost surely unsuited to
956 the reposdirname_absolute case. */
957 !reposdirname_absolute
966 repo = xmalloc (strlen (toplevel_repos)
968 strcpy (repo, toplevel_repos);
969 r = repo + strlen (repo);
970 if (r[-1] != '.' || r[-2] != '/')
973 Create_Admin (".", ".", repo, (char *) NULL,
974 (char *) NULL, 0, 1);
979 if ( CVS_CHDIR (dir_name) < 0)
984 if (! existence_error (errno))
985 error (1, errno, "could not chdir to %s", dir_name);
987 /* Directory does not exist, we need to create it. */
990 /* Provided we are willing to assume that directories get
991 created one at a time, we could simplify this a lot.
992 Do note that one aspect still would need to walk the
993 dir_name path: the checking for "fncmp (dir, CVSADM)". */
995 dir = xmalloc (strlen (dir_name) + 1);
997 rdirp = reposdirname;
999 /* This algorithm makes nested directories one at a time
1000 and create CVS administration files in them. For
1001 example, we're checking out foo/bar/baz from the
1004 1) create foo, point CVS/Repository to <root>/foo
1005 2) .. foo/bar .. <root>/foo/bar
1006 3) .. foo/bar/baz .. <root>/foo/bar/baz
1008 As you can see, we're just stepping along DIR_NAME (with
1009 DIRP) and REPOSDIRNAME (with RDIRP) respectively.
1011 We need to be careful when we are checking out a
1012 module, however, since DIR_NAME and REPOSDIRNAME are not
1013 going to be the same. Since modules will not have any
1014 slashes in their names, we should watch the output of
1015 STRCHR to decide whether or not we should use STRCHR on
1016 the RDIRP. That is, if we're down to a module name,
1017 don't keep picking apart the repository directory name. */
1021 dirp = strchr (dirp, '/');
1024 strncpy (dir, dir_name, dirp - dir_name);
1025 dir[dirp - dir_name] = '\0';
1026 /* Skip the slash. */
1029 /* This just means that the repository string has
1030 fewer components than the dir_name string. But
1031 that is OK (e.g. see modules3-8 in testsuite). */
1034 rdirp = strchr (rdirp, '/');
1038 /* If there are no more slashes in the dir name,
1039 we're down to the most nested directory -OR- to
1040 the name of a module. In the first case, we
1041 should be down to a DIRP that has no slashes,
1042 so it won't help/hurt to do another STRCHR call
1043 on DIRP. It will definitely hurt, however, if
1044 we're down to a module name, since a module
1045 name can point to a nested directory (that is,
1046 DIRP will still have slashes in it. Therefore,
1047 we should set it to NULL so the routine below
1048 copies the contents of REMOTEDIRNAME onto the
1049 root repository directory (does this if rdirp
1050 is set to NULL, because we used to do an extra
1051 STRCHR call here). */
1054 strcpy (dir, dir_name);
1057 if (fncmp (dir, CVSADM) == 0)
1059 error (0, 0, "cannot create a directory named %s", dir);
1060 error (0, 0, "because CVS uses \"%s\" for its own uses",
1062 error (1, 0, "rename the directory and try again");
1065 if (mkdir_if_needed (dir))
1067 /* It already existed, fine. Just keep going. */
1069 else if (strcmp (command_name, "export") == 0)
1070 /* Don't create CVSADM directories if this is export. */
1075 * Put repository in CVS/Repository. For historical
1076 * (pre-CVS/Root) reasons, this is an absolute pathname,
1077 * but what really matters is the part of it which is
1078 * relative to cvsroot.
1083 repo = xmalloc (strlen (reposdirname)
1084 + strlen (toplevel_repos)
1086 if (reposdirname_absolute)
1090 strcpy (repo, toplevel_repos);
1092 r = repo + strlen (repo);
1097 /* See comment near start of function; the only
1098 way that the server can put the right thing
1099 in each CVS/Repository file is to create the
1100 directories one at a time. I think that the
1101 CVS server has been doing this all along. */
1103 warning: server is not creating directories one at a time");
1104 strncpy (r, reposdirname, rdirp - reposdirname);
1105 r[rdirp - reposdirname] = '\0';
1108 strcpy (r, reposdirname);
1110 Create_Admin (dir, dir, repo,
1111 (char *)NULL, (char *)NULL, 0, 0);
1114 b = strrchr (dir, '/');
1116 Subdir_Register ((List *) NULL, (char *) NULL, dir);
1120 Subdir_Register ((List *) NULL, dir, b + 1);
1127 /* Skip the slash. */
1131 } while (dirp != NULL);
1133 /* Now it better work. */
1134 if ( CVS_CHDIR (dir_name) < 0)
1135 error (1, errno, "could not chdir to %s", dir_name);
1138 if (strcmp (command_name, "export") != 0)
1140 last_entries = Entries_Open (0);
1142 /* If this is a newly created directory, we will record
1143 all subdirectory information, so call Subdirs_Known in
1144 case there are no subdirectories. If this is not a
1145 newly created directory, it may be an old working
1146 directory from before we recorded subdirectory
1147 information in the Entries file. We force a search for
1148 all subdirectories now, to make sure our subdirectory
1149 information is up to date. If the Entries file does
1150 record subdirectory information, then this call only
1151 does list manipulation. */
1153 Subdirs_Known (last_entries);
1158 dirlist = Find_Directories ((char *) NULL, W_LOCAL,
1166 free (reposdirname);
1167 (*func) (data, last_entries, short_pathname, filename);
1168 free (short_pathname);
1173 copy_a_file (data, ent_list, short_pathname, filename)
1176 char *short_pathname;
1180 #ifdef USE_VMS_FILENAMES
1184 read_line (&newname);
1186 #ifdef USE_VMS_FILENAMES
1187 /* Mogrify the filename so VMS is happy with it. */
1188 for(p = newname; *p; p++)
1189 if(*p == '.' || *p == '#') *p = '_';
1192 copy_file (filename, newname);
1197 handle_copy_file (args, len)
1201 call_in_directory (args, copy_a_file, (char *)NULL);
1205 static void read_counted_file PROTO ((char *, char *));
1207 /* Read from the server the count for the length of a file, then read
1208 the contents of that file and write them to FILENAME. FULLNAME is
1209 the name of the file for use in error messages. FIXME-someday:
1210 extend this to deal with compressed files and make update_entries
1211 use it. On error, gives a fatal error. */
1213 read_counted_file (filename, fullname)
1221 /* Pointers in buf to the place to put data which will be read,
1222 and the data which needs to be written, respectively. */
1225 /* Number of bytes left to read and number of bytes in buf waiting to
1226 be written, respectively. */
1232 read_line (&size_string);
1233 if (size_string[0] == 'z')
1235 protocol error: compressed files not supported for that operation");
1236 /* FIXME: should be doing more error checking, probably. Like using
1237 strtoul and making sure we used up the whole line. */
1238 size = atoi (size_string);
1241 /* A more sophisticated implementation would use only a limited amount
1242 of buffer space (8K perhaps), and read that much at a time. We allocate
1243 a buffer for the whole file only to make it easy to keep track what
1244 needs to be read and written. */
1245 buf = xmalloc (size);
1247 /* FIXME-someday: caller should pass in a flag saying whether it
1248 is binary or not. I haven't carefully looked into whether
1249 CVS/Template files should use local text file conventions or
1251 fp = CVS_FOPEN (filename, "wb");
1253 error (1, errno, "cannot write %s", fullname);
1258 while (nread > 0 || nwrite > 0)
1264 n = try_read_from_server (pread, nread);
1272 n = fwrite (pwrite, 1, nwrite, fp);
1274 error (1, errno, "cannot write %s", fullname);
1280 if (fclose (fp) < 0)
1281 error (1, errno, "cannot close %s", fullname);
1284 /* OK, we want to swallow the "U foo.c" response and then output it only
1285 if we can update the file. In the future we probably want some more
1286 systematic approach to parsing tagged text, but for now we keep it
1287 ad hoc. "Why," I hear you cry, "do we not just look at the
1288 Update-existing and Created responses?" That is an excellent question,
1289 and the answer is roughly conservatism/laziness--I haven't read through
1290 update.c enough to figure out the exact correspondence or lack thereof
1291 between those responses and a "U foo.c" line (note that Merged, from
1292 join_file, can be either "C foo" or "U foo" depending on the context). */
1293 /* Nonzero if we have seen +updated and not -updated. */
1294 static int updated_seen;
1295 /* Filename from an "fname" tagged response within +updated/-updated. */
1296 static char *updated_fname;
1299 /* Nonzero if we should arrange to return with a failure exit status. */
1300 static int failure_exit;
1304 * The time stamp of the last file we registered.
1306 static time_t last_register_time;
1309 * The Checksum response gives the checksum for the file transferred
1310 * over by the next Updated, Merged or Patch response. We just store
1311 * it here, and then check it in update_entries.
1314 static int stored_checksum_valid;
1315 static unsigned char stored_checksum[16];
1318 handle_checksum (args, len)
1326 if (stored_checksum_valid)
1327 error (1, 0, "Checksum received before last one was used");
1331 for (i = 0; i < 16; i++)
1337 stored_checksum[i] = (char) strtol (buf, &bufend, 16);
1338 if (bufend != buf + 2)
1342 if (i < 16 || *s != '\0')
1343 error (1, 0, "Invalid Checksum response: `%s'", args);
1345 stored_checksum_valid = 1;
1348 static int stored_mode_valid;
1349 static char *stored_mode;
1351 static void handle_mode PROTO ((char *, int));
1354 handle_mode (args, len)
1358 if (stored_mode_valid)
1359 error (1, 0, "protocol error: duplicate Mode");
1360 if (stored_mode != NULL)
1362 stored_mode = xstrdup (args);
1363 stored_mode_valid = 1;
1366 /* Nonzero if time was specified in Mod-time. */
1367 static int stored_modtime_valid;
1368 /* Time specified in Mod-time. */
1369 static time_t stored_modtime;
1371 static void handle_mod_time PROTO ((char *, int));
1374 handle_mod_time (args, len)
1378 if (stored_modtime_valid)
1379 error (0, 0, "protocol error: duplicate Mod-time");
1380 stored_modtime = get_date (args, NULL);
1381 if (stored_modtime == (time_t) -1)
1382 error (0, 0, "protocol error: cannot parse date %s", args);
1384 stored_modtime_valid = 1;
1388 * If we receive a patch, but the patch program fails to apply it, we
1389 * want to request the original file. We keep a list of files whose
1390 * patches have failed.
1393 char **failed_patches;
1394 int failed_patches_count;
1396 struct update_entries_data
1400 * We are just getting an Entries line; the local file is
1403 UPDATE_ENTRIES_CHECKIN,
1404 /* We are getting the file contents as well. */
1405 UPDATE_ENTRIES_UPDATE,
1407 * We are getting a patch against the existing local file, not
1408 * an entire new file.
1410 UPDATE_ENTRIES_PATCH,
1412 * We are getting an RCS change text (diff -n output) against
1413 * the existing local file, not an entire new file.
1415 UPDATE_ENTRIES_RCS_DIFF
1419 /* We are replacing an existing file. */
1420 UPDATE_ENTRIES_EXISTING,
1421 /* We are creating a new file. */
1423 /* We don't know whether it is existing or new. */
1424 UPDATE_ENTRIES_EXISTING_OR_NEW
1428 * String to put in the timestamp field or NULL to use the timestamp
1434 /* Update the Entries line for this file. */
1436 update_entries (data_arg, ent_list, short_pathname, filename)
1439 char *short_pathname;
1443 struct update_entries_data *data = (struct update_entries_data *)data_arg;
1448 /* Timestamp field. Always empty according to the protocol. */
1450 char *options = NULL;
1454 char *scratch_entries = NULL;
1457 #ifdef UTIME_EXPECTS_WRITABLE
1458 int change_it_back = 0;
1461 read_line (&entries_line);
1464 * Parse the entries line.
1466 scratch_entries = xstrdup (entries_line);
1468 if (scratch_entries[0] != '/')
1469 error (1, 0, "bad entries line `%s' from server", entries_line);
1470 user = scratch_entries + 1;
1471 if ((cp = strchr (user, '/')) == NULL)
1472 error (1, 0, "bad entries line `%s' from server", entries_line);
1475 if ((cp = strchr (vn, '/')) == NULL)
1476 error (1, 0, "bad entries line `%s' from server", entries_line);
1480 if ((cp = strchr (ts, '/')) == NULL)
1481 error (1, 0, "bad entries line `%s' from server", entries_line);
1484 if ((cp = strchr (options, '/')) == NULL)
1485 error (1, 0, "bad entries line `%s' from server", entries_line);
1489 /* If a slash ends the tag_or_date, ignore everything after it. */
1490 cp = strchr (tag_or_date, '/');
1493 if (*tag_or_date == 'T')
1494 tag = tag_or_date + 1;
1495 else if (*tag_or_date == 'D')
1496 date = tag_or_date + 1;
1498 /* Done parsing the entries line. */
1500 if (data->contents == UPDATE_ENTRIES_UPDATE
1501 || data->contents == UPDATE_ENTRIES_PATCH
1502 || data->contents == UPDATE_ENTRIES_RCS_DIFF)
1508 char *temp_filename;
1512 read_line (&mode_string);
1514 read_line (&size_string);
1515 if (size_string[0] == 'z')
1518 size = atoi (size_string+1);
1523 size = atoi (size_string);
1527 /* Note that checking this separately from writing the file is
1528 a race condition: if the existing or lack thereof of the
1529 file changes between now and the actually calls which
1530 operate on it, we lose. However (a) there are so many
1531 cases, I'm reluctant to try to fix them all, (b) in some
1532 cases the system might not even have a system call which
1533 does the right thing, and (c) it isn't clear this needs to
1535 if (data->existp == UPDATE_ENTRIES_EXISTING
1536 && !isfile (filename))
1537 /* Emit a warning and update the file anyway. */
1538 error (0, 0, "warning: %s unexpectedly disappeared",
1541 if (data->existp == UPDATE_ENTRIES_NEW
1542 && isfile (filename))
1544 /* Emit a warning and refuse to update the file; we don't want
1545 to clobber a user's file. */
1549 /* size should be unsigned, but until we get around to fixing
1550 that, work around it. */
1555 /* This error might be confusing; it isn't really clear to
1556 the user what to do about it. Keep in mind that it has
1557 several causes: (1) something/someone creates the file
1558 during the time that CVS is running, (2) the repository
1559 has two files whose names clash for the client because
1560 of case-insensitivity or similar causes, (3) a special
1561 case of this is that a file gets renamed for example
1562 from a.c to A.C. A "cvs update" on a case-insensitive
1563 client will get this error. Repeating the update takes
1564 care of the problem, but is it clear to the user what
1565 is going on and what to do about it?, (4) the client
1566 has a file which the server doesn't know about (e.g. "?
1567 foo" file), and that name clashes with a file the
1568 server does know about, (5) classify.c will print the same
1569 message for other reasons.
1571 I hope the above paragraph makes it clear that making this
1572 clearer is not a one-line fix. */
1573 error (0, 0, "move away %s; it is in the way", short_pathname);
1574 if (updated_fname != NULL)
1576 cvs_output ("C ", 0);
1577 cvs_output (updated_fname, 0);
1578 cvs_output ("\n", 1);
1582 discard_file_and_return:
1583 /* Now read and discard the file contents. */
1586 while (nread < usize)
1588 toread = usize - nread;
1589 if (toread > sizeof buf)
1590 toread = sizeof buf;
1592 nread += try_read_from_server (buf, toread);
1598 free (entries_line);
1600 /* The Mode, Mod-time, and Checksum responses should not carry
1601 over to a subsequent Created (or whatever) response, even
1602 in the error case. */
1603 stored_mode_valid = 0;
1604 if (stored_mode != NULL)
1606 stored_modtime_valid = 0;
1607 stored_checksum_valid = 0;
1609 if (updated_fname != NULL)
1611 free (updated_fname);
1612 updated_fname = NULL;
1617 temp_filename = xmalloc (strlen (filename) + 80);
1618 #ifdef USE_VMS_FILENAMES
1619 /* A VMS rename of "blah.dat" to "foo" to implies a
1620 destination of "foo.dat" which is unfortinate for CVS */
1621 sprintf (temp_filename, "%s_new_", filename);
1623 #ifdef _POSIX_NO_TRUNC
1624 sprintf (temp_filename, ".new.%.9s", filename);
1625 #else /* _POSIX_NO_TRUNC */
1626 sprintf (temp_filename, ".new.%s", filename);
1627 #endif /* _POSIX_NO_TRUNC */
1628 #endif /* USE_VMS_FILENAMES */
1630 buf = xmalloc (size);
1632 /* Some systems, like OS/2 and Windows NT, end lines with CRLF
1633 instead of just LF. Format translation is done in the C
1634 library I/O funtions. Here we tell them whether or not to
1635 convert -- if this file is marked "binary" with the RCS -kb
1636 flag, then we don't want to convert, else we do (because
1637 CVS assumes text files by default). */
1640 bin = !(strcmp (options, "-kb"));
1644 if (data->contents == UPDATE_ENTRIES_RCS_DIFF)
1646 /* This is an RCS change text. We just hold the change
1651 "server error: gzip invalid with RCS change text");
1653 read_from_server (buf, size);
1659 fd = CVS_OPEN (temp_filename,
1660 (O_WRONLY | O_CREAT | O_TRUNC
1661 | (bin ? OPEN_BINARY : 0)),
1666 /* I can see a case for making this a fatal error; for
1667 a condition like disk full or network unreachable
1668 (for a file server), carrying on and giving an
1669 error on each file seems unnecessary. But if it is
1670 a permission problem, or some such, then it is
1671 entirely possible that future files will not have
1672 the same problem. */
1673 error (0, errno, "cannot write %s", short_pathname);
1674 goto discard_file_and_return;
1679 read_from_server (buf, size);
1682 gunzip_and_write (fd, short_pathname, buf, size);
1683 else if (write (fd, buf, size) != size)
1684 error (1, errno, "writing %s", short_pathname);
1688 error (1, errno, "writing %s", short_pathname);
1691 /* This is after we have read the file from the net (a change
1692 from previous versions, where the server would send us
1693 "M U foo.c" before Update-existing or whatever), but before
1694 we finish writing the file (arguably a bug). The timing
1695 affects a user who wants status info about how far we have
1696 gotten, and also affects whether "U foo.c" appears in addition
1697 to various error messages. */
1698 if (updated_fname != NULL)
1700 cvs_output ("U ", 0);
1701 cvs_output (updated_fname, 0);
1702 cvs_output ("\n", 1);
1703 free (updated_fname);
1709 if (data->contents == UPDATE_ENTRIES_UPDATE)
1711 rename_file (temp_filename, filename);
1713 else if (data->contents == UPDATE_ENTRIES_PATCH)
1715 #ifdef DONT_USE_PATCH
1716 /* Hmm. We support only Rcs-diff, and the server supports
1717 only Patched (or else it would have sent Rcs-diff instead).
1718 Fall back to transmitting entire files. */
1720 #else /* Use patch. */
1725 backup = xmalloc (strlen (filename) + 5);
1726 strcpy (backup, filename);
1727 strcat (backup, "~");
1728 (void) unlink_file (backup);
1729 if (!isfile (filename))
1730 error (1, 0, "patch original file %s does not exist",
1732 if ( CVS_STAT (temp_filename, &s) < 0)
1733 error (1, errno, "can't stat patch file %s", temp_filename);
1738 /* This behavior (in which -b takes an argument) is
1739 supported by GNU patch 2.1. Apparently POSIX.2
1740 specifies a -b option without an argument. GNU
1741 patch 2.1.5 implements this and therefore won't
1742 work here. GNU patch versions after 2.1.5 are said
1743 to have a kludge which checks if the last 4 args
1744 are `-b SUFFIX ORIGFILE PATCHFILE' and if so emit a
1745 warning (I think -s suppresses it), and then behave
1748 Of course this is yet one more reason why in the long
1749 run we want Rcs-diff to replace Patched. */
1751 run_setup (PATCH_PROGRAM);
1757 run_arg (temp_filename);
1758 retcode = run_exec (DEVNULL, RUN_TTY, RUN_TTY, RUN_NORMAL);
1760 /* FIXME: should we really be silently ignoring errors? */
1761 (void) unlink_file (temp_filename);
1764 /* FIXME: should we really be silently ignoring errors? */
1765 (void) unlink_file (backup);
1769 int old_errno = errno;
1772 if (isfile (backup))
1773 rename_file (backup, filename);
1775 /* Get rid of the patch reject file. */
1776 path_tmp = xmalloc (strlen (filename) + 10);
1777 strcpy (path_tmp, filename);
1778 strcat (path_tmp, ".rej");
1779 /* FIXME: should we really be silently ignoring errors? */
1780 (void) unlink_file (path_tmp);
1783 error (retcode == -1 ? 1 : 0, retcode == -1 ? old_errno : 0,
1784 "could not patch %s%s", filename,
1785 retcode == -1 ? "" : "; will refetch");
1790 #endif /* Use patch. */
1800 /* Handle UPDATE_ENTRIES_RCS_DIFF. */
1802 if (!isfile (filename))
1803 error (1, 0, "patch original file %s does not exist",
1809 get_file (filename, short_pathname, bin ? FOPEN_BINARY_READ : "r",
1810 &filebuf, &filebufsize, &nread);
1811 /* At this point the contents of the existing file are in
1812 FILEBUF, and the length of the contents is in NREAD.
1813 The contents of the patch from the network are in BUF,
1814 and the length of the patch is in SIZE. */
1816 if (! rcs_change_text (short_pathname, filebuf, nread, buf, size,
1817 &patchedbuf, &patchedlen))
1821 if (stored_checksum_valid)
1823 struct MD5Context context;
1824 unsigned char checksum[16];
1826 /* We have a checksum. Check it before writing
1827 the file out, so that we don't have to read it
1830 MD5Update (&context, (unsigned char *) patchedbuf, patchedlen);
1831 MD5Final (checksum, &context);
1832 if (memcmp (checksum, stored_checksum, 16) != 0)
1835 "checksum failure after patch to %s; will refetch",
1841 stored_checksum_valid = 0;
1848 e = open_file (temp_filename,
1849 bin ? FOPEN_BINARY_WRITE : "w");
1850 if (fwrite (patchedbuf, 1, patchedlen, e) != patchedlen)
1851 error (1, errno, "cannot write %s", temp_filename);
1852 if (fclose (e) == EOF)
1853 error (1, errno, "cannot close %s", temp_filename);
1854 rename_file (temp_filename, filename);
1863 free (temp_filename);
1865 if (stored_checksum_valid && ! patch_failed)
1868 struct MD5Context context;
1869 unsigned char buf[8192];
1871 unsigned char checksum[16];
1874 * Compute the MD5 checksum. This will normally only be
1875 * used when receiving a patch, so we always compute it
1876 * here on the final file, rather than on the received
1879 * Note that if the file is a text file, we should read it
1880 * here using text mode, so its lines will be terminated the same
1881 * way they were transmitted.
1883 e = CVS_FOPEN (filename, "r");
1885 error (1, errno, "could not open %s", short_pathname);
1888 while ((len = fread (buf, 1, sizeof buf, e)) != 0)
1889 MD5Update (&context, buf, len);
1891 error (1, errno, "could not read %s", short_pathname);
1892 MD5Final (checksum, &context);
1896 stored_checksum_valid = 0;
1898 if (memcmp (checksum, stored_checksum, 16) != 0)
1900 if (data->contents != UPDATE_ENTRIES_PATCH)
1901 error (1, 0, "checksum failure on %s",
1905 "checksum failure after patch to %s; will refetch",
1914 /* Save this file to retrieve later. */
1915 failed_patches = (char **) xrealloc ((char *) failed_patches,
1916 ((failed_patches_count + 1)
1917 * sizeof (char *)));
1918 failed_patches[failed_patches_count] = xstrdup (short_pathname);
1919 ++failed_patches_count;
1921 stored_checksum_valid = 0;
1930 /* FIXME: we should be respecting the umask. */
1931 int status = change_mode (filename, mode_string);
1933 error (0, status, "cannot change mode of %s", short_pathname);
1940 if (stored_mode_valid)
1941 change_mode (filename, stored_mode);
1942 stored_mode_valid = 0;
1944 if (stored_modtime_valid)
1948 memset (&t, 0, sizeof (t));
1949 /* There is probably little point in trying to preserved the
1950 actime (or is there? What about Checked-in?). */
1951 t.modtime = t.actime = stored_modtime;
1953 #ifdef UTIME_EXPECTS_WRITABLE
1954 if (!iswritable (filename))
1956 xchmod (filename, 1);
1959 #endif /* UTIME_EXPECTS_WRITABLE */
1961 if (utime (filename, &t) < 0)
1962 error (0, errno, "cannot set time on %s", filename);
1964 #ifdef UTIME_EXPECTS_WRITABLE
1965 if (change_it_back == 1)
1967 xchmod (filename, 0);
1970 #endif /* UTIME_EXPECTS_WRITABLE */
1972 stored_modtime_valid = 0;
1976 * Process the entries line. Do this after we've written the file,
1977 * since we need the timestamp.
1979 if (strcmp (command_name, "export") != 0)
1981 char *local_timestamp;
1982 char *file_timestamp;
1984 (void) time (&last_register_time);
1986 local_timestamp = data->timestamp;
1987 if (local_timestamp == NULL || ts[0] == '+')
1988 file_timestamp = time_stamp (filename);
1990 file_timestamp = NULL;
1993 * These special version numbers signify that it is not up to
1994 * date. Create a dummy timestamp which will never compare
1995 * equal to the timestamp of the file.
1997 if (vn[0] == '\0' || vn[0] == '0' || vn[0] == '-')
1998 local_timestamp = "dummy timestamp";
1999 else if (local_timestamp == NULL)
2001 local_timestamp = file_timestamp;
2002 mark_up_to_date (filename);
2005 Register (ent_list, filename, vn, local_timestamp,
2006 options, tag, date, ts[0] == '+' ? file_timestamp : NULL);
2009 free (file_timestamp);
2011 free (scratch_entries);
2013 free (entries_line);
2017 handle_checked_in (args, len)
2021 struct update_entries_data dat;
2022 dat.contents = UPDATE_ENTRIES_CHECKIN;
2023 dat.existp = UPDATE_ENTRIES_EXISTING_OR_NEW;
2024 dat.timestamp = NULL;
2025 call_in_directory (args, update_entries, (char *)&dat);
2029 handle_new_entry (args, len)
2033 struct update_entries_data dat;
2034 dat.contents = UPDATE_ENTRIES_CHECKIN;
2035 dat.existp = UPDATE_ENTRIES_EXISTING_OR_NEW;
2036 dat.timestamp = "dummy timestamp from new-entry";
2037 call_in_directory (args, update_entries, (char *)&dat);
2041 handle_updated (args, len)
2045 struct update_entries_data dat;
2046 dat.contents = UPDATE_ENTRIES_UPDATE;
2047 dat.existp = UPDATE_ENTRIES_EXISTING_OR_NEW;
2048 dat.timestamp = NULL;
2049 call_in_directory (args, update_entries, (char *)&dat);
2052 static void handle_created PROTO((char *, int));
2055 handle_created (args, len)
2059 struct update_entries_data dat;
2060 dat.contents = UPDATE_ENTRIES_UPDATE;
2061 dat.existp = UPDATE_ENTRIES_NEW;
2062 dat.timestamp = NULL;
2063 call_in_directory (args, update_entries, (char *)&dat);
2066 static void handle_update_existing PROTO((char *, int));
2069 handle_update_existing (args, len)
2073 struct update_entries_data dat;
2074 dat.contents = UPDATE_ENTRIES_UPDATE;
2075 dat.existp = UPDATE_ENTRIES_EXISTING;
2076 dat.timestamp = NULL;
2077 call_in_directory (args, update_entries, (char *)&dat);
2081 handle_merged (args, len)
2085 struct update_entries_data dat;
2086 dat.contents = UPDATE_ENTRIES_UPDATE;
2087 /* Think this could be UPDATE_ENTRIES_EXISTING, but just in case... */
2088 dat.existp = UPDATE_ENTRIES_EXISTING_OR_NEW;
2089 dat.timestamp = "Result of merge";
2090 call_in_directory (args, update_entries, (char *)&dat);
2094 handle_patched (args, len)
2098 struct update_entries_data dat;
2099 dat.contents = UPDATE_ENTRIES_PATCH;
2100 /* Think this could be UPDATE_ENTRIES_EXISTING, but just in case... */
2101 dat.existp = UPDATE_ENTRIES_EXISTING_OR_NEW;
2102 dat.timestamp = NULL;
2103 call_in_directory (args, update_entries, (char *)&dat);
2107 handle_rcs_diff (args, len)
2111 struct update_entries_data dat;
2112 dat.contents = UPDATE_ENTRIES_RCS_DIFF;
2113 /* Think this could be UPDATE_ENTRIES_EXISTING, but just in case... */
2114 dat.existp = UPDATE_ENTRIES_EXISTING_OR_NEW;
2115 dat.timestamp = NULL;
2116 call_in_directory (args, update_entries, (char *)&dat);
2120 remove_entry (data, ent_list, short_pathname, filename)
2123 char *short_pathname;
2126 Scratch_Entry (ent_list, filename);
2130 handle_remove_entry (args, len)
2134 call_in_directory (args, remove_entry, (char *)NULL);
2138 remove_entry_and_file (data, ent_list, short_pathname, filename)
2141 char *short_pathname;
2144 Scratch_Entry (ent_list, filename);
2145 /* Note that we don't ignore existence_error's here. The server
2146 should be sending Remove-entry rather than Removed in cases
2147 where the file does not exist. And if the user removes the
2148 file halfway through a cvs command, we should be printing an
2150 if (unlink_file (filename) < 0)
2151 error (0, errno, "unable to remove %s", short_pathname);
2155 handle_removed (args, len)
2159 call_in_directory (args, remove_entry_and_file, (char *)NULL);
2162 /* Is this the top level (directory containing CVSROOT)? */
2164 is_cvsroot_level (pathname)
2167 if (strcmp (toplevel_repos, CVSroot_directory) != 0)
2170 return strchr (pathname, '/') == NULL;
2174 set_static (data, ent_list, short_pathname, filename)
2177 char *short_pathname;
2181 fp = open_file (CVSADM_ENTSTAT, "w+");
2182 if (fclose (fp) == EOF)
2183 error (1, errno, "cannot close %s", CVSADM_ENTSTAT);
2187 handle_set_static_directory (args, len)
2191 if (strcmp (command_name, "export") == 0)
2193 /* Swallow the repository. */
2197 call_in_directory (args, set_static, (char *)NULL);
2201 clear_static (data, ent_list, short_pathname, filename)
2204 char *short_pathname;
2207 if (unlink_file (CVSADM_ENTSTAT) < 0 && ! existence_error (errno))
2208 error (1, errno, "cannot remove file %s", CVSADM_ENTSTAT);
2212 handle_clear_static_directory (pathname, len)
2216 if (strcmp (command_name, "export") == 0)
2218 /* Swallow the repository. */
2223 if (is_cvsroot_level (pathname))
2226 * Top level (directory containing CVSROOT). This seems to normally
2227 * lack a CVS directory, so don't try to create files in it.
2231 call_in_directory (pathname, clear_static, (char *)NULL);
2235 set_sticky (data, ent_list, short_pathname, filename)
2238 char *short_pathname;
2244 read_line (&tagspec);
2245 f = open_file (CVSADM_TAG, "w+");
2246 if (fprintf (f, "%s\n", tagspec) < 0)
2247 error (1, errno, "writing %s", CVSADM_TAG);
2248 if (fclose (f) == EOF)
2249 error (1, errno, "closing %s", CVSADM_TAG);
2254 handle_set_sticky (pathname, len)
2258 if (strcmp (command_name, "export") == 0)
2260 /* Swallow the repository. */
2262 /* Swallow the tag line. */
2266 if (is_cvsroot_level (pathname))
2269 * Top level (directory containing CVSROOT). This seems to normally
2270 * lack a CVS directory, so don't try to create files in it.
2273 /* Swallow the repository. */
2275 /* Swallow the tag line. */
2280 call_in_directory (pathname, set_sticky, (char *)NULL);
2284 clear_sticky (data, ent_list, short_pathname, filename)
2287 char *short_pathname;
2290 if (unlink_file (CVSADM_TAG) < 0 && ! existence_error (errno))
2291 error (1, errno, "cannot remove %s", CVSADM_TAG);
2295 handle_clear_sticky (pathname, len)
2299 if (strcmp (command_name, "export") == 0)
2301 /* Swallow the repository. */
2306 if (is_cvsroot_level (pathname))
2309 * Top level (directory containing CVSROOT). This seems to normally
2310 * lack a CVS directory, so don't try to create files in it.
2315 call_in_directory (pathname, clear_sticky, (char *)NULL);
2319 static void template PROTO ((char *, List *, char *, char *));
2322 template (data, ent_list, short_pathname, filename)
2325 char *short_pathname;
2328 /* FIXME: should be computing second argument from CVSADM_TEMPLATE
2329 and short_pathname. */
2330 read_counted_file (CVSADM_TEMPLATE, "<CVS/Template file>");
2333 static void handle_template PROTO ((char *, int));
2336 handle_template (pathname, len)
2340 call_in_directory (pathname, template, NULL);
2347 struct save_prog *next;
2350 static struct save_prog *checkin_progs;
2351 static struct save_prog *update_progs;
2354 * Unlike some responses this doesn't include the repository. So we can't
2355 * just call call_in_directory and have the right thing happen; we save up
2356 * the requests and do them at the end.
2359 handle_set_checkin_prog (args, len)
2364 struct save_prog *p;
2366 p = (struct save_prog *) xmalloc (sizeof (struct save_prog));
2367 p->next = checkin_progs;
2368 p->dir = xstrdup (args);
2374 handle_set_update_prog (args, len)
2379 struct save_prog *p;
2381 p = (struct save_prog *) xmalloc (sizeof (struct save_prog));
2382 p->next = update_progs;
2383 p->dir = xstrdup (args);
2388 static void do_deferred_progs PROTO((void));
2391 do_deferred_progs ()
2393 struct save_prog *p;
2394 struct save_prog *q;
2399 if (toplevel_wd != NULL)
2401 if (CVS_CHDIR (toplevel_wd) < 0)
2402 error (1, errno, "could not chdir to %s", toplevel_wd);
2404 for (p = checkin_progs; p != NULL; )
2406 fname = xmalloc (strlen (p->dir) + sizeof CVSADM_CIPROG + 10);
2407 sprintf (fname, "%s/%s", p->dir, CVSADM_CIPROG);
2408 f = open_file (fname, "w");
2409 if (fprintf (f, "%s\n", p->name) < 0)
2410 error (1, errno, "writing %s", fname);
2411 if (fclose (f) == EOF)
2412 error (1, errno, "closing %s", fname);
2420 checkin_progs = NULL;
2421 for (p = update_progs; p != NULL; )
2423 fname = xmalloc (strlen (p->dir) + sizeof CVSADM_UPROG + 10);
2424 sprintf (fname, "%s/%s", p->dir, CVSADM_UPROG);
2425 f = open_file (fname, "w");
2426 if (fprintf (f, "%s\n", p->name) < 0)
2427 error (1, errno, "writing %s", fname);
2428 if (fclose (f) == EOF)
2429 error (1, errno, "closing %s", fname);
2437 update_progs = NULL;
2442 struct save_dir *next;
2445 struct save_dir *prune_candidates;
2448 add_prune_candidate (dir)
2453 if ((dir[0] == '.' && dir[1] == '\0')
2454 || (prune_candidates != NULL
2455 && strcmp (dir, prune_candidates->dir) == 0))
2457 p = (struct save_dir *) xmalloc (sizeof (struct save_dir));
2458 p->dir = xstrdup (dir);
2459 p->next = prune_candidates;
2460 prune_candidates = p;
2463 static void process_prune_candidates PROTO((void));
2466 process_prune_candidates ()
2471 if (toplevel_wd != NULL)
2473 if (CVS_CHDIR (toplevel_wd) < 0)
2474 error (1, errno, "could not chdir to %s", toplevel_wd);
2476 for (p = prune_candidates; p != NULL; )
2478 if (isemptydir (p->dir, 1))
2482 if (unlink_file_dir (p->dir) < 0)
2483 error (0, errno, "cannot remove %s", p->dir);
2484 b = strrchr (p->dir, '/');
2486 Subdir_Deregister ((List *) NULL, (char *) NULL, p->dir);
2490 Subdir_Deregister ((List *) NULL, p->dir, b + 1);
2498 prune_candidates = NULL;
2501 /* Send a Repository line. */
2503 static char *last_repos;
2504 static char *last_update_dir;
2506 static void send_repository PROTO((char *, char *, char *));
2509 send_repository (dir, repos, update_dir)
2516 /* FIXME: this is probably not the best place to check; I wish I
2517 * knew where in here's callers to really trap this bug. To
2518 * reproduce the bug, just do this:
2522 * cvs -d some_repos update foo
2524 * Poof, CVS seg faults and dies! It's because it's trying to
2525 * send a NULL string to the server but dies in send_to_server.
2526 * That string was supposed to be the repository, but it doesn't
2527 * get set because there's no CVSADM dir, and somehow it's not
2528 * getting set from the -d argument either... ?
2532 /* Lame error. I want a real fix but can't stay up to track
2533 this down right now. */
2534 error (1, 0, "no repository");
2537 if (update_dir == NULL || update_dir[0] == '\0')
2540 if (last_repos != NULL
2541 && strcmp (repos, last_repos) == 0
2542 && last_update_dir != NULL
2543 && strcmp (update_dir, last_update_dir) == 0)
2544 /* We've already sent it. */
2547 if (client_prune_dirs)
2548 add_prune_candidate (update_dir);
2550 /* 80 is large enough for any of CVSADM_*. */
2551 adm_name = xmalloc (strlen (dir) + 80);
2553 send_to_server ("Directory ", 0);
2555 /* Send the directory name. I know that this
2556 sort of duplicates code elsewhere, but each
2557 case seems slightly different... */
2559 char *p = update_dir;
2562 assert (*p != '\012');
2566 send_to_server (buf, 1);
2571 send_to_server (buf, 1);
2576 send_to_server ("\012", 1);
2577 send_to_server (repos, 0);
2578 send_to_server ("\012", 1);
2580 if (supported_request ("Static-directory"))
2585 strcat (adm_name, dir);
2586 strcat (adm_name, "/");
2588 strcat (adm_name, CVSADM_ENTSTAT);
2589 if (isreadable (adm_name))
2591 send_to_server ("Static-directory\012", 0);
2594 if (supported_request ("Sticky"))
2598 strcpy (adm_name, CVSADM_TAG);
2600 sprintf (adm_name, "%s/%s", dir, CVSADM_TAG);
2602 f = CVS_FOPEN (adm_name, "r");
2605 if (! existence_error (errno))
2606 error (1, errno, "reading %s", adm_name);
2612 send_to_server ("Sticky ", 0);
2613 while (fgets (line, sizeof (line), f) != NULL)
2615 send_to_server (line, 0);
2616 nl = strchr (line, '\n');
2621 send_to_server ("\012", 1);
2622 if (fclose (f) == EOF)
2623 error (0, errno, "closing %s", adm_name);
2626 if (supported_request ("Checkin-prog"))
2630 strcpy (adm_name, CVSADM_CIPROG);
2632 sprintf (adm_name, "%s/%s", dir, CVSADM_CIPROG);
2634 f = CVS_FOPEN (adm_name, "r");
2637 if (! existence_error (errno))
2638 error (1, errno, "reading %s", adm_name);
2645 send_to_server ("Checkin-prog ", 0);
2647 while (fgets (line, sizeof (line), f) != NULL)
2649 send_to_server (line, 0);
2651 nl = strchr (line, '\n');
2656 send_to_server ("\012", 1);
2657 if (fclose (f) == EOF)
2658 error (0, errno, "closing %s", adm_name);
2661 if (supported_request ("Update-prog"))
2665 strcpy (adm_name, CVSADM_UPROG);
2667 sprintf (adm_name, "%s/%s", dir, CVSADM_UPROG);
2669 f = CVS_FOPEN (adm_name, "r");
2672 if (! existence_error (errno))
2673 error (1, errno, "reading %s", adm_name);
2680 send_to_server ("Update-prog ", 0);
2682 while (fgets (line, sizeof (line), f) != NULL)
2684 send_to_server (line, 0);
2686 nl = strchr (line, '\n');
2691 send_to_server ("\012", 1);
2692 if (fclose (f) == EOF)
2693 error (0, errno, "closing %s", adm_name);
2697 if (last_repos != NULL)
2699 if (last_update_dir != NULL)
2700 free (last_update_dir);
2701 last_repos = xstrdup (repos);
2702 last_update_dir = xstrdup (update_dir);
2705 /* Send a Repository line and set toplevel_repos. */
2708 send_a_repository (dir, repository, update_dir)
2713 if (toplevel_repos == NULL && repository != NULL)
2715 if (update_dir[0] == '\0'
2716 || (update_dir[0] == '.' && update_dir[1] == '\0'))
2717 toplevel_repos = xstrdup (repository);
2721 * Get the repository from a CVS/Repository file if update_dir
2722 * is absolute. This is not correct in general, because
2723 * the CVS/Repository file might not be the top-level one.
2724 * This is for cases like "cvs update /foo/bar" (I'm not
2725 * sure it matters what toplevel_repos we get, but it does
2726 * matter that we don't hit the "internal error" code below).
2728 if (update_dir[0] == '/')
2729 toplevel_repos = Name_Repository (update_dir, update_dir);
2733 * Guess the repository of that directory by looking at a
2734 * subdirectory and removing as many pathname components
2735 * as are in update_dir. I think that will always (or at
2736 * least almost always) be 1.
2738 * So this deals with directories which have been
2739 * renamed, though it doesn't necessarily deal with
2740 * directories which have been put inside other
2741 * directories (and cvs invoked on the containing
2742 * directory). I'm not sure the latter case needs to
2746 * This gets toplevel_repos wrong for "cvs update ../foo"
2747 * but I'm not sure toplevel_repos matters in that case.
2749 int slashes_in_update_dir;
2750 int slashes_skipped;
2754 * Strip trailing slashes from the name of the update directory.
2755 * Otherwise, running `cvs update dir/' provokes the failure
2756 * `protocol error: illegal directory syntax in dir/' when
2757 * running in client/server mode.
2759 strip_trailing_slashes (update_dir);
2761 slashes_in_update_dir = 0;
2762 for (p = update_dir; *p != '\0'; ++p)
2764 ++slashes_in_update_dir;
2766 slashes_skipped = 0;
2767 p = repository + strlen (repository);
2770 if (p == repository)
2772 "internal error: not enough slashes in %s",
2776 if (slashes_skipped < slashes_in_update_dir + 1)
2781 toplevel_repos = xmalloc (p - repository + 1);
2782 /* Note that we don't copy the trailing '/'. */
2783 strncpy (toplevel_repos, repository, p - repository);
2784 toplevel_repos[p - repository] = '\0';
2789 send_repository (dir, repository, update_dir);
2792 /* The "expanded" modules. */
2793 static int modules_count;
2794 static int modules_allocated;
2795 static char **modules_vector;
2798 handle_module_expansion (args, len)
2802 if (modules_vector == NULL)
2804 modules_allocated = 1; /* Small for testing */
2805 modules_vector = (char **) xmalloc
2806 (modules_allocated * sizeof (modules_vector[0]));
2808 else if (modules_count >= modules_allocated)
2810 modules_allocated *= 2;
2811 modules_vector = (char **) xrealloc
2812 ((char *) modules_vector,
2813 modules_allocated * sizeof (modules_vector[0]));
2815 modules_vector[modules_count] = xmalloc (strlen (args) + 1);
2816 strcpy (modules_vector[modules_count], args);
2820 /* Original, not "expanded" modules. */
2821 static int module_argc;
2822 static char **module_argv;
2825 client_expand_modules (argc, argv, local)
2834 module_argv = (char **) xmalloc ((argc + 1) * sizeof (module_argv[0]));
2835 for (i = 0; i < argc; ++i)
2836 module_argv[i] = xstrdup (argv[i]);
2837 module_argv[argc] = NULL;
2839 for (i = 0; i < argc; ++i)
2841 send_a_repository ("", CVSroot_directory, "");
2843 send_to_server ("expand-modules\012", 0);
2845 errs = get_server_responses ();
2846 if (last_repos != NULL)
2849 if (last_update_dir != NULL)
2850 free (last_update_dir);
2851 last_update_dir = NULL;
2853 error (errs, 0, "cannot expand modules");
2857 client_send_expansions (local, where, build_dirs)
2865 /* Send the original module names. The "expanded" module name might
2866 not be suitable as an argument to a co request (e.g. it might be
2867 the result of a -d argument in the modules file). It might be
2868 cleaner if we genuinely expanded module names, all the way to a
2869 local directory and repository, but that isn't the way it works
2871 send_file_names (module_argc, module_argv, 0);
2873 for (i = 0; i < modules_count; ++i)
2875 argv[0] = where ? where : modules_vector[i];
2876 if (isfile (argv[0]))
2877 send_files (1, argv, local, 0, build_dirs ? SEND_BUILD_DIRS : 0);
2879 send_a_repository ("", CVSroot_directory, "");
2883 client_nonexpanded_setup ()
2885 send_a_repository ("", CVSroot_directory, "");
2889 handle_m (args, len)
2893 /* In the case where stdout and stderr point to the same place,
2894 fflushing stderr will make output happen in the correct order.
2895 Often stderr will be line-buffered and this won't be needed,
2896 but not always (is that true? I think the comment is probably
2897 based on being confused between default buffering between
2898 stdout and stderr. But I'm not sure). */
2900 fwrite (args, len, sizeof (*args), stdout);
2901 putc ('\n', stdout);
2904 static void handle_mbinary PROTO ((char *, int));
2907 handle_mbinary (args, len)
2918 /* See comment at handle_m about (non)flush of stderr. */
2921 read_line (&size_string);
2922 size = atoi (size_string);
2925 /* OK, now get all the data. The algorithm here is that we read
2926 as much as the network wants to give us in
2927 try_read_from_server, and then we output it all, and then
2928 repeat, until we get all the data. */
2930 while (totalread < size)
2932 toread = size - totalread;
2933 if (toread > sizeof buf)
2934 toread = sizeof buf;
2936 nread = try_read_from_server (buf, toread);
2937 cvs_output_binary (buf, nread);
2943 handle_e (args, len)
2947 /* In the case where stdout and stderr point to the same place,
2948 fflushing stdout will make output happen in the correct order. */
2950 fwrite (args, len, sizeof (*args), stderr);
2951 putc ('\n', stderr);
2956 handle_f (args, len)
2963 static void handle_mt PROTO ((char *, int));
2966 handle_mt (args, len)
2974 /* See comment at handle_m for more details. */
2977 p = strchr (args, ' ');
2989 if (strcmp (tag, "+updated") == 0)
2993 if (strcmp (tag, "-updated") == 0)
2999 if (strcmp (tag, "fname") == 0)
3001 if (updated_fname != NULL)
3003 /* Output the previous message now. This can happen
3004 if there was no Update-existing or other such
3005 response, due to the -n global option. */
3006 cvs_output ("U ", 0);
3007 cvs_output (updated_fname, 0);
3008 cvs_output ("\n", 1);
3009 free (updated_fname);
3011 updated_fname = xstrdup (text);
3013 /* Swallow all other tags. Either they are extraneous
3014 or they reflect future extensions that we can
3017 else if (strcmp (tag, "newline") == 0)
3019 else if (text != NULL)
3020 printf ("%s", text);
3024 #endif /* CLIENT_SUPPORT */
3025 #if defined(CLIENT_SUPPORT) || defined(SERVER_SUPPORT)
3027 /* This table must be writeable if the server code is included. */
3028 struct response responses[] =
3030 #ifdef CLIENT_SUPPORT
3031 #define RSP_LINE(n, f, t, s) {n, f, t, s}
3032 #else /* ! CLIENT_SUPPORT */
3033 #define RSP_LINE(n, f, t, s) {n, s}
3034 #endif /* CLIENT_SUPPORT */
3036 RSP_LINE("ok", handle_ok, response_type_ok, rs_essential),
3037 RSP_LINE("error", handle_error, response_type_error, rs_essential),
3038 RSP_LINE("Valid-requests", handle_valid_requests, response_type_normal,
3040 RSP_LINE("Checked-in", handle_checked_in, response_type_normal,
3042 RSP_LINE("New-entry", handle_new_entry, response_type_normal, rs_optional),
3043 RSP_LINE("Checksum", handle_checksum, response_type_normal, rs_optional),
3044 RSP_LINE("Copy-file", handle_copy_file, response_type_normal, rs_optional),
3045 RSP_LINE("Updated", handle_updated, response_type_normal, rs_essential),
3046 RSP_LINE("Created", handle_created, response_type_normal, rs_optional),
3047 RSP_LINE("Update-existing", handle_update_existing, response_type_normal,
3049 RSP_LINE("Merged", handle_merged, response_type_normal, rs_essential),
3050 RSP_LINE("Patched", handle_patched, response_type_normal, rs_optional),
3051 RSP_LINE("Rcs-diff", handle_rcs_diff, response_type_normal, rs_optional),
3052 RSP_LINE("Mode", handle_mode, response_type_normal, rs_optional),
3053 RSP_LINE("Mod-time", handle_mod_time, response_type_normal, rs_optional),
3054 RSP_LINE("Removed", handle_removed, response_type_normal, rs_essential),
3055 RSP_LINE("Remove-entry", handle_remove_entry, response_type_normal,
3057 RSP_LINE("Set-static-directory", handle_set_static_directory,
3058 response_type_normal,
3060 RSP_LINE("Clear-static-directory", handle_clear_static_directory,
3061 response_type_normal,
3063 RSP_LINE("Set-sticky", handle_set_sticky, response_type_normal,
3065 RSP_LINE("Clear-sticky", handle_clear_sticky, response_type_normal,
3067 RSP_LINE("Template", handle_template, response_type_normal,
3069 RSP_LINE("Set-checkin-prog", handle_set_checkin_prog, response_type_normal,
3071 RSP_LINE("Set-update-prog", handle_set_update_prog, response_type_normal,
3073 RSP_LINE("Notified", handle_notified, response_type_normal, rs_optional),
3074 RSP_LINE("Module-expansion", handle_module_expansion, response_type_normal,
3076 RSP_LINE("M", handle_m, response_type_normal, rs_essential),
3077 RSP_LINE("Mbinary", handle_mbinary, response_type_normal, rs_optional),
3078 RSP_LINE("E", handle_e, response_type_normal, rs_essential),
3079 RSP_LINE("F", handle_f, response_type_normal, rs_optional),
3080 RSP_LINE("MT", handle_mt, response_type_normal, rs_optional),
3081 /* Possibly should be response_type_error. */
3082 RSP_LINE(NULL, NULL, response_type_normal, rs_essential)
3087 #endif /* CLIENT_SUPPORT or SERVER_SUPPORT */
3088 #ifdef CLIENT_SUPPORT
3091 * If LEN is 0, then send_to_server() computes string's length itself.
3093 * Therefore, pass the real length when transmitting data that might
3097 send_to_server (str, len)
3106 buf_output (to_server, str, len);
3108 /* There is no reason not to send data to the server, so do it
3109 whenever we've accumulated enough information in the buffer to
3110 make it worth sending. */
3112 if (nbytes >= 2 * BUFFER_DATA_SIZE)
3116 status = buf_send_output (to_server);
3118 error (1, status, "error writing to server");
3123 /* Read up to LEN bytes from the server. Returns actual number of
3124 bytes read, which will always be at least one; blocks if there is
3125 no data available at all. Gives a fatal error on EOF or error. */
3127 try_read_from_server (buf, len)
3134 status = buf_read_data (from_server, len, &data, &nread);
3139 "end of file from server (consult above messages if any)");
3140 else if (status == -2)
3141 error (1, 0, "out of memory");
3143 error (1, status, "reading from server");
3146 memcpy (buf, data, nread);
3152 * Read LEN bytes from the server or die trying.
3155 read_from_server (buf, len)
3162 red += try_read_from_server (buf + red, len - red);
3169 * Get some server responses and process them. Returns nonzero for
3170 * error, 0 for success. */
3172 get_server_responses ()
3174 struct response *rs;
3180 len = read_line (&cmd);
3181 for (rs = responses; rs->name != NULL; ++rs)
3182 if (strncmp (cmd, rs->name, strlen (rs->name)) == 0)
3184 int cmdlen = strlen (rs->name);
3185 if (cmd[cmdlen] == '\0')
3187 else if (cmd[cmdlen] == ' ')
3191 * The first len characters match, but it's a different
3192 * response. e.g. the response is "oklahoma" but we
3196 (*rs->func) (cmd + cmdlen, len - cmdlen);
3199 if (rs->name == NULL)
3200 /* It's OK to print just to the first '\0'. */
3201 /* We might want to handle control characters and the like
3202 in some other way other than just sending them to stdout.
3203 One common reason for this error is if people use :ext:
3204 with a version of rsh which is doing CRLF translation or
3205 something, and so the client gets "ok^M" instead of "ok".
3206 Right now that will tend to print part of this error
3207 message over the other part of it. It seems like we could
3208 do better (either in general, by quoting or omitting all
3209 control characters, and/or specifically, by detecting the CRLF
3210 case and printing a specific error message). */
3212 "warning: unrecognized response `%s' from cvs server",
3215 } while (rs->type == response_type_normal);
3217 if (updated_fname != NULL)
3219 /* Output the previous message now. This can happen
3220 if there was no Update-existing or other such
3221 response, due to the -n global option. */
3222 cvs_output ("U ", 0);
3223 cvs_output (updated_fname, 0);
3224 cvs_output ("\n", 1);
3225 free (updated_fname);
3226 updated_fname = NULL;
3229 if (rs->type == response_type_error)
3236 /* Get the responses and then close the connection. */
3240 * Flag var; we'll set it in start_server() and not one of its
3241 * callees, such as start_rsh_server(). This means that there might
3242 * be a small window between the starting of the server and the
3243 * setting of this var, but all the code in that window shouldn't care
3244 * because it's busy checking return values to see if the server got
3245 * started successfully anyway.
3247 int server_started = 0;
3250 get_responses_and_close ()
3252 int errs = get_server_responses ();
3255 if (last_entries != NULL)
3257 Entries_Close (last_entries);
3258 last_entries = NULL;
3261 do_deferred_progs ();
3263 if (client_prune_dirs)
3264 process_prune_candidates ();
3266 /* The calls to buf_shutdown are currently only meaningful when we
3267 are using compression. First we shut down TO_SERVER. That
3268 tells the server that its input is finished. It then shuts
3269 down the buffer it is sending to us, at which point our shut
3270 down of FROM_SERVER will complete. */
3272 status = buf_shutdown (to_server);
3274 error (0, status, "shutting down buffer to server");
3275 status = buf_shutdown (from_server);
3277 error (0, status, "shutting down buffer from server");
3279 #ifdef NO_SOCKET_TO_FD
3280 if (use_socket_style)
3282 if (shutdown (server_sock, 2) < 0)
3283 error (1, 0, "shutting down server socket: %s", SOCK_STRERROR (SOCK_ERRNO));
3286 #endif /* NO_SOCKET_TO_FD */
3288 #if defined(HAVE_KERBEROS) || defined(AUTH_CLIENT_SUPPORT)
3289 if (server_fd != -1)
3291 if (shutdown (server_fd, 1) < 0)
3292 error (1, 0, "shutting down connection to %s: %s",
3293 CVSroot_hostname, SOCK_STRERROR (SOCK_ERRNO));
3295 * This test will always be true because we dup the descriptor
3297 if (fileno (from_server_fp) != fileno (to_server_fp))
3299 if (fclose (to_server_fp) != 0)
3301 "closing down connection to %s",
3308 #ifdef SHUTDOWN_SERVER
3309 SHUTDOWN_SERVER (fileno (to_server_fp));
3310 #else /* ! SHUTDOWN_SERVER */
3313 #ifdef START_RSH_WITH_POPEN_RW
3314 if (pclose (to_server_fp) == EOF)
3315 #else /* ! START_RSH_WITH_POPEN_RW */
3316 if (fclose (to_server_fp) == EOF)
3317 #endif /* START_RSH_WITH_POPEN_RW */
3319 error (1, errno, "closing connection to %s",
3324 if (! buf_empty_p (from_server)
3325 || getc (from_server_fp) != EOF)
3326 error (0, 0, "dying gasps from %s unexpected", CVSroot_hostname);
3327 else if (ferror (from_server_fp))
3328 error (0, errno, "reading from %s", CVSroot_hostname);
3330 fclose (from_server_fp);
3331 #endif /* SHUTDOWN_SERVER */
3335 && waitpid (rsh_pid, (int *) 0, 0) == -1)
3336 error (1, errno, "waiting for process %d", rsh_pid);
3340 /* see if we need to sleep before returning */
3341 if (last_register_time)
3346 if (now == last_register_time)
3347 sleep (1); /* to avoid time-stamp races */
3353 #ifndef NO_EXT_METHOD
3354 static void start_rsh_server PROTO((int *, int *));
3358 supported_request (name)
3363 for (rq = requests; rq->name; rq++)
3364 if (!strcmp (rq->name, name))
3365 return rq->status == rq_supported;
3366 error (1, 0, "internal error: testing support for unknown option?");
3372 #if defined (AUTH_CLIENT_SUPPORT) || defined (HAVE_KERBEROS)
3373 static struct hostent *init_sockaddr PROTO ((struct sockaddr_in *, char *,
3376 static struct hostent *
3377 init_sockaddr (name, hostname, port)
3378 struct sockaddr_in *name;
3382 struct hostent *hostinfo;
3383 unsigned short shortport = port;
3385 memset (name, 0, sizeof (*name));
3386 name->sin_family = AF_INET;
3387 name->sin_port = htons (shortport);
3388 hostinfo = gethostbyname (hostname);
3389 if (hostinfo == NULL)
3391 fprintf (stderr, "Unknown host %s.\n", hostname);
3394 name->sin_addr = *(struct in_addr *) hostinfo->h_addr;
3398 #endif /* defined (AUTH_CLIENT_SUPPORT) || defined (HAVE_KERBEROS) */
3400 #ifdef AUTH_CLIENT_SUPPORT
3402 static int auth_server_port_number PROTO ((void));
3405 auth_server_port_number ()
3407 struct servent *s = getservbyname ("cvspserver", "tcp");
3410 return ntohs (s->s_port);
3412 return CVS_AUTH_PORT;
3416 /* Read a line from socket SOCK. Result does not include the
3417 terminating linefeed. This is only used by the authentication
3418 protocol, which we call before we set up all the buffering stuff.
3419 It is possible it should use the buffers too, which would be faster
3420 (unlike the server, there isn't really a security issue in terms of
3421 separating authentication from the rest of the code).
3423 Space for the result is malloc'd and should be freed by the caller.
3425 Returns number of bytes read. */
3427 recv_line (sock, resultp)
3433 size_t input_index = 0;
3434 size_t result_size = 80;
3436 result = (char *) xmalloc (result_size);
3441 if (recv (sock, &ch, 1, 0) < 0)
3442 error (1, 0, "recv() from server %s: %s", CVSroot_hostname,
3443 SOCK_STRERROR (SOCK_ERRNO));
3450 /* It's end of file. */
3451 error (1, 0, "end of file from server");
3457 result[input_index++] = c;
3458 while (input_index + 1 >= result_size)
3461 result = (char *) xrealloc (result, result_size);
3468 /* Terminate it just for kicks, but we *can* deal with embedded NULs. */
3469 result[input_index] = '\0';
3471 if (resultp == NULL)
3476 /* Connect to the authenticating server.
3478 If VERIFY_ONLY is non-zero, then just verify that the password is
3479 correct and then shutdown the connection.
3481 If VERIFY_ONLY is 0, then really connect to the server.
3483 If DO_GSSAPI is non-zero, then we use GSSAPI authentication rather
3484 than the pserver password authentication.
3486 If we fail to connect or if access is denied, then die with fatal
3489 connect_to_pserver (tofdp, fromfdp, verify_only, do_gssapi)
3490 int *tofdp, *fromfdp;
3495 #ifndef NO_SOCKET_TO_FD
3499 struct sockaddr_in client_sai;
3500 struct hostent *hostinfo;
3502 sock = socket (AF_INET, SOCK_STREAM, 0);
3505 error (1, 0, "cannot create socket: %s", SOCK_STRERROR (SOCK_ERRNO));
3507 port_number = auth_server_port_number ();
3508 hostinfo = init_sockaddr (&client_sai, CVSroot_hostname, port_number);
3509 if (connect (sock, (struct sockaddr *) &client_sai, sizeof (client_sai))
3511 error (1, 0, "connect to %s:%d failed: %s", CVSroot_hostname,
3512 port_number, SOCK_STRERROR (SOCK_ERRNO));
3514 /* Run the authorization mini-protocol before anything else. */
3518 if (! connect_to_gserver (sock, hostinfo))
3521 error (1, 0, "This client does not support GSSAPI authentication");
3527 char *repository = CVSroot_directory;
3528 char *username = CVSroot_username;
3529 char *password = NULL;
3534 begin = "BEGIN VERIFICATION REQUEST\012";
3535 end = "END VERIFICATION REQUEST\012";
3539 begin = "BEGIN AUTH REQUEST\012";
3540 end = "END AUTH REQUEST\012";
3543 /* Get the password, probably from ~/.cvspass. */
3544 password = get_cvs_password ();
3546 /* Announce that we're starting the authorization protocol. */
3547 if (send (sock, begin, strlen (begin), 0) < 0)
3548 error (1, 0, "cannot send: %s", SOCK_STRERROR (SOCK_ERRNO));
3550 /* Send the data the server needs. */
3551 if (send (sock, repository, strlen (repository), 0) < 0)
3552 error (1, 0, "cannot send: %s", SOCK_STRERROR (SOCK_ERRNO));
3553 if (send (sock, "\012", 1, 0) < 0)
3554 error (1, 0, "cannot send: %s", SOCK_STRERROR (SOCK_ERRNO));
3555 if (send (sock, username, strlen (username), 0) < 0)
3556 error (1, 0, "cannot send: %s", SOCK_STRERROR (SOCK_ERRNO));
3557 if (send (sock, "\012", 1, 0) < 0)
3558 error (1, 0, "cannot send: %s", SOCK_STRERROR (SOCK_ERRNO));
3559 if (send (sock, password, strlen (password), 0) < 0)
3560 error (1, 0, "cannot send: %s", SOCK_STRERROR (SOCK_ERRNO));
3561 if (send (sock, "\012", 1, 0) < 0)
3562 error (1, 0, "cannot send: %s", SOCK_STRERROR (SOCK_ERRNO));
3564 /* Announce that we're ending the authorization protocol. */
3565 if (send (sock, end, strlen (end), 0) < 0)
3566 error (1, 0, "cannot send: %s", SOCK_STRERROR (SOCK_ERRNO));
3569 memset (password, 0, strlen (password));
3575 /* Loop, getting responses from the server. */
3578 recv_line (sock, &read_buf);
3580 if (strcmp (read_buf, "I HATE YOU") == 0)
3582 /* Authorization not granted. */
3585 else if (strncmp (read_buf, "E ", 2) == 0)
3587 fprintf (stderr, "%s\n", read_buf + 2);
3589 /* Continue with the authentication protocol. */
3591 else if (strncmp (read_buf, "error ", 6) == 0)
3595 /* First skip the code. */
3597 while (*p != ' ' && *p != '\0')
3600 /* Skip the space that follows the code. */
3604 /* Now output the text. */
3605 fprintf (stderr, "%s\n", p);
3608 else if (strcmp (read_buf, "I LOVE YOU") == 0)
3615 /* Unrecognized response from server. */
3616 if (shutdown (sock, 2) < 0)
3619 "unrecognized auth response from %s: %s",
3620 CVSroot_hostname, read_buf);
3622 "shutdown() failed, server %s: %s",
3624 SOCK_STRERROR (SOCK_ERRNO));
3627 "unrecognized auth response from %s: %s",
3628 CVSroot_hostname, read_buf);
3636 if (shutdown (sock, 2) < 0)
3637 error (0, 0, "shutdown() failed, server %s: %s", CVSroot_hostname,
3638 SOCK_STRERROR (SOCK_ERRNO));
3643 #ifdef NO_SOCKET_TO_FD
3644 use_socket_style = 1;
3646 /* Try to break mistaken callers: */
3649 #else /* ! NO_SOCKET_TO_FD */
3651 close_on_exec (server_fd);
3652 tofd = fromfd = sock;
3653 /* Hand them back to the caller. */
3656 #endif /* NO_SOCKET_TO_FD */
3662 if (shutdown (sock, 2) < 0)
3665 "authorization failed: server %s rejected access",
3668 "shutdown() failed (server %s): %s",
3670 SOCK_STRERROR (SOCK_ERRNO));
3674 "authorization failed: server %s rejected access",
3677 #endif /* AUTH_CLIENT_SUPPORT */
3682 /* This function has not been changed to deal with NO_SOCKET_TO_FD
3683 (i.e., systems on which sockets cannot be converted to file
3684 descriptors). The first person to try building a kerberos client
3685 on such a system (OS/2, Windows 95, and maybe others) will have to
3686 make take care of this. */
3688 start_tcp_server (tofdp, fromfdp)
3689 int *tofdp, *fromfdp;
3692 const char *portenv;
3695 struct sockaddr_in sin;
3698 s = socket (AF_INET, SOCK_STREAM, 0);
3700 error (1, 0, "cannot create socket: %s", SOCK_STRERROR (SOCK_ERRNO));
3702 /* Get CVS_CLIENT_PORT or look up cvs/tcp with CVS_PORT as default */
3703 portenv = getenv ("CVS_CLIENT_PORT");
3704 if (portenv != NULL)
3706 port = atoi (portenv);
3709 error (0, 0, "CVS_CLIENT_PORT must be a positive number! If you");
3710 error (0, 0, "are trying to force a connection via rsh, please");
3711 error (0, 0, "put \":server:\" at the beginning of your CVSROOT");
3712 error (1, 0, "variable.");
3715 fprintf(stderr, "Using TCP port %d to contact server.\n", port);
3721 sp = getservbyname ("cvs", "tcp");
3725 port = ntohs (sp->s_port);
3728 hp = init_sockaddr (&sin, CVSroot_hostname, port);
3730 hname = xmalloc (strlen (hp->h_name) + 1);
3731 strcpy (hname, hp->h_name);
3733 if (connect (s, (struct sockaddr *) &sin, sizeof sin) < 0)
3734 error (1, 0, "connect to %s:%d failed: %s", CVSroot_hostname,
3735 port, SOCK_STRERROR (SOCK_ERRNO));
3737 #ifdef HAVE_KERBEROS
3740 struct sockaddr_in laddr;
3747 realm = krb_realmofhost (hname);
3749 laddrlen = sizeof (laddr);
3750 if (getsockname (s, (struct sockaddr *) &laddr, &laddrlen) < 0)
3751 error (1, 0, "getsockname failed: %s", SOCK_STRERROR (SOCK_ERRNO));
3753 /* We don't care about the checksum, and pass it as zero. */
3754 status = krb_sendauth (KOPT_DO_MUTUAL, s, &ticket, "rcmd",
3755 hname, realm, (unsigned long) 0, &msg_data,
3756 &cred, sched, &laddr, &sin, "KCVSV1.0");
3757 if (status != KSUCCESS)
3758 error (1, 0, "kerberos authentication failed: %s",
3759 krb_get_err_text (status));
3760 memcpy (kblock, cred.session, sizeof (C_Block));
3762 #endif /* HAVE_KERBEROS */
3765 close_on_exec (server_fd);
3769 /* Give caller the values it wants. */
3774 #endif /* HAVE_KERBEROS */
3778 /* Receive a given number of bytes. */
3781 recv_bytes (sock, buf, need)
3790 got = recv (sock, buf, need, 0);
3792 error (1, 0, "recv() from server %s: %s", CVSroot_hostname,
3793 SOCK_STRERROR (SOCK_ERRNO));
3799 /* Connect to the server using GSSAPI authentication. */
3802 connect_to_gserver (sock, hostinfo)
3804 struct hostent *hostinfo;
3808 gss_buffer_desc *tok_in_ptr, tok_in, tok_out;
3809 OM_uint32 stat_min, stat_maj;
3810 gss_name_t server_name;
3812 str = "BEGIN GSSAPI REQUEST\012";
3814 if (send (sock, str, strlen (str), 0) < 0)
3815 error (1, 0, "cannot send: %s", SOCK_STRERROR (SOCK_ERRNO));
3817 sprintf (buf, "cvs@%s", hostinfo->h_name);
3818 tok_in.length = strlen (buf);
3820 gss_import_name (&stat_min, &tok_in, gss_nt_service_name, &server_name);
3822 tok_in_ptr = GSS_C_NO_BUFFER;
3823 gcontext = GSS_C_NO_CONTEXT;
3827 stat_maj = gss_init_sec_context (&stat_min, GSS_C_NO_CREDENTIAL,
3828 &gcontext, server_name,
3831 | GSS_C_REPLAY_FLAG),
3832 0, NULL, tok_in_ptr, NULL, &tok_out,
3834 if (stat_maj != GSS_S_COMPLETE && stat_maj != GSS_S_CONTINUE_NEEDED)
3836 OM_uint32 message_context;
3838 message_context = 0;
3839 gss_display_status (&stat_min, stat_maj, GSS_C_GSS_CODE,
3840 GSS_C_NULL_OID, &message_context, &tok_out);
3841 error (1, 0, "GSSAPI authentication failed: %s",
3842 (char *) tok_out.value);
3845 if (tok_out.length == 0)
3854 cbuf[0] = (tok_out.length >> 8) & 0xff;
3855 cbuf[1] = tok_out.length & 0xff;
3856 if (send (sock, cbuf, 2, 0) < 0)
3857 error (1, 0, "cannot send: %s", SOCK_STRERROR (SOCK_ERRNO));
3858 if (send (sock, tok_out.value, tok_out.length, 0) < 0)
3859 error (1, 0, "cannot send: %s", SOCK_STRERROR (SOCK_ERRNO));
3861 recv_bytes (sock, cbuf, 2);
3862 need = ((cbuf[0] & 0xff) << 8) | (cbuf[1] & 0xff);
3863 assert (need <= sizeof buf);
3864 recv_bytes (sock, buf, need);
3865 tok_in.length = need;
3869 tok_in_ptr = &tok_in;
3871 while (stat_maj == GSS_S_CONTINUE_NEEDED);
3876 #endif /* HAVE_GSSAPI */
3878 static int send_variable_proc PROTO ((Node *, void *));
3881 send_variable_proc (node, closure)
3885 send_to_server ("Set ", 0);
3886 send_to_server (node->key, 0);
3887 send_to_server ("=", 1);
3888 send_to_server (node->data, 0);
3889 send_to_server ("\012", 1);
3893 /* Contact the server. */
3898 char *log = getenv ("CVS_CLIENT_LOG");
3900 /* Note that generally speaking we do *not* fall back to a different
3901 way of connecting if the first one does not work. This is slow
3902 (*really* slow on a 14.4kbps link); the clean way to have a CVS
3903 which supports several ways of connecting is with access methods. */
3905 switch (CVSroot_method)
3908 #ifdef AUTH_CLIENT_SUPPORT
3909 case pserver_method:
3910 /* Toss the return value. It will die with error if anything
3911 goes wrong anyway. */
3912 connect_to_pserver (&tofd, &fromfd, 0, 0);
3917 case kserver_method:
3918 start_tcp_server (&tofd, &fromfd);
3923 case gserver_method:
3924 /* GSSAPI authentication is handled by the pserver. */
3925 connect_to_pserver (&tofd, &fromfd, 0, 1);
3930 #if defined (NO_EXT_METHOD)
3931 error (0, 0, ":ext: method not supported by this port of CVS");
3932 error (1, 0, "try :server: instead");
3934 start_rsh_server (&tofd, &fromfd);
3939 #if defined(START_SERVER)
3940 START_SERVER (&tofd, &fromfd, getcaller (),
3941 CVSroot_username, CVSroot_hostname,
3943 # if defined (START_SERVER_RETURNS_SOCKET) && defined (NO_SOCKET_TO_FD)
3944 /* This is a system on which we can only write to a socket
3945 using send/recv. Therefore its START_SERVER needs to
3947 use_socket_style = 1;
3952 /* FIXME: It should be possible to implement this portably,
3953 like pserver, which would get rid of the duplicated code
3954 in {vms,windows-NT,...}/startserver.c. */
3956 the :server: access method is not supported by this port of CVS");
3962 (start_server internal error): unknown access method");
3966 /* "Hi, I'm Darlene and I'll be your server tonight..." */
3969 #ifdef NO_SOCKET_TO_FD
3970 if (use_socket_style)
3972 to_server = socket_buffer_initialize (server_sock, 0,
3974 from_server = socket_buffer_initialize (server_sock, 1,
3978 #endif /* NO_SOCKET_TO_FD */
3980 /* todo: some OS's don't need these calls... */
3981 close_on_exec (tofd);
3982 close_on_exec (fromfd);
3984 /* SCO 3 and AIX have a nasty bug in the I/O libraries which precludes
3985 fdopening the same file descriptor twice, so dup it if it is the
3989 fromfd = dup (tofd);
3991 error (1, errno, "cannot dup net connection");
3994 /* These will use binary mode on systems which have it. */
3995 to_server_fp = fdopen (tofd, FOPEN_BINARY_WRITE);
3996 if (to_server_fp == NULL)
3997 error (1, errno, "cannot fdopen %d for write", tofd);
3998 to_server = stdio_buffer_initialize (to_server_fp, 0,
4001 from_server_fp = fdopen (fromfd, FOPEN_BINARY_READ);
4002 if (from_server_fp == NULL)
4003 error (1, errno, "cannot fdopen %d for read", fromfd);
4004 from_server = stdio_buffer_initialize (from_server_fp, 1,
4008 /* Set up logfiles, if any. */
4011 int len = strlen (log);
4012 char *buf = xmalloc (len + 5);
4019 /* Open logfiles in binary mode so that they reflect
4020 exactly what was transmitted and received (that is
4021 more important than that they be maximally
4022 convenient to view). */
4023 /* Note that if we create several connections in a single CVS client
4024 (currently used by update.c), then the last set of logfiles will
4025 overwrite the others. There is currently no way around this. */
4027 fp = open_file (buf, "wb");
4029 error (0, errno, "opening to-server logfile %s", buf);
4031 to_server = log_buffer_initialize (to_server, fp, 0,
4035 fp = open_file (buf, "wb");
4037 error (0, errno, "opening from-server logfile %s", buf);
4039 from_server = log_buffer_initialize (from_server, fp, 1,
4045 /* Clear static variables. */
4046 if (toplevel_repos != NULL)
4047 free (toplevel_repos);
4048 toplevel_repos = NULL;
4049 if (last_dir_name != NULL)
4050 free (last_dir_name);
4051 last_dir_name = NULL;
4052 if (last_repos != NULL)
4055 if (last_update_dir != NULL)
4056 free (last_update_dir);
4057 last_update_dir = NULL;
4058 stored_checksum_valid = 0;
4059 stored_mode_valid = 0;
4061 if (strcmp (command_name, "init") != 0)
4063 send_to_server ("Root ", 0);
4064 send_to_server (CVSroot_directory, 0);
4065 send_to_server ("\012", 1);
4069 struct response *rs;
4071 send_to_server ("Valid-responses", 0);
4073 for (rs = responses; rs->name != NULL; ++rs)
4075 send_to_server (" ", 0);
4076 send_to_server (rs->name, 0);
4078 send_to_server ("\012", 1);
4080 send_to_server ("valid-requests\012", 0);
4082 if (get_server_responses ())
4086 * Now handle global options.
4088 * -H, -f, -d, -e should be handled OK locally.
4090 * -b we ignore (treating it as a server installation issue).
4091 * FIXME: should be an error message.
4093 * -v we print local version info; FIXME: Add a protocol request to get
4094 * the version from the server so we can print that too.
4096 * -l -t -r -w -q -n and -Q need to go to the server.
4100 int have_global = supported_request ("Global_option");
4106 send_to_server ("Global_option -n\012", 0);
4110 "This server does not support the global -n option.");
4116 send_to_server ("Global_option -q\012", 0);
4120 "This server does not support the global -q option.");
4126 send_to_server ("Global_option -Q\012", 0);
4130 "This server does not support the global -Q option.");
4136 send_to_server ("Global_option -r\012", 0);
4140 "This server does not support the global -r option.");
4146 send_to_server ("Global_option -t\012", 0);
4150 "This server does not support the global -t option.");
4156 send_to_server ("Global_option -l\012", 0);
4160 "This server does not support the global -l option.");
4167 /* Turn on encryption before turning on compression. We do
4168 not want to try to compress the encrypted stream. Instead,
4169 we want to encrypt the compressed stream. If we can't turn
4170 on encryption, bomb out; don't let the user think the data
4171 is being encrypted when it is not. */
4172 #ifdef HAVE_KERBEROS
4173 if (CVSroot_method == kserver_method)
4175 if (! supported_request ("Kerberos-encrypt"))
4176 error (1, 0, "This server does not support encryption");
4177 send_to_server ("Kerberos-encrypt\012", 0);
4178 to_server = krb_encrypt_buffer_initialize (to_server, 0, sched,
4181 from_server = krb_encrypt_buffer_initialize (from_server, 1,
4186 #endif /* HAVE_KERBEROS */
4188 if (CVSroot_method == gserver_method)
4190 if (! supported_request ("Gssapi-encrypt"))
4191 error (1, 0, "This server does not support encryption");
4192 send_to_server ("Gssapi-encrypt\012", 0);
4193 to_server = cvs_gssapi_wrap_buffer_initialize (to_server, 0,
4196 from_server = cvs_gssapi_wrap_buffer_initialize (from_server, 1,
4199 cvs_gssapi_encrypt = 1;
4202 #endif /* HAVE_GSSAPI */
4203 error (1, 0, "Encryption is only supported when using GSSAPI or Kerberos");
4204 #else /* ! ENCRYPTION */
4205 error (1, 0, "This client does not support encryption");
4206 #endif /* ! ENCRYPTION */
4211 if (supported_request ("Gzip-stream"))
4213 char gzip_level_buf[5];
4214 send_to_server ("Gzip-stream ", 0);
4215 sprintf (gzip_level_buf, "%d", gzip_level);
4216 send_to_server (gzip_level_buf, 0);
4217 send_to_server ("\012", 1);
4219 /* All further communication with the server will be
4222 to_server = compress_buffer_initialize (to_server, 0, gzip_level,
4224 from_server = compress_buffer_initialize (from_server, 1,
4228 #ifndef NO_CLIENT_GZIP_PROCESS
4229 else if (supported_request ("gzip-file-contents"))
4231 char gzip_level_buf[5];
4232 send_to_server ("gzip-file-contents ", 0);
4233 sprintf (gzip_level_buf, "%d", gzip_level);
4234 send_to_server (gzip_level_buf, 0);
4236 send_to_server ("\012", 1);
4238 file_gzip_level = gzip_level;
4243 fprintf (stderr, "server doesn't support gzip-file-contents\n");
4244 /* Setting gzip_level to 0 prevents us from giving the
4245 error twice if update has to contact the server again
4246 to fetch unpatchable files. */
4251 if (cvsauthenticate && ! cvsencrypt)
4253 /* Turn on authentication after turning on compression, so
4254 that we can compress the authentication information. We
4255 assume that encrypted data is always authenticated--the
4256 ability to decrypt the data stream is itself a form of
4259 if (CVSroot_method == gserver_method)
4261 if (! supported_request ("Gssapi-authenticate"))
4263 "This server does not support stream authentication");
4264 send_to_server ("Gssapi-authenticate\012", 0);
4265 to_server = cvs_gssapi_wrap_buffer_initialize (to_server, 0,
4268 from_server = cvs_gssapi_wrap_buffer_initialize (from_server, 1,
4273 error (1, 0, "Stream authentication is only supported when using GSSAPI");
4274 #else /* ! HAVE_GSSAPI */
4275 error (1, 0, "This client does not support stream authentication");
4276 #endif /* ! HAVE_GSSAPI */
4279 #ifdef FILENAMES_CASE_INSENSITIVE
4280 if (supported_request ("Case"))
4281 send_to_server ("Case\012", 0);
4284 /* If "Set" is not supported, just silently fail to send the variables.
4285 Users with an old server should get a useful error message when it
4286 fails to recognize the ${=foo} syntax. This way if someone uses
4287 several servers, some of which are new and some old, they can still
4288 set user variables in their .cvsrc without trouble. */
4289 if (supported_request ("Set"))
4290 walklist (variable_list, send_variable_proc, NULL);
4293 #ifndef NO_EXT_METHOD
4295 /* Contact the server by starting it with rsh. */
4297 /* Right now, we have two different definitions for this function,
4298 depending on whether we start the rsh server using popenRW or not.
4299 This isn't ideal, and the best thing would probably be to change
4300 the OS/2 port to be more like the regular Unix client (i.e., by
4301 implementing piped_child)... but I'm doing something else at the
4302 moment, and wish to make only one change at a time. -Karl */
4304 #ifdef START_RSH_WITH_POPEN_RW
4306 /* This is actually a crock -- it's OS/2-specific, for no one else
4307 uses it. If I get time, I want to make piped_child and all the
4308 other stuff in os2/run.c work right. In the meantime, this gets us
4309 up and running, and that's most important. */
4312 start_rsh_server (tofdp, fromfdp)
4313 int *tofdp, *fromfdp;
4317 /* If you're working through firewalls, you can set the
4318 CVS_RSH environment variable to a script which uses rsh to
4319 invoke another rsh on a proxy machine. */
4320 char *cvs_rsh = getenv ("CVS_RSH");
4321 char *cvs_server = getenv ("CVS_SERVER");
4323 /* This needs to fit "rsh", "-b", "-l", "USER", "host",
4324 "cmd (w/ args)", and NULL. We leave some room to grow. */
4328 /* People sometimes suggest or assume that this should default
4329 to "remsh" on systems like HPUX in which that is the
4330 system-supplied name for the rsh program. However, that
4331 causes various problems (keep in mind that systems such as
4332 HPUX might have non-system-supplied versions of "rsh", like
4333 a Kerberized one, which one might want to use). If we
4334 based the name on what is found in the PATH of the person
4335 who runs configure, that would make it harder to
4336 consistently produce the same result in the face of
4337 different people producing binary distributions. If we
4338 based it on "remsh" always being the default for HPUX
4339 (e.g. based on uname), that might be slightly better but
4340 would require us to keep track of what the defaults are for
4341 each system type, and probably would cope poorly if the
4342 existence of remsh or rsh varies from OS version to OS
4343 version. Therefore, it seems best to have the default
4344 remain "rsh", and tell HPUX users to specify remsh, for
4345 example in CVS_RSH or other such mechanisms to be devised,
4346 if that is what they want (the manual already tells them
4352 /* The command line starts out with rsh. */
4353 rsh_argv[i++] = cvs_rsh;
4355 #ifdef RSH_NEEDS_BINARY_FLAG
4356 /* "-b" for binary, under OS/2. */
4357 rsh_argv[i++] = "-b";
4358 #endif /* RSH_NEEDS_BINARY_FLAG */
4360 /* Then we strcat more things on the end one by one. */
4361 if (CVSroot_username != NULL)
4363 rsh_argv[i++] = "-l";
4364 rsh_argv[i++] = CVSroot_username;
4367 rsh_argv[i++] = CVSroot_hostname;
4368 rsh_argv[i++] = cvs_server;
4369 rsh_argv[i++] = "server";
4371 /* Mark the end of the arg list. */
4372 rsh_argv[i] = (char *) NULL;
4376 fprintf (stderr, " -> Starting server: ");
4377 putc ('\n', stderr);
4381 rsh_pid = popenRW (rsh_argv, pipes);
4383 error (1, errno, "cannot start server via rsh");
4385 /* Give caller the file descriptors. */
4387 *fromfdp = pipes[1];
4390 #else /* ! START_RSH_WITH_POPEN_RW */
4393 start_rsh_server (tofdp, fromfdp)
4397 /* If you're working through firewalls, you can set the
4398 CVS_RSH environment variable to a script which uses rsh to
4399 invoke another rsh on a proxy machine. */
4400 char *cvs_rsh = getenv ("CVS_RSH");
4401 char *cvs_server = getenv ("CVS_SERVER");
4409 /* Pass the command to rsh as a single string. This shouldn't
4410 affect most rsh servers at all, and will pacify some buggy
4411 versions of rsh that grab switches out of the middle of the
4412 command (they're calling the GNU getopt routines incorrectly). */
4413 command = xmalloc (strlen (cvs_server)
4414 + strlen (CVSroot_directory)
4417 /* If you are running a very old (Nov 3, 1994, before 1.5)
4418 * version of the server, you need to make sure that your .bashrc
4419 * on the server machine does not set CVSROOT to something
4420 * containing a colon (or better yet, upgrade the server). */
4421 sprintf (command, "%s server", cvs_server);
4428 *p++ = CVSroot_hostname;
4430 /* If the login names differ between client and server
4431 * pass it on to rsh.
4433 if (CVSroot_username != NULL)
4436 *p++ = CVSroot_username;
4446 fprintf (stderr, " -> Starting server: ");
4447 for (i = 0; argv[i]; i++)
4448 fprintf (stderr, "%s ", argv[i]);
4449 putc ('\n', stderr);
4451 rsh_pid = piped_child (argv, tofdp, fromfdp);
4454 error (1, errno, "cannot start server via rsh");
4459 #endif /* START_RSH_WITH_POPEN_RW */
4461 #endif /* NO_EXT_METHOD */
4465 /* Send an argument STRING. */
4473 send_to_server ("Argument ", 0);
4479 send_to_server ("\012Argumentx ", 0);
4484 send_to_server (buf, 1);
4488 send_to_server ("\012", 1);
4491 static void send_modified PROTO ((char *, char *, Vers_TS *));
4493 /* VERS->OPTIONS specifies whether the file is binary or not. NOTE: BEFORE
4494 using any other fields of the struct vers, we would need to fix
4495 client_process_import_file to set them up. */
4498 send_modified (file, short_pathname, vers)
4500 char *short_pathname;
4503 /* File was modified, send it. */
4512 (void) fprintf (stderr, " -> Sending file `%s' to server\n", file);
4514 /* Don't think we can assume fstat exists. */
4515 if ( CVS_STAT (file, &sb) < 0)
4516 error (1, errno, "reading %s", short_pathname);
4518 mode_string = mode_to_string (sb.st_mode);
4520 /* Beware: on systems using CRLF line termination conventions,
4521 the read and write functions will convert CRLF to LF, so the
4522 number of characters read is not the same as sb.st_size. Text
4523 files should always be transmitted using the LF convention, so
4524 we don't want to disable this conversion. */
4525 bufsize = sb.st_size;
4526 buf = xmalloc (bufsize);
4528 /* Is the file marked as containing binary data by the "-kb" flag?
4529 If so, make sure to open it in binary mode: */
4531 if (vers && vers->options)
4532 bin = !(strcmp (vers->options, "-kb"));
4536 #ifdef BROKEN_READWRITE_CONVERSION
4539 /* If only stdio, not open/write/etc., do text/binary
4540 conversion, use convert_file which can compensate
4541 (FIXME: we could just use stdio instead which would
4542 avoid the whole problem). */
4543 char tfile[1024]; strcpy(tfile, file); strcat(tfile, ".CVSBFCTMP");
4544 convert_file (file, O_RDONLY,
4545 tfile, O_WRONLY | O_CREAT | O_TRUNC | OPEN_BINARY);
4546 fd = CVS_OPEN (tfile, O_RDONLY | OPEN_BINARY);
4548 error (1, errno, "reading %s", short_pathname);
4551 fd = CVS_OPEN (file, O_RDONLY | OPEN_BINARY);
4553 fd = CVS_OPEN (file, O_RDONLY | (bin ? OPEN_BINARY : 0));
4557 error (1, errno, "reading %s", short_pathname);
4559 if (file_gzip_level && sb.st_size > 100)
4563 read_and_gzip (fd, short_pathname, (unsigned char **)&buf,
4568 error (0, errno, "warning: can't close %s", short_pathname);
4573 send_to_server ("Modified ", 0);
4574 send_to_server (file, 0);
4575 send_to_server ("\012", 1);
4576 send_to_server (mode_string, 0);
4577 send_to_server ("\012z", 2);
4578 sprintf (tmp, "%lu\n", (unsigned long) newsize);
4579 send_to_server (tmp, 0);
4581 send_to_server (buf, newsize);
4592 /* FIXME: This is gross. It assumes that we might read
4593 less than st_size bytes (true on NT), but not more.
4594 Instead of this we should just be reading a block of
4595 data (e.g. 8192 bytes), writing it to the network, and
4597 while ((len = read (fd, bufp, (buf + sb.st_size) - bufp)) > 0)
4601 error (1, errno, "reading %s", short_pathname);
4603 newsize = bufp - buf;
4606 error (0, errno, "warning: can't close %s", short_pathname);
4611 send_to_server ("Modified ", 0);
4612 send_to_server (file, 0);
4613 send_to_server ("\012", 1);
4614 send_to_server (mode_string, 0);
4615 send_to_server ("\012", 1);
4616 sprintf (tmp, "%lu\012", (unsigned long) newsize);
4617 send_to_server (tmp, 0);
4619 #ifdef BROKEN_READWRITE_CONVERSION
4622 char tfile[1024]; strcpy(tfile, file); strcat(tfile, ".CVSBFCTMP");
4623 if (CVS_UNLINK (tfile) < 0)
4624 error (0, errno, "warning: can't remove temp file %s", tfile);
4629 * Note that this only ends with a newline if the file ended with
4633 send_to_server (buf, newsize);
4639 /* The address of an instance of this structure is passed to
4640 send_fileproc, send_filesdoneproc, and send_direntproc, as the
4641 callerdat parameter. */
4645 /* Each of the following flags are zero for clear or nonzero for set. */
4651 static int send_fileproc PROTO ((void *callerdat, struct file_info *finfo));
4653 /* Deal with one file. */
4655 send_fileproc (callerdat, finfo)
4657 struct file_info *finfo;
4659 struct send_data *args = (struct send_data *) callerdat;
4661 struct file_info xfinfo;
4662 /* File name to actually use. Might differ in case from
4666 send_a_repository ("", finfo->repository, finfo->update_dir);
4669 xfinfo.repository = NULL;
4671 vers = Version_TS (&xfinfo, NULL, NULL, NULL, 0, 0);
4673 if (vers->entdata != NULL)
4674 filename = vers->entdata->user;
4676 filename = finfo->file;
4678 if (vers->vn_user != NULL)
4680 /* The Entries request. */
4681 send_to_server ("Entry /", 0);
4682 send_to_server (filename, 0);
4683 send_to_server ("/", 0);
4684 send_to_server (vers->vn_user, 0);
4685 send_to_server ("/", 0);
4686 if (vers->ts_conflict != NULL)
4688 if (vers->ts_user != NULL &&
4689 strcmp (vers->ts_conflict, vers->ts_user) == 0)
4690 send_to_server ("+=", 0);
4692 send_to_server ("+modified", 0);
4694 send_to_server ("/", 0);
4695 send_to_server (vers->entdata != NULL
4696 ? vers->entdata->options
4699 send_to_server ("/", 0);
4700 if (vers->entdata != NULL && vers->entdata->tag)
4702 send_to_server ("T", 0);
4703 send_to_server (vers->entdata->tag, 0);
4705 else if (vers->entdata != NULL && vers->entdata->date)
4707 send_to_server ("D", 0);
4708 send_to_server (vers->entdata->date, 0);
4710 send_to_server ("\012", 1);
4714 /* It seems a little silly to re-read this on each file, but
4715 send_dirent_proc doesn't get called if filenames are specified
4716 explicitly on the command line. */
4717 wrap_add_file (CVSDOTWRAPPER, 1);
4719 if (wrap_name_has (filename, WRAP_RCSOPTION))
4721 /* No "Entry", but the wrappers did give us a kopt so we better
4722 send it with "Kopt". As far as I know this only happens
4723 for "cvs add". Question: is there any reason why checking
4724 for options from wrappers isn't done in Version_TS?
4726 Note: it might have been better to just remember all the
4727 kopts on the client side, rather than send them to the server,
4728 and have it send us back the same kopts. But that seemed like
4729 a bigger change than I had in mind making now. */
4731 if (supported_request ("Kopt"))
4735 send_to_server ("Kopt ", 0);
4736 opt = wrap_rcsoption (filename, 1);
4737 send_to_server (opt, 0);
4738 send_to_server ("\012", 1);
4744 warning: ignoring -k options due to server limitations");
4748 if (vers->ts_user == NULL)
4751 * Do we want to print "file was lost" like normal CVS?
4752 * Would it always be appropriate?
4754 /* File no longer exists. Don't do anything, missing files
4757 else if (vers->ts_rcs == NULL
4759 || strcmp (vers->ts_user, vers->ts_rcs) != 0)
4761 if (args->no_contents
4762 && supported_request ("Is-modified"))
4764 send_to_server ("Is-modified ", 0);
4765 send_to_server (filename, 0);
4766 send_to_server ("\012", 1);
4769 send_modified (filename, finfo->fullname, vers);
4773 send_to_server ("Unchanged ", 0);
4774 send_to_server (filename, 0);
4775 send_to_server ("\012", 1);
4778 /* if this directory has an ignore list, add this file to it */
4785 p->key = xstrdup (finfo->file);
4786 (void) addnode (ignlist, p);
4789 freevers_ts (&vers);
4793 static void send_ignproc PROTO ((char *, char *));
4796 send_ignproc (file, dir)
4800 if (ign_inhibit_server || !supported_request ("Questionable"))
4803 (void) printf ("? %s/%s\n", dir, file);
4805 (void) printf ("? %s\n", file);
4809 send_to_server ("Questionable ", 0);
4810 send_to_server (file, 0);
4811 send_to_server ("\012", 1);
4815 static int send_filesdoneproc PROTO ((void *, int, char *, char *, List *));
4818 send_filesdoneproc (callerdat, err, repository, update_dir, entries)
4825 /* if this directory has an ignore list, process it then free it */
4828 ignore_files (ignlist, entries, update_dir, send_ignproc);
4835 static Dtype send_dirent_proc PROTO ((void *, char *, char *, char *, List *));
4838 * send_dirent_proc () is called back by the recursion processor before a
4839 * sub-directory is processed for update.
4840 * A return code of 0 indicates the directory should be
4841 * processed by the recursion code. A return of non-zero indicates the
4842 * recursion code should skip this directory.
4846 send_dirent_proc (callerdat, dir, repository, update_dir, entries)
4853 struct send_data *args = (struct send_data *) callerdat;
4857 if (ignore_directory (update_dir))
4859 /* print the warm fuzzy message */
4861 error (0, 0, "Ignoring %s", update_dir);
4862 return (R_SKIP_ALL);
4866 * If the directory does not exist yet (e.g. "cvs update -d foo"),
4867 * no need to send any files from it. If the directory does not
4868 * have a CVS directory, then we pretend that it does not exist.
4869 * Otherwise, we will fail when trying to open the Entries file.
4870 * This case will happen when checking out a module defined as
4873 cvsadm_name = xmalloc (strlen (dir) + sizeof (CVSADM) + 10);
4874 sprintf (cvsadm_name, "%s/%s", dir, CVSADM);
4875 dir_exists = isdir (cvsadm_name);
4878 /* initialize the ignore list for this directory */
4879 ignlist = getlist ();
4882 * If there is an empty directory (e.g. we are doing `cvs add' on a
4883 * newly-created directory), the server still needs to know about it.
4889 * Get the repository from a CVS/Repository file whenever possible.
4890 * The repository variable is wrong if the names in the local
4891 * directory don't match the names in the repository.
4893 char *repos = Name_Repository (dir, update_dir);
4894 send_a_repository (dir, repos, update_dir);
4899 /* It doesn't make sense to send a non-existent directory,
4900 because there is no way to get the correct value for
4901 the repository (I suppose maybe via the expand-modules
4902 request). In the case where the "obvious" choice for
4903 repository is correct, the server can figure out whether
4904 to recreate the directory; in the case where it is wrong
4905 (that is, does not match what modules give us), we might as
4906 well just fail to recreate it.
4908 Checking for noexec is a kludge for "cvs -n add dir". */
4909 /* Don't send a non-existent directory unless we are building
4910 new directories (build_dirs is true). Otherwise, CVS may
4911 see a D line in an Entries file, and recreate a directory
4912 which the user removed by hand. */
4913 if (args->build_dirs && noexec)
4914 send_a_repository (dir, repository, update_dir);
4917 return (dir_exists ? R_PROCESS : R_SKIP_ALL);
4921 * Send each option in a string to the server, one by one.
4922 * This assumes that the options are separated by spaces, for example
4923 * STRING might be "--foo -C5 -y".
4927 send_option_string (string)
4933 copy = xstrdup (string);
4940 for (s = p; *s != ' ' && *s != '\0'; s++)
4954 /* Send the names of all the argument files to the server. */
4957 send_file_names (argc, argv, flags)
4966 /* The fact that we do this here as well as start_recursion is a bit
4967 of a performance hit. Perhaps worth cleaning up someday. */
4968 if (flags & SEND_EXPAND_WILD)
4969 expand_wild (argc, argv, &argc, &argv);
4971 /* Send Max-dotdot if needed. */
4973 for (i = 0; i < argc; ++i)
4975 level = pathname_levels (argv[i]);
4976 if (level > max_level)
4981 if (supported_request ("Max-dotdot"))
4984 sprintf (buf, "%d", max_level);
4986 send_to_server ("Max-dotdot ", 0);
4987 send_to_server (buf, 0);
4988 send_to_server ("\012", 1);
4992 * "leading .." is not strictly correct, as this also includes
4993 * cases like "foo/../..". But trying to explain that in the
4994 * error message would probably just confuse users.
4997 "leading .. not supported by old (pre-Max-dotdot) servers");
5000 for (i = 0; i < argc; ++i)
5006 #ifdef FILENAMES_CASE_INSENSITIVE
5007 /* We want to send the file name as it appears
5008 in CVS/Entries. We put this inside an ifdef
5009 to avoid doing all these system calls in
5010 cases where fncmp is just strcmp anyway. */
5011 /* For now just do this for files in the local
5012 directory. Would be nice to handle the
5013 non-local case too, though. */
5014 /* The isdir check could more gracefully be replaced
5015 with a way of having Entries_Open report back the
5016 error to us and letting us ignore existence_error.
5018 if (p == last_component (p) && isdir (CVSADM))
5023 /* If we were doing non-local directory,
5024 we would save_cwd, CVS_CHDIR
5025 like in update.c:isemptydir. */
5026 /* Note that if we are adding a directory,
5027 the following will read the entry
5028 that we just wrote there, that is, we
5029 will get the case specified on the
5030 command line, not the case of the
5031 directory in the filesystem. This
5032 is correct behavior. */
5033 entries = Entries_Open (0);
5034 node = findnode_fn (entries, p);
5037 line = xstrdup (node->key);
5041 Entries_Close (entries);
5043 #endif /* FILENAMES_CASE_INSENSITIVE */
5045 send_to_server ("Argument ", 0);
5051 send_to_server ("\012Argumentx ", 0);
5053 else if (ISDIRSEP (*p))
5056 send_to_server (buf, 1);
5061 send_to_server (buf, 1);
5065 send_to_server ("\012", 1);
5070 if (flags & SEND_EXPAND_WILD)
5073 for (i = 0; i < argc; ++i)
5080 /* Send Repository, Modified and Entry. argc and argv contain only
5081 the files to operate on (or empty for everything), not options.
5082 local is nonzero if we should not recurse (-l option). flags &
5083 SEND_BUILD_DIRS is nonzero if nonexistent directories should be
5084 sent. flags & SEND_FORCE is nonzero if we should send unmodified
5085 files to the server as though they were modified. flags &
5086 SEND_NO_CONTENTS means that this command only needs to know
5087 _whether_ a file is modified, not the contents. Also sends Argument
5088 lines for argc and argv, so should be called after options are sent. */
5090 send_files (argc, argv, local, aflag, flags)
5097 struct send_data args;
5101 * aflag controls whether the tag/date is copied into the vers_ts.
5102 * But we don't actually use it, so I don't think it matters what we pass
5105 args.build_dirs = flags & SEND_BUILD_DIRS;
5106 args.force = flags & SEND_FORCE;
5107 args.no_contents = flags & SEND_NO_CONTENTS;
5108 err = start_recursion
5109 (send_fileproc, send_filesdoneproc,
5110 send_dirent_proc, (DIRLEAVEPROC)NULL, (void *) &args,
5111 argc, argv, local, W_LOCAL, aflag, 0, (char *)NULL, 0);
5114 if (toplevel_repos == NULL)
5116 * This happens if we are not processing any files,
5117 * or for checkouts in directories without any existing stuff
5118 * checked out. The following assignment is correct for the
5119 * latter case; I don't think toplevel_repos matters for the
5122 toplevel_repos = xstrdup (CVSroot_directory);
5123 send_repository ("", toplevel_repos, ".");
5127 client_import_setup (repository)
5130 if (toplevel_repos == NULL) /* should always be true */
5131 send_a_repository ("", repository, "");
5135 * Process the argument import file.
5138 client_process_import_file (message, vfile, vtag, targc, targv, repository,
5146 int all_files_binary;
5152 assert (toplevel_repos != NULL);
5154 if (strncmp (repository, toplevel_repos, strlen (toplevel_repos)) != 0)
5156 "internal error: pathname `%s' doesn't specify file in `%s'",
5157 repository, toplevel_repos);
5159 if (strcmp (repository, toplevel_repos) == 0)
5162 fullname = xstrdup (vfile);
5166 update_dir = repository + strlen (toplevel_repos) + 1;
5168 fullname = xmalloc (strlen (vfile) + strlen (update_dir) + 10);
5169 strcpy (fullname, update_dir);
5170 strcat (fullname, "/");
5171 strcat (fullname, vfile);
5174 send_a_repository ("", repository, update_dir);
5175 if (all_files_binary)
5177 vers.options = xmalloc (4); /* strlen("-kb") + 1 */
5178 strcpy (vers.options, "-kb");
5182 vers.options = wrap_rcsoption (vfile, 1);
5184 if (vers.options != NULL)
5186 if (supported_request ("Kopt"))
5188 send_to_server ("Kopt ", 0);
5189 send_to_server (vers.options, 0);
5190 send_to_server ("\012", 1);
5194 "warning: ignoring -k options due to server limitations");
5196 send_modified (vfile, fullname, &vers);
5197 if (vers.options != NULL)
5198 free (vers.options);
5204 client_import_done ()
5206 if (toplevel_repos == NULL)
5208 * This happens if we are not processing any files,
5209 * or for checkouts in directories without any existing stuff
5210 * checked out. The following assignment is correct for the
5211 * latter case; I don't think toplevel_repos matters for the
5214 /* FIXME: "can't happen" now that we call client_import_setup
5215 at the beginning. */
5216 toplevel_repos = xstrdup (CVSroot_directory);
5217 send_repository ("", toplevel_repos, ".");
5221 notified_a_file (data, ent_list, short_pathname, filename)
5224 char *short_pathname;
5229 size_t line_len = 8192;
5230 char *line = xmalloc (line_len);
5236 fp = open_file (CVSADM_NOTIFY, "r");
5237 if (getline (&line, &line_len, fp) < 0)
5240 error (0, 0, "cannot read %s: end of file", CVSADM_NOTIFY);
5242 error (0, errno, "cannot read %s", CVSADM_NOTIFY);
5245 cp = strchr (line, '\t');
5248 error (0, 0, "malformed %s file", CVSADM_NOTIFY);
5252 if (strcmp (filename, line + 1) != 0)
5254 error (0, 0, "protocol error: notified %s, expected %s", filename,
5258 if (getline (&line, &line_len, fp) < 0)
5263 if (fclose (fp) < 0)
5264 error (0, errno, "cannot close %s", CVSADM_NOTIFY);
5265 if ( CVS_UNLINK (CVSADM_NOTIFY) < 0)
5266 error (0, errno, "cannot remove %s", CVSADM_NOTIFY);
5271 error (0, errno, "cannot read %s", CVSADM_NOTIFY);
5275 newf = open_file (CVSADM_NOTIFYTMP, "w");
5276 if (fputs (line, newf) < 0)
5278 error (0, errno, "cannot write %s", CVSADM_NOTIFYTMP);
5281 while ((nread = fread (line, 1, line_len, fp)) > 0)
5284 while ((nwritten = fwrite (p, 1, nread, newf)) > 0)
5291 error (0, errno, "cannot write %s", CVSADM_NOTIFYTMP);
5297 error (0, errno, "cannot read %s", CVSADM_NOTIFY);
5300 if (fclose (newf) < 0)
5302 error (0, errno, "cannot close %s", CVSADM_NOTIFYTMP);
5306 if (fclose (fp) < 0)
5308 error (0, errno, "cannot close %s", CVSADM_NOTIFY);
5313 /* In this case, we want rename_file() to ignore noexec. */
5314 int saved_noexec = noexec;
5316 rename_file (CVSADM_NOTIFYTMP, CVSADM_NOTIFY);
5317 noexec = saved_noexec;
5322 (void) fclose (newf);
5329 handle_notified (args, len)
5333 call_in_directory (args, notified_a_file, NULL);
5337 client_notify (repository, update_dir, filename, notif_type, val)
5346 send_a_repository ("", repository, update_dir);
5347 send_to_server ("Notify ", 0);
5348 send_to_server (filename, 0);
5349 send_to_server ("\012", 1);
5350 buf[0] = notif_type;
5352 send_to_server (buf, 1);
5353 send_to_server ("\t", 1);
5354 send_to_server (val, 0);
5358 * Send an option with an argument, dealing correctly with newlines in
5359 * the argument. If ARG is NULL, forget the whole thing.
5362 option_with_arg (option, arg)
5369 send_to_server ("Argument ", 0);
5370 send_to_server (option, 0);
5371 send_to_server ("\012", 1);
5377 * Send a date to the server. This will passed a string which is the
5378 * result of Make_Date, and looks like YY.MM.DD.HH.MM.SS, where all
5379 * the letters are single digits. The time will be GMT. getdate on
5380 * the server can't parse that, so we turn it back into something
5381 * which it can parse.
5385 client_senddate (date)
5388 int year, month, day, hour, minute, second;
5391 if (sscanf (date, DATEFORM, &year, &month, &day, &hour, &minute, &second)
5394 error (1, 0, "diff_client_senddate: sscanf failed on date");
5397 sprintf (buf, "%d/%d/%d %d:%d:%d GMT", month, day, year,
5398 hour, minute, second);
5399 option_with_arg ("-D", buf);
5403 send_init_command ()
5405 /* This is here because we need the CVSroot_directory variable. */
5406 send_to_server ("init ", 0);
5407 send_to_server (CVSroot_directory, 0);
5408 send_to_server ("\012", 0);
5411 #endif /* CLIENT_SUPPORT */