Annotation of src/usr.bin/cvs/client.c, Revision 1.23
1.23 ! xsa 1: /* $OpenBSD: client.c,v 1.22 2006/11/13 15:55:54 xsa Exp $ */
1.1 jfb 2: /*
1.9 joris 3: * Copyright (c) 2006 Joris Vink <joris@openbsd.org>
1.1 jfb 4: *
1.9 joris 5: * Permission to use, copy, modify, and distribute this software for any
6: * purpose with or without fee is hereby granted, provided that the above
7: * copyright notice and this permission notice appear in all copies.
8: *
9: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.1 jfb 16: */
17:
1.9 joris 18: #include "includes.h"
1.1 jfb 19:
20: #include "cvs.h"
21: #include "log.h"
1.9 joris 22: #include "diff.h"
23: #include "remote.h"
1.1 jfb 24:
1.9 joris 25: struct cvs_req cvs_requests[] = {
26: /* this is what our client will use, the server should support it */
27: { "Root", 1, cvs_server_root, REQ_NEEDED },
28: { "Valid-responses", 1, cvs_server_validresp, REQ_NEEDED },
29: { "valid-requests", 1, cvs_server_validreq, REQ_NEEDED },
30: { "Global_option", 0, cvs_server_globalopt, REQ_NEEDED },
31: { "Directory", 0, cvs_server_directory, REQ_NEEDED },
32: { "Entry", 0, cvs_server_entry, REQ_NEEDED },
33: { "Modified", 0, cvs_server_modified, REQ_NEEDED },
34: { "UseUnchanged", 0, cvs_server_useunchanged, REQ_NEEDED },
35: { "Unchanged", 0, cvs_server_unchanged, REQ_NEEDED },
36: { "Questionable", 0, cvs_server_questionable, REQ_NEEDED },
37: { "Argument", 0, cvs_server_argument, REQ_NEEDED },
1.1 jfb 38:
1.9 joris 39: /*
40: * used to tell the server what is going on in our
41: * working copy, unsupported until we are told otherwise
42: */
43: { "Max-dotdot", 0, NULL, 0 },
44: { "Static-directory", 0, NULL, 0 },
45: { "Sticky", 0, NULL, 0 },
46: { "Checkin-prog", 0, NULL, 0 },
47: { "Update-prog", 0, NULL, 0 },
48: { "Kopt", 0, NULL, 0 },
49: { "Checkin-time", 0, NULL, 0 },
50: { "Is-modified", 0, NULL, 0 },
51: { "Notify", 0, NULL, 0 },
52: { "Case", 0, NULL, 0 },
53: { "Argumentx", 0, NULL, 0 },
54: { "Gzip-stream", 0, NULL, 0 },
55: { "Kerberos-encrypt", 0, NULL, 0 },
56: { "Gssapi-encrypt", 0, NULL, 0 },
57: { "Gssapi-authenticate", 0, NULL, 0 },
58: { "Set", 0, NULL, 0 },
59: { "expand-modules", 0, NULL, 0 },
60:
61: /* commands that might be supported */
62: { "ci", 0, cvs_server_commit, 0 },
63: { "co", 0, NULL, 0 },
64: { "diff", 0, cvs_server_diff, 0 },
1.17 xsa 65: { "tag", 0, cvs_server_tag, 0 },
1.9 joris 66: { "status", 0, cvs_server_status, 0 },
1.21 xsa 67: { "admin", 0, cvs_server_admin, 0 },
1.9 joris 68: { "history", 0, NULL, 0 },
69: { "watchers", 0, NULL, 0 },
70: { "editors", 0, NULL, 0 },
71: { "annotate", 0, NULL, 0 },
72: { "log", 0, cvs_server_log, 0 },
73: { "export", 0, NULL, 0 },
74: { "rdiff", 0, NULL, 0 },
75: { "rtag", 0, NULL, 0 },
1.22 xsa 76: { "init", 0, cvs_server_init, 0 },
1.9 joris 77: { "update", 0, cvs_server_update, 0 },
78: { "import", 0, NULL, 0 },
1.15 xsa 79: { "add", 0, cvs_server_add, 0 },
80: { "remove", 0, cvs_server_remove, 0 },
1.23 ! xsa 81: { "version", 0, cvs_server_version, 0 },
1.9 joris 82: { "watch-on", 0, NULL, 0 },
83: { "watch-off", 0, NULL, 0 },
84: { "watch-add", 0, NULL, 0 },
85: { "watch-remove", 0, NULL, 0 },
86: { "release", 0, NULL, 0 },
87: { "noop", 0, NULL, 0 },
88: { "update-patches", 0, NULL, 0 },
89: { "gzip-file-contents", 0, NULL, 0 },
90: { "wrapper-sendme-rcsOptions", 0, NULL, 0 },
91: { "", -1, NULL, 0 }
92: };
93:
1.16 xsa 94: static void client_check_directory(char *);
95: static char *client_get_supported_responses(void);
96: static char *lastdir = NULL;
97: static int end_of_response = 0;
98:
99: static void cvs_client_initlog(void);
100:
101: /*
102: * File descriptors for protocol logging when the CVS_CLIENT_LOG environment
103: * variable is set.
104: */
105: static int cvs_client_logon = 0;
106: static int cvs_client_inlog_fd = -1;
107: static int cvs_client_outlog_fd = -1;
108:
1.9 joris 109:
110: static char *
111: client_get_supported_responses(void)
112: {
113: BUF *bp;
114: char *d;
115: int i, first;
116:
117: first = 0;
118: bp = cvs_buf_alloc(512, BUF_AUTOEXT);
119: for (i = 0; cvs_responses[i].supported != -1; i++) {
120: if (cvs_responses[i].hdlr == NULL)
121: continue;
122:
123: if (first != 0)
124: cvs_buf_append(bp, " ", 1);
125: else
126: first++;
127: cvs_buf_append(bp, cvs_responses[i].name,
128: strlen(cvs_responses[i].name));
129: }
130:
131: cvs_buf_putc(bp, '\0');
132: d = cvs_buf_release(bp);
133: return (d);
134: }
1.1 jfb 135:
1.10 joris 136: static void
137: client_check_directory(char *data)
138: {
139: int l;
140: CVSENTRIES *entlist;
141: char *entry, *parent, *base;
142:
143: STRIP_SLASH(data);
144:
145: cvs_mkpath(data);
146:
147: if ((base = basename(data)) == NULL)
148: fatal("client_check_directory: overflow");
149:
150: if ((parent = dirname(data)) == NULL)
151: fatal("client_check_directory: overflow");
1.11 joris 152:
153: if (!strcmp(parent, "."))
154: return;
1.10 joris 155:
156: entry = xmalloc(CVS_ENT_MAXLINELEN);
157: l = snprintf(entry, CVS_ENT_MAXLINELEN, "D/%s////", base);
158: if (l == -1 || l >= CVS_ENT_MAXLINELEN)
159: fatal("client_check_directory: overflow");
160:
161: entlist = cvs_ent_open(parent);
162: cvs_ent_add(entlist, entry);
163: cvs_ent_close(entlist, ENT_SYNC);
164:
165: xfree(entry);
166: }
167:
1.9 joris 168: void
169: cvs_client_connect_to_server(void)
170: {
171: char *cmd, *argv[9], *resp;
172: int ifd[2], ofd[2], argc;
1.1 jfb 173:
1.9 joris 174: switch (current_cvsroot->cr_method) {
175: case CVS_METHOD_PSERVER:
176: case CVS_METHOD_KSERVER:
177: case CVS_METHOD_GSERVER:
178: case CVS_METHOD_FORK:
179: case CVS_METHOD_EXT:
1.14 joris 180: fatal("the specified connection method is not supported");
1.9 joris 181: default:
182: break;
183: }
184:
185: if (pipe(ifd) == -1)
186: fatal("cvs_client_connect: %s", strerror(errno));
187: if (pipe(ofd) == -1)
188: fatal("cvs_client_connect: %s", strerror(errno));
189:
190: switch (fork()) {
191: case -1:
192: fatal("cvs_client_connect: fork failed: %s", strerror(errno));
193: case 0:
194: if (dup2(ifd[0], STDIN_FILENO) == -1)
195: fatal("cvs_client_connect: %s", strerror(errno));
196: if (dup2(ofd[1], STDOUT_FILENO) == -1)
197: fatal("cvs_client_connect: %s", strerror(errno));
1.1 jfb 198:
1.9 joris 199: close(ifd[1]);
200: close(ofd[0]);
1.1 jfb 201:
1.9 joris 202: if ((cmd = getenv("CVS_SERVER")) == NULL)
203: cmd = CVS_SERVER_DEFAULT;
1.1 jfb 204:
205: argc = 0;
206: argv[argc++] = cvs_rsh;
207:
1.9 joris 208: if (current_cvsroot->cr_user != NULL) {
1.1 jfb 209: argv[argc++] = "-l";
1.9 joris 210: argv[argc++] = current_cvsroot->cr_user;
1.1 jfb 211: }
212:
1.9 joris 213: argv[argc++] = current_cvsroot->cr_host;
214: argv[argc++] = cmd;
1.1 jfb 215: argv[argc++] = "server";
216: argv[argc] = NULL;
217:
1.9 joris 218: cvs_log(LP_TRACE, "connecting to server %s",
219: current_cvsroot->cr_host);
220:
1.1 jfb 221: execvp(argv[0], argv);
1.9 joris 222: fatal("cvs_client_connect: failed to execute cvs server");
223: default:
224: break;
1.1 jfb 225: }
226:
1.9 joris 227: close(ifd[0]);
228: close(ofd[1]);
229:
230: if ((current_cvsroot->cr_srvin = fdopen(ifd[1], "w")) == NULL)
231: fatal("cvs_client_connect: %s", strerror(errno));
232: if ((current_cvsroot->cr_srvout = fdopen(ofd[0], "r")) == NULL)
233: fatal("cvs_client_connect: %s", strerror(errno));
1.1 jfb 234:
1.9 joris 235: setvbuf(current_cvsroot->cr_srvin, NULL,_IOLBF, 0);
236: setvbuf(current_cvsroot->cr_srvout, NULL, _IOLBF, 0);
1.1 jfb 237:
1.16 xsa 238: cvs_client_initlog();
239:
1.18 xsa 240: if (cvs_cmdop != CVS_OP_INIT)
241: cvs_client_send_request("Root %s", current_cvsroot->cr_dir);
1.1 jfb 242:
1.9 joris 243: resp = client_get_supported_responses();
244: cvs_client_send_request("Valid-responses %s", resp);
245: xfree(resp);
1.1 jfb 246:
1.9 joris 247: cvs_client_send_request("valid-requests");
248: cvs_client_get_responses();
1.1 jfb 249:
1.20 xsa 250: if (cvs_nolog == 1)
251: cvs_client_send_request("Global_option -l");
252:
1.19 xsa 253: if (cvs_noexec == 1)
254: cvs_client_send_request("Global_option -n");
255:
256: if (verbosity == 0)
257: cvs_client_send_request("Global_option -Q");
1.20 xsa 258:
259: /* Be quiet. This is the default in OpenCVS. */
260: cvs_client_send_request("Global_option -q");
1.19 xsa 261:
262: if (cvs_readonly == 1)
263: cvs_client_send_request("Global_option -r");
264:
265: if (cvs_trace == 1)
1.9 joris 266: cvs_client_send_request("Global_option -t");
1.1 jfb 267:
1.9 joris 268: if (verbosity == 2)
269: cvs_client_send_request("Global_option -V");
1.1 jfb 270:
1.9 joris 271: cvs_client_send_request("UseUnchanged");
1.1 jfb 272: }
273:
1.9 joris 274: void
275: cvs_client_send_request(char *fmt, ...)
276: {
277: va_list ap;
278: char *data, *s;
279: struct cvs_req *req;
280:
281: va_start(ap, fmt);
282: vasprintf(&data, fmt, ap);
283: va_end(ap);
1.1 jfb 284:
1.9 joris 285: if ((s = strchr(data, ' ')) != NULL)
286: *s = '\0';
1.1 jfb 287:
1.9 joris 288: req = cvs_remote_get_request_info(data);
289: if (req == NULL)
290: fatal("'%s' is an unknown request", data);
1.1 jfb 291:
1.9 joris 292: if (req->supported != 1)
293: fatal("remote cvs server does not support '%s'", data);
1.1 jfb 294:
1.9 joris 295: if (s != NULL)
296: *s = ' ';
1.1 jfb 297:
1.12 joris 298: cvs_log(LP_TRACE, "%s", data);
1.16 xsa 299:
300: if (cvs_client_inlog_fd != -1) {
301: BUF *bp;
302:
303: bp = cvs_buf_alloc(strlen(data), BUF_AUTOEXT);
304:
305: if (cvs_buf_append(bp, data, strlen(data)) < 0)
306: fatal("cvs_client_send_request: cvs_buf_append");
307:
308: cvs_buf_putc(bp, '\n');
309:
310: if (cvs_buf_write_fd(bp, cvs_client_inlog_fd) < 0)
311: fatal("cvs_client_send_request: cvs_buf_write_fd");
312:
313: cvs_buf_free(bp);
314: }
315:
1.9 joris 316: cvs_remote_output(data);
317: xfree(data);
318: }
1.1 jfb 319:
1.9 joris 320: void
321: cvs_client_read_response(void)
1.1 jfb 322: {
1.9 joris 323: char *cmd, *data;
324: struct cvs_resp *resp;
1.1 jfb 325:
1.9 joris 326: cmd = cvs_remote_input();
327: if ((data = strchr(cmd, ' ')) != NULL)
328: (*data++) = '\0';
1.1 jfb 329:
1.9 joris 330: resp = cvs_remote_get_response_info(cmd);
331: if (resp == NULL)
332: fatal("response '%s' is not supported by our client", cmd);
1.1 jfb 333:
1.9 joris 334: if (resp->hdlr == NULL)
335: fatal("opencvs client does not support '%s'", cmd);
1.1 jfb 336:
1.16 xsa 337: if (cvs_client_outlog_fd != -1) {
338: BUF *bp;
339:
340: bp = cvs_buf_alloc(strlen(cmd), BUF_AUTOEXT);
341:
342: if (cvs_buf_append(bp, cmd, strlen(cmd)) < 0)
343: fatal("cvs_client_read_response: cvs_buf_append");
344:
345: if (cvs_buf_append(bp,
346: (data == NULL) ? "" : " ",
347: (data == NULL) ? 0 : 1) < 0) {
348: fatal("cvs_client_read_response: cvs_buf_append");
349: }
350:
351: if (cvs_buf_append(bp,
352: (data == NULL) ? "" : data,
353: (data == NULL) ? 0 : strlen(data)) < 0) {
354: fatal("cvs_client_read_response: cvs_buf_append");
355: }
356:
357: cvs_buf_putc(bp, '\n');
358:
359: if (cvs_buf_write_fd(bp, cvs_client_outlog_fd) < 0)
360: fatal("cvs_client_read_response: cvs_buf_write_fd");
361:
362: cvs_buf_free(bp);
363: }
364:
1.9 joris 365: (*resp->hdlr)(data);
1.16 xsa 366:
1.9 joris 367: xfree(cmd);
1.1 jfb 368: }
369:
1.9 joris 370: void
371: cvs_client_get_responses(void)
372: {
373: while (end_of_response != 1)
374: cvs_client_read_response();
1.1 jfb 375:
1.9 joris 376: end_of_response = 0;
377: }
1.1 jfb 378:
1.9 joris 379: void
380: cvs_client_senddir(const char *dir)
1.1 jfb 381: {
1.9 joris 382: char *repo;
383:
384: if (lastdir != NULL && !strcmp(dir, lastdir))
385: return;
1.1 jfb 386:
1.9 joris 387: cvs_client_send_request("Directory %s", dir);
1.1 jfb 388:
1.9 joris 389: repo = xmalloc(MAXPATHLEN);
390: cvs_get_repository_path(dir, repo, MAXPATHLEN);
391: cvs_remote_output(repo);
392: xfree(repo);
1.1 jfb 393:
1.9 joris 394: if (lastdir != NULL)
395: xfree(lastdir);
396: lastdir = xstrdup(dir);
397: }
1.1 jfb 398:
1.9 joris 399: void
400: cvs_client_sendfile(struct cvs_file *cf)
1.1 jfb 401: {
1.9 joris 402: int l;
403: size_t len;
404: char rev[16], timebuf[64], sticky[32];
1.1 jfb 405:
1.9 joris 406: if (cf->file_type != CVS_FILE)
407: return;
1.1 jfb 408:
1.9 joris 409: cvs_client_senddir(cf->file_wd);
410: cvs_remote_classify_file(cf);
411:
1.10 joris 412: if (cf->file_type == CVS_DIR)
413: return;
414:
1.9 joris 415: if (cf->file_ent != NULL) {
416: if (cf->file_status == FILE_ADDED) {
417: len = strlcpy(rev, "0", sizeof(rev));
418: if (len >= sizeof(rev))
419: fatal("cvs_client_sendfile: truncation");
420:
421: len = strlcpy(timebuf, "Initial ", sizeof(timebuf));
422: if (len >= sizeof(timebuf))
423: fatal("cvs_client_sendfile: truncation");
424:
425: len = strlcat(timebuf, cf->file_name, sizeof(timebuf));
426: if (len >= sizeof(timebuf))
427: fatal("cvs_client_sendfile: truncation");
428: } else {
429: rcsnum_tostr(cf->file_ent->ce_rev, rev, sizeof(rev));
430: ctime_r(&cf->file_ent->ce_mtime, timebuf);
431: }
1.1 jfb 432:
1.9 joris 433: if (cf->file_ent->ce_conflict == NULL) {
434: if (timebuf[strlen(timebuf) - 1] == '\n')
435: timebuf[strlen(timebuf) - 1] = '\0';
436: } else {
437: len = strlcpy(timebuf, cf->file_ent->ce_conflict,
438: sizeof(timebuf));
439: if (len >= sizeof(timebuf))
440: fatal("cvs_client_sendfile: truncation");
441: }
1.1 jfb 442:
1.9 joris 443: sticky[0] = '\0';
444: if (cf->file_ent->ce_tag != NULL) {
445: l = snprintf(sticky, sizeof(sticky), "T%s",
446: cf->file_ent->ce_tag);
447: if (l == -1 || l >= (int)sizeof(sticky))
448: fatal("cvs_client_sendfile: overflow");
1.1 jfb 449: }
450:
1.13 joris 451: cvs_client_send_request("Entry /%s/%s%s/%s//%s",
1.9 joris 452: cf->file_name, (cf->file_status == FILE_REMOVED) ? "-" : "",
453: rev, timebuf, sticky);
454: }
455:
456: switch (cf->file_status) {
457: case FILE_UNKNOWN:
458: if (cf->fd != -1)
459: cvs_client_send_request("Questionable %s",
460: cf->file_name);
461: break;
462: case FILE_ADDED:
463: case FILE_MODIFIED:
464: cvs_client_send_request("Modified %s", cf->file_name);
465: cvs_remote_send_file(cf->file_path);
466: break;
467: case FILE_UPTODATE:
468: cvs_client_send_request("Unchanged %s", cf->file_name);
469: break;
1.1 jfb 470: }
1.9 joris 471: }
1.1 jfb 472:
1.9 joris 473: void
474: cvs_client_send_files(char **argv, int argc)
475: {
476: int i;
1.1 jfb 477:
1.9 joris 478: for (i = 0; i < argc; i++)
479: cvs_client_send_request("Argument %s", argv[i]);
480: }
1.1 jfb 481:
1.9 joris 482: void
483: cvs_client_ok(char *data)
484: {
485: end_of_response = 1;
1.1 jfb 486: }
487:
1.9 joris 488: void
489: cvs_client_error(char *data)
490: {
491: end_of_response = 1;
492: }
1.1 jfb 493:
1.9 joris 494: void
495: cvs_client_validreq(char *data)
1.1 jfb 496: {
1.9 joris 497: int i;
498: char *sp, *ep;
499: struct cvs_req *req;
500:
501: sp = data;
502: do {
503: if ((ep = strchr(sp, ' ')) != NULL)
504: *ep = '\0';
505:
506: req = cvs_remote_get_request_info(sp);
507: if (req != NULL)
508: req->supported = 1;
509:
510: if (ep != NULL)
511: sp = ep + 1;
512: } while (ep != NULL);
513:
514: for (i = 0; cvs_requests[i].supported != -1; i++) {
515: req = &cvs_requests[i];
516: if ((req->flags & REQ_NEEDED) &&
517: req->supported != 1) {
518: fatal("server does not support required '%s'",
519: req->name);
520: }
1.1 jfb 521: }
1.9 joris 522: }
1.1 jfb 523:
1.9 joris 524: void
525: cvs_client_e(char *data)
526: {
527: cvs_printf("%s\n", data);
528: }
1.1 jfb 529:
1.9 joris 530: void
531: cvs_client_m(char *data)
532: {
533: cvs_printf("%s\n", data);
534: }
1.1 jfb 535:
1.9 joris 536: void
537: cvs_client_checkedin(char *data)
538: {
539: int l;
540: CVSENTRIES *entlist;
541: struct cvs_ent *ent, *newent;
542: char *dir, *entry, rev[16], timebuf[64], sticky[16];
1.1 jfb 543:
1.9 joris 544: dir = cvs_remote_input();
545: entry = cvs_remote_input();
546: xfree(dir);
1.1 jfb 547:
1.9 joris 548: entlist = cvs_ent_open(data);
549: newent = cvs_ent_parse(entry);
550: ent = cvs_ent_get(entlist, newent->ce_name);
551: xfree(entry);
1.1 jfb 552:
1.9 joris 553: entry = xmalloc(CVS_ENT_MAXLINELEN);
1.1 jfb 554:
1.9 joris 555: rcsnum_tostr(newent->ce_rev, rev, sizeof(rev));
556: ctime_r(&ent->ce_mtime, timebuf);
557: if (timebuf[strlen(timebuf) - 1] == '\n')
558: timebuf[strlen(timebuf) - 1] = '\0';
1.1 jfb 559:
1.9 joris 560: sticky[0] = '\0';
561: if (ent->ce_tag != NULL) {
562: l = snprintf(sticky, sizeof(sticky), "T%s", ent->ce_tag);
563: if (l == -1 || l >= (int)sizeof(sticky))
564: fatal("cvs_client_checkedin: overflow");
1.2 jfb 565: }
1.1 jfb 566:
1.9 joris 567: l = snprintf(entry, CVS_ENT_MAXLINELEN, "/%s/%s/%s//%s/",
568: newent->ce_name, rev, timebuf, sticky);
569: if (l == -1 || l >= CVS_ENT_MAXLINELEN)
570: fatal("cvs_client_checkedin: overflow");
571:
572: cvs_ent_free(ent);
573: cvs_ent_free(newent);
574: cvs_ent_add(entlist, entry);
575: cvs_ent_close(entlist, ENT_SYNC);
1.1 jfb 576:
1.9 joris 577: xfree(entry);
1.1 jfb 578: }
579:
1.9 joris 580: void
581: cvs_client_updated(char *data)
582: {
583: BUF *bp;
584: int l, fd;
585: time_t now;
586: mode_t fmode;
587: size_t flen;
588: CVSENTRIES *ent;
589: struct cvs_ent *e;
590: const char *errstr;
591: struct timeval tv[2];
592: char timebuf[32], *repo, *rpath, *entry, *mode;
593: char revbuf[32], *len, *fpath, *wdir;
594:
1.10 joris 595: client_check_directory(data);
1.9 joris 596:
597: rpath = cvs_remote_input();
598: entry = cvs_remote_input();
599: mode = cvs_remote_input();
600: len = cvs_remote_input();
601:
602: repo = xmalloc(MAXPATHLEN);
603: cvs_get_repository_path(".", repo, MAXPATHLEN);
604:
605: if (strlen(repo) + 1 > strlen(rpath))
606: fatal("received a repository path that is too short");
607:
608: fpath = rpath + strlen(repo) + 1;
609: if ((wdir = dirname(fpath)) == NULL)
610: fatal("cvs_client_updated: dirname: %s", strerror(errno));
611: xfree(repo);
612:
613: flen = strtonum(len, 0, INT_MAX, &errstr);
614: if (errstr != NULL)
615: fatal("cvs_client_updated: %s: %s", len, errstr);
616: xfree(len);
617:
618: cvs_strtomode(mode, &fmode);
619: xfree(mode);
620:
621: time(&now);
622: now = cvs_hack_time(now, 0);
623: ctime_r(&now, timebuf);
624: if (timebuf[strlen(timebuf) - 1] == '\n')
625: timebuf[strlen(timebuf) - 1] = '\0';
626:
627: e = cvs_ent_parse(entry);
628: xfree(entry);
629: rcsnum_tostr(e->ce_rev, revbuf, sizeof(revbuf));
630: entry = xmalloc(CVS_ENT_MAXLINELEN);
631: l = snprintf(entry, CVS_ENT_MAXLINELEN, "/%s/%s/%s//", e->ce_name,
632: revbuf, timebuf);
633: if (l == -1 || l >= CVS_ENT_MAXLINELEN)
634: fatal("cvs_client_updated: overflow");
635:
636: cvs_ent_free(e);
637: ent = cvs_ent_open(wdir);
638: cvs_ent_add(ent, entry);
639: cvs_ent_close(ent, ENT_SYNC);
640: xfree(entry);
641:
642: bp = cvs_remote_receive_file(flen);
643: if ((fd = open(fpath, O_CREAT | O_WRONLY | O_TRUNC)) == -1)
644: fatal("cvs_client_updated: open: %s: %s",
645: fpath, strerror(errno));
1.1 jfb 646:
1.9 joris 647: if (cvs_buf_write_fd(bp, fd) == -1)
648: fatal("cvs_client_updated: cvs_buf_write_fd failed for %s",
649: fpath);
1.1 jfb 650:
1.9 joris 651: cvs_buf_free(bp);
1.1 jfb 652:
1.9 joris 653: now = cvs_hack_time(now, 0);
654: tv[0].tv_sec = now;
655: tv[0].tv_usec = 0;
656: tv[1] = tv[0];
1.1 jfb 657:
1.9 joris 658: if (futimes(fd, tv) == -1)
659: fatal("cvs_client_updated: futimes: %s", strerror(errno));
1.1 jfb 660:
1.9 joris 661: if (fchmod(fd, fmode) == -1)
662: fatal("cvs_client_updated: fchmod: %s", strerror(errno));
1.1 jfb 663:
1.9 joris 664: (void)close(fd);
1.1 jfb 665:
1.9 joris 666: xfree(rpath);
1.1 jfb 667: }
668:
1.9 joris 669: void
670: cvs_client_merged(char *data)
671: {
672: }
1.1 jfb 673:
1.9 joris 674: void
675: cvs_client_removed(char *data)
676: {
1.13 joris 677: char *dir;
678:
679: dir = cvs_remote_input();
680: xfree(dir);
1.9 joris 681: }
1.1 jfb 682:
1.9 joris 683: void
684: cvs_client_remove_entry(char *data)
1.1 jfb 685: {
1.9 joris 686: char *dir;
1.1 jfb 687:
1.9 joris 688: dir = cvs_remote_input();
689: xfree(dir);
1.16 xsa 690: }
691: /*
692: * cvs_client_initlog()
693: *
694: * Initialize protocol logging if the CVS_CLIENT_LOG environment variable is
695: * set. In this case, the variable's value is used as a path to which the
696: * appropriate suffix is added (".in" for client input and ".out" for server
697: * output).
698: */
699: static void
700: cvs_client_initlog(void)
701: {
702: int l;
703: u_int i;
704: char *env, *envdup, buf[MAXPATHLEN], fpath[MAXPATHLEN];
705: char rpath[MAXPATHLEN], *s;
706: struct stat st;
707: time_t now;
708: struct passwd *pwd;
709:
710: /* avoid doing it more than once */
711: if (cvs_client_logon)
712: return;
713:
714: if ((env = getenv("CVS_CLIENT_LOG")) == NULL)
715: return;
716:
717: envdup = xstrdup(env);
718: if ((s = strchr(envdup, '%')) != NULL)
719: *s = '\0';
720:
721: if (strlcpy(buf, env, sizeof(buf)) >= sizeof(buf))
722: fatal("cvs_client_initlog: truncation");
723:
724: if (strlcpy(rpath, envdup, sizeof(rpath)) >= sizeof(rpath))
725: fatal("cvs_client_initlog: truncation");
726:
727: xfree(envdup);
728:
729: s = buf;
730: while ((s = strchr(s, '%')) != NULL) {
731: s++;
732: switch (*s) {
733: case 'c':
734: if (strlcpy(fpath, cvs_command, sizeof(fpath)) >=
735: sizeof(fpath))
736: fatal("cvs_client_initlog: truncation");
737: break;
738: case 'd':
739: time(&now);
740: if (strlcpy(fpath, ctime(&now), sizeof(fpath)) >=
741: sizeof(fpath))
742: fatal("cvs_client_initlog: truncation");
743: break;
744: case 'p':
745: snprintf(fpath, sizeof(fpath), "%d", getpid());
746: break;
747: case 'u':
748: if ((pwd = getpwuid(getuid())) != NULL) {
749: if (strlcpy(fpath, pwd->pw_name,
750: sizeof(fpath)) >= sizeof(fpath))
751: fatal("cvs_client_initlog: truncation");
752: } else {
753: fpath[0] = '\0';
754: }
755: endpwent();
756: break;
757: default:
758: fpath[0] = '\0';
759: break;
760: }
761:
762: if (fpath[0] != '\0') {
763: if (strlcat(rpath, "-", sizeof(rpath)) >= sizeof(rpath))
764: fatal("cvs_client_initlog: truncation");
765:
766: if (strlcat(rpath, fpath, sizeof(rpath))
767: >= sizeof(rpath))
768: fatal("cvs_client_initlog: truncation");
769: }
770: }
771:
772: for (i = 0; i < UINT_MAX; i++) {
773: l = snprintf(fpath, sizeof(fpath), "%s-%d.in", rpath, i);
774: if (l == -1 || l >= (int)sizeof(fpath))
775: fatal("cvs_client_initlog: overflow");
776:
777: if (stat(fpath, &st) != -1)
778: continue;
779:
780: if (errno != ENOENT)
781: fatal("cvs_client_initlog() stat failed '%s'",
782: strerror(errno));
783:
784: break;
785: }
786:
787: if ((cvs_client_inlog_fd = open(fpath,
788: O_RDWR | O_CREAT | O_TRUNC, 0644)) == NULL) {
789: fatal("cvs_client_initlog: open `%s': %s",
790: fpath, strerror(errno));
791: }
792:
793: for (i = 0; i < UINT_MAX; i++) {
794: l = snprintf(fpath, sizeof(fpath), "%s-%d.out", rpath, i);
795: if (l == -1 || l >= (int)sizeof(fpath))
796: fatal("cvs_client_initlog: overflow");
797:
798: if (stat(fpath, &st) != -1)
799: continue;
800:
801: if (errno != ENOENT)
802: fatal("cvs_client_initlog() stat failed '%s'",
803: strerror(errno));
804:
805: break;
806: }
807:
808: if ((cvs_client_outlog_fd = open(fpath,
809: O_RDWR | O_CREAT | O_TRUNC, 0644)) == NULL) {
810: fatal("cvs_client_initlog: open `%s': %s",
811: fpath, strerror(errno));
812: }
813:
814: cvs_client_logon = 1;
1.1 jfb 815: }