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