[BACK]Return to resp.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / cvs

Annotation of src/usr.bin/cvs/resp.c, Revision 1.12

1.12    ! jfb         1: /*     $OpenBSD: resp.c,v 1.11 2004/12/06 21:03:12 deraadt Exp $       */
1.1       jfb         2: /*
                      3:  * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
                      4:  * All rights reserved.
                      5:  *
                      6:  * Redistribution and use in source and binary forms, with or without
                      7:  * modification, are permitted provided that the following conditions
                      8:  * are met:
                      9:  *
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  * 2. The name of the author may not be used to endorse or promote products
                     13:  *    derived from this software without specific prior written permission.
                     14:  *
                     15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
                     16:  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
                     17:  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
                     18:  * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
                     19:  * EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLUDING, BUT NOT LIMITED TO,
                     20:  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
                     21:  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
                     22:  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
                     23:  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
                     24:  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     25:  */
                     26:
                     27:
                     28: #include <sys/types.h>
                     29: #include <sys/stat.h>
1.2       jfb        30: #include <sys/time.h>
1.1       jfb        31:
                     32: #include <fcntl.h>
                     33: #include <stdio.h>
                     34: #include <errno.h>
                     35: #include <dirent.h>
                     36: #include <stdlib.h>
                     37: #include <unistd.h>
                     38: #include <string.h>
                     39: #include <sysexits.h>
                     40:
                     41: #include "buf.h"
                     42: #include "cvs.h"
                     43: #include "log.h"
                     44: #include "file.h"
                     45: #include "proto.h"
                     46:
                     47:
                     48: #define CVS_MTSTK_MAXDEPTH   16
                     49:
                     50:
1.4       jfb        51: #define STRIP_SLASH(p)                                         \
                     52:        do {                                                    \
                     53:                size_t len;                                     \
                     54:                len = strlen(p);                                \
                     55:                while ((len > 0) && (p[len - 1] == '/'))        \
                     56:                        p[--len] = '\0';                        \
                     57:        } while (0)
                     58:
                     59:
                     60:
1.1       jfb        61: static int  cvs_resp_validreq  (struct cvsroot *, int, char *);
                     62: static int  cvs_resp_cksum     (struct cvsroot *, int, char *);
                     63: static int  cvs_resp_modtime   (struct cvsroot *, int, char *);
                     64: static int  cvs_resp_m         (struct cvsroot *, int, char *);
                     65: static int  cvs_resp_ok        (struct cvsroot *, int, char *);
                     66: static int  cvs_resp_error     (struct cvsroot *, int, char *);
                     67: static int  cvs_resp_statdir   (struct cvsroot *, int, char *);
                     68: static int  cvs_resp_sticky    (struct cvsroot *, int, char *);
                     69: static int  cvs_resp_newentry  (struct cvsroot *, int, char *);
                     70: static int  cvs_resp_updated   (struct cvsroot *, int, char *);
                     71: static int  cvs_resp_removed   (struct cvsroot *, int, char *);
                     72: static int  cvs_resp_mode      (struct cvsroot *, int, char *);
                     73: static int  cvs_resp_modxpand  (struct cvsroot *, int, char *);
                     74: static int  cvs_resp_rcsdiff   (struct cvsroot *, int, char *);
                     75: static int  cvs_resp_template  (struct cvsroot *, int, char *);
                     76:
                     77:
                     78: struct cvs_resphdlr {
                     79:        int (*hdlr)(struct cvsroot *, int, char *);
                     80: } cvs_resp_swtab[CVS_RESP_MAX + 1] = {
                     81:        { NULL              },
                     82:        { cvs_resp_ok       },
                     83:        { cvs_resp_error    },
                     84:        { cvs_resp_validreq },
                     85:        { cvs_resp_newentry },
                     86:        { cvs_resp_newentry },
                     87:        { cvs_resp_cksum    },
                     88:        { NULL              },
                     89:        { cvs_resp_updated  },
                     90:        { cvs_resp_updated  },
                     91:        { cvs_resp_updated  },  /* 10 */
                     92:        { cvs_resp_updated  },
                     93:        { cvs_resp_updated  },
                     94:        { cvs_resp_rcsdiff  },
                     95:        { cvs_resp_mode     },
                     96:        { cvs_resp_modtime  },
                     97:        { cvs_resp_removed  },
                     98:        { cvs_resp_removed  },
                     99:        { cvs_resp_statdir  },
                    100:        { cvs_resp_statdir  },
                    101:        { cvs_resp_sticky   },  /* 20 */
                    102:        { cvs_resp_sticky   },
                    103:        { cvs_resp_template },
                    104:        { NULL              },
                    105:        { NULL              },
                    106:        { NULL              },
                    107:        { cvs_resp_modxpand },
                    108:        { NULL              },
                    109:        { cvs_resp_m        },
                    110:        { cvs_resp_m        },
                    111:        { cvs_resp_m        },  /* 30 */
                    112:        { cvs_resp_m        },
                    113:        { cvs_resp_m        },
                    114: };
                    115:
                    116:
                    117:
                    118: /*
                    119:  * The MT command uses scoping to tag the data.  Whenever we encouter a '+',
                    120:  * we push the name of the tag on the stack, and we pop it when we encounter
                    121:  * a '-' with the same name.
                    122:  */
                    123:
                    124: static char *cvs_mt_stack[CVS_MTSTK_MAXDEPTH];
                    125: static u_int cvs_mtstk_depth = 0;
                    126:
1.12    ! jfb       127: static time_t cvs_modtime = CVS_DATE_DMSEC;
1.1       jfb       128:
                    129:
                    130: /* last checksum received */
                    131: char *cvs_fcksum = NULL;
                    132:
                    133: mode_t  cvs_lastmode = 0;
                    134:
                    135: /* hack to receive the remote version without outputting it */
                    136: extern u_int cvs_version_sent;
                    137:
                    138:
                    139: /*
                    140:  * cvs_resp_handle()
                    141:  *
                    142:  * Generic response handler dispatcher.  The handler expects the first line
                    143:  * of the command as single argument.
                    144:  * Returns the return value of the command on success, or -1 on failure.
                    145:  */
                    146:
                    147: int
                    148: cvs_resp_handle(struct cvsroot *root, char *line)
                    149: {
                    150:        char *cp, *cmd;
                    151:        struct cvs_resp *resp;
                    152:
                    153:        cmd = line;
                    154:
                    155:        cp = strchr(cmd, ' ');
                    156:        if (cp != NULL)
                    157:                *(cp++) = '\0';
                    158:
                    159:        resp = cvs_resp_getbyname(cmd);
                    160:        if (resp == NULL) {
                    161:                return (-1);
1.11      deraadt   162:        } else if (cvs_resp_swtab[resp->resp_id].hdlr == NULL) {
1.1       jfb       163:                cvs_log(LP_ERRNO, "handler for `%s' not implemented", cmd);
                    164:                return (-1);
                    165:        }
                    166:
                    167:        return (*cvs_resp_swtab[resp->resp_id].hdlr)(root, resp->resp_id, cp);
                    168: }
                    169:
                    170:
                    171: /*
                    172:  * cvs_resp_validreq()
                    173:  *
                    174:  * Handler for the `Valid-requests' response.  The list of valid requests is
                    175:  * split on spaces and each request's entry in the valid request array is set
                    176:  * to 1 to indicate the validity.
                    177:  * Returns 0 on success, or -1 on failure.
                    178:  */
                    179:
                    180: static int
                    181: cvs_resp_validreq(struct cvsroot *root, int type, char *line)
                    182: {
                    183:        char *sp, *ep;
                    184:        struct cvs_req *req;
                    185:
                    186:        /* parse the requests */
                    187:        sp = line;
                    188:        do {
                    189:                ep = strchr(sp, ' ');
                    190:                if (ep != NULL)
                    191:                        *ep = '\0';
                    192:
                    193:                req = cvs_req_getbyname(sp);
                    194:                if (req != NULL)
                    195:                        CVS_SETVR(root, req->req_id);
                    196:
                    197:                if (ep != NULL)
                    198:                        sp = ep + 1;
                    199:        } while (ep != NULL);
                    200:
                    201:        return (0);
                    202: }
                    203:
                    204:
                    205: /*
                    206:  * cvs_resp_m()
                    207:  *
                    208:  * Handler for the `M', 'MT', `F' and `E' responses.
                    209:  */
                    210:
                    211: static int
                    212: cvs_resp_m(struct cvsroot *root, int type, char *line)
                    213: {
                    214:        char *cp;
                    215:        FILE *stream;
                    216:
                    217:        stream = NULL;
                    218:
                    219:        switch (type) {
                    220:        case CVS_RESP_F:
                    221:                fflush(stderr);
                    222:                return (0);
                    223:        case CVS_RESP_M:
                    224:                if (cvs_version_sent) {
                    225:                        /*
                    226:                         * Instead of outputting the line, we save it as the
                    227:                         * remote server's version string.
                    228:                         */
                    229:                        cvs_version_sent = 0;
                    230:                        root->cr_version = strdup(line);
                    231:                        return (0);
                    232:                }
                    233:                stream = stdout;
                    234:                break;
                    235:        case CVS_RESP_E:
                    236:                stream = stderr;
                    237:                break;
                    238:        case CVS_RESP_MT:
                    239:                if (*line == '+') {
                    240:                        if (cvs_mtstk_depth == CVS_MTSTK_MAXDEPTH) {
                    241:                                cvs_log(LP_ERR,
                    242:                                    "MT scope stack has reached max depth");
                    243:                                return (-1);
                    244:                        }
                    245:                        cvs_mt_stack[cvs_mtstk_depth] = strdup(line + 1);
                    246:                        if (cvs_mt_stack[cvs_mtstk_depth] == NULL)
                    247:                                return (-1);
                    248:                        cvs_mtstk_depth++;
1.11      deraadt   249:                } else if (*line == '-') {
1.1       jfb       250:                        if (cvs_mtstk_depth == 0) {
                    251:                                cvs_log(LP_ERR, "MT scope stack underflow");
                    252:                                return (-1);
1.11      deraadt   253:                        } else if (strcmp(line + 1,
1.1       jfb       254:                            cvs_mt_stack[cvs_mtstk_depth - 1]) != 0) {
                    255:                                cvs_log(LP_ERR, "mismatch in MT scope stack");
                    256:                                return (-1);
                    257:                        }
                    258:                        free(cvs_mt_stack[cvs_mtstk_depth--]);
1.11      deraadt   259:                } else {
1.1       jfb       260:                        if (strcmp(line, "newline") == 0)
                    261:                                putc('\n', stdout);
                    262:                        else if (strncmp(line, "fname ", 6) == 0)
                    263:                                printf("%s", line + 6);
                    264:                        else {
                    265:                                /* assume text */
                    266:                                cp = strchr(line, ' ');
                    267:                                if (cp != NULL)
                    268:                                        printf("%s", cp + 1);
                    269:                        }
                    270:                }
                    271:
                    272:                return (0);
                    273:        case CVS_RESP_MBINARY:
                    274:                cvs_log(LP_WARN, "Mbinary not supported in client yet");
                    275:                break;
                    276:        }
                    277:
                    278:        fputs(line, stream);
                    279:        fputc('\n', stream);
                    280:
                    281:        return (0);
                    282: }
                    283:
                    284:
                    285: /*
                    286:  * cvs_resp_ok()
                    287:  *
                    288:  * Handler for the `ok' response.  This handler's job is to
                    289:  */
                    290:
                    291: static int
                    292: cvs_resp_ok(struct cvsroot *root, int type, char *line)
                    293: {
                    294:        return (1);
                    295: }
                    296:
                    297:
                    298: /*
                    299:  * cvs_resp_error()
                    300:  *
                    301:  * Handler for the `error' response.  This handler's job is to
                    302:  */
                    303:
                    304: static int
                    305: cvs_resp_error(struct cvsroot *root, int type, char *line)
                    306: {
1.7       jfb       307:        fprintf(stderr, "%s\n", line);
1.1       jfb       308:        return (1);
                    309: }
                    310:
                    311:
                    312: /*
                    313:  * cvs_resp_statdir()
                    314:  *
                    315:  * Handler for the `Clear-static-directory' and `Set-static-directory'
                    316:  * responses.
                    317:  */
                    318:
                    319: static int
                    320: cvs_resp_statdir(struct cvsroot *root, int type, char *line)
                    321: {
                    322:        int fd;
                    323:        char rpath[MAXPATHLEN], statpath[MAXPATHLEN];
                    324:
1.3       jfb       325:        /* remote directory line */
                    326:        if (cvs_getln(root, rpath, sizeof(rpath)) < 0)
                    327:                return (-1);
1.1       jfb       328:
                    329:        snprintf(statpath, sizeof(statpath), "%s/%s", line,
                    330:            CVS_PATH_STATICENTRIES);
                    331:
                    332:        if ((type == CVS_RESP_CLRSTATDIR) &&
                    333:            (unlink(statpath) == -1) && (errno != ENOENT)) {
                    334:                cvs_log(LP_ERRNO, "failed to unlink %s file",
                    335:                    CVS_PATH_STATICENTRIES);
                    336:                return (-1);
1.11      deraadt   337:        } else if (type == CVS_RESP_SETSTATDIR) {
1.1       jfb       338:                fd = open(statpath, O_CREAT|O_TRUNC|O_WRONLY, 0400);
                    339:                if (fd == -1) {
1.3       jfb       340:                        cvs_log(LP_ERRNO,
                    341:                            "failed to set static directory on %s", line);
1.1       jfb       342:                        return (-1);
                    343:                }
                    344:                (void)close(fd);
                    345:
                    346:        }
                    347:
                    348:        return (0);
                    349: }
                    350:
                    351: /*
                    352:  * cvs_resp_sticky()
                    353:  *
1.4       jfb       354:  * Handler for the `Clear-sticky' and `Set-sticky' responses.  If the
                    355:  * specified directory doesn't exist, we create it and attach it to the
                    356:  * global file structure.
1.1       jfb       357:  */
                    358:
                    359: static int
                    360: cvs_resp_sticky(struct cvsroot *root, int type, char *line)
                    361: {
1.5       jfb       362:        char buf[MAXPATHLEN], subdir[MAXPATHLEN], *file;
                    363:        struct cvs_ent *ent;
1.4       jfb       364:        CVSFILE *cf, *sdir;
                    365:
                    366:        /* get the remote path */
1.5       jfb       367:        if (cvs_getln(root, buf, sizeof(buf)) < 0)
1.4       jfb       368:                return (-1);
1.1       jfb       369:
1.4       jfb       370:        STRIP_SLASH(line);
1.1       jfb       371:
1.4       jfb       372:        cvs_splitpath(line, subdir, sizeof(subdir), &file);
                    373:        sdir = cvs_file_find(cvs_files, subdir);
                    374:        if (sdir == NULL) {
                    375:                cvs_log(LP_ERR, "failed to find %s", subdir);
                    376:                return (-1);
                    377:        }
1.1       jfb       378:
1.4       jfb       379:        cf = cvs_file_find(sdir, file);
                    380:        if (cf == NULL) {
1.1       jfb       381:                /* attempt to create it */
1.8       jfb       382:                cf = cvs_file_create(sdir, line, DT_DIR, 0755);
1.4       jfb       383:                if (cf == NULL)
                    384:                        return (-1);
                    385:                cf->cf_ddat->cd_repo = strdup(line);
                    386:                cf->cf_ddat->cd_root = root;
                    387:                root->cr_ref++;
1.1       jfb       388:
1.4       jfb       389:                cvs_file_attach(sdir, cf);
1.5       jfb       390:
                    391:                /* add a directory entry to the parent */
                    392:                if (CVS_DIR_ENTRIES(sdir) != NULL) {
1.8       jfb       393:                        snprintf(buf, sizeof(buf), "D/%s////",
                    394:                            CVS_FILE_NAME(cf));
1.5       jfb       395:                        ent = cvs_ent_parse(buf);
                    396:                        if (ent == NULL)
                    397:                                cvs_log(LP_ERR,
                    398:                                    "failed to create directory entry");
                    399:                        else
                    400:                                cvs_ent_add(CVS_DIR_ENTRIES(sdir), ent);
                    401:                }
1.1       jfb       402:        }
                    403:
1.4       jfb       404:        if (type == CVS_RESP_CLRSTICKY)
                    405:                cf->cf_ddat->cd_flags &= ~CVS_DIRF_STICKY;
                    406:        else if (type == CVS_RESP_SETSTICKY)
                    407:                cf->cf_ddat->cd_flags |= CVS_DIRF_STICKY;
1.1       jfb       408:
                    409:        return (0);
                    410: }
                    411:
                    412:
                    413: /*
                    414:  * cvs_resp_newentry()
                    415:  *
                    416:  * Handler for the `New-entry' response and `Checked-in' responses.
1.9       jfb       417:  * In the case of `New-entry', we expect the entry line
1.1       jfb       418:  */
                    419:
                    420: static int
                    421: cvs_resp_newentry(struct cvsroot *root, int type, char *line)
                    422: {
                    423:        char entbuf[128];
1.9       jfb       424:        struct cvs_ent *ent;
1.1       jfb       425:        CVSENTRIES *entfile;
                    426:
                    427:        /* get the remote path */
                    428:        cvs_getln(root, entbuf, sizeof(entbuf));
                    429:
                    430:        /* get the new Entries line */
                    431:        if (cvs_getln(root, entbuf, sizeof(entbuf)) < 0)
                    432:                return (-1);
                    433:
                    434:        entfile = cvs_ent_open(line, O_WRONLY);
                    435:        if (entfile == NULL)
                    436:                return (-1);
1.9       jfb       437:        if (type == CVS_RESP_NEWENTRY) {
                    438:                cvs_ent_addln(entfile, entbuf);
1.11      deraadt   439:        } else if (type == CVS_RESP_CHECKEDIN) {
1.9       jfb       440:                ent = cvs_ent_parse(entbuf);
                    441:                if (ent == NULL) {
                    442:                        cvs_log(LP_ERR, "failed to parse entry");
                    443:                        cvs_ent_close(entfile);
                    444:                        return (-1);
                    445:                }
                    446:
                    447:                /* timestamp it to now */
                    448:                ent->ce_mtime = time(&(ent->ce_mtime));
                    449:
                    450:                /* replace the current entry with the one we just received */
                    451:                if (cvs_ent_remove(entfile, ent->ce_name) < 0)
                    452:                        cvs_log(LP_WARN, "failed to remove `%s' entry",
                    453:                            ent->ce_name);
                    454:
                    455:                cvs_ent_add(entfile, ent);
                    456:        }
1.1       jfb       457:        cvs_ent_close(entfile);
                    458:
                    459:        return (0);
                    460: }
                    461:
                    462:
                    463: /*
                    464:  * cvs_resp_cksum()
                    465:  *
                    466:  * Handler for the `Checksum' response.  We store the checksum received for
                    467:  * the next file in a dynamically-allocated buffer pointed to by <cvs_fcksum>.
                    468:  * Upon next file reception, the handler checks to see if there is a stored
                    469:  * checksum.
                    470:  * The file handler must make sure that the checksums match and free the
                    471:  * checksum buffer once it's done to indicate there is no further checksum.
                    472:  */
                    473:
                    474: static int
                    475: cvs_resp_cksum(struct cvsroot *root, int type, char *line)
                    476: {
                    477:        if (cvs_fcksum != NULL) {
                    478:                cvs_log(LP_WARN, "unused checksum");
                    479:                free(cvs_fcksum);
                    480:        }
                    481:
                    482:        cvs_fcksum = strdup(line);
                    483:        if (cvs_fcksum == NULL) {
                    484:                cvs_log(LP_ERRNO, "failed to copy checksum string");
                    485:                return (-1);
                    486:        }
                    487:
                    488:        return (0);
                    489: }
                    490:
                    491:
                    492: /*
                    493:  * cvs_resp_modtime()
                    494:  *
                    495:  * Handler for the `Mod-time' file update modifying response.  The timestamp
                    496:  * given is used to set the last modification time on the next file that
                    497:  * will be received.
                    498:  */
                    499:
                    500: static int
                    501: cvs_resp_modtime(struct cvsroot *root, int type, char *line)
                    502: {
1.4       jfb       503:        cvs_modtime = cvs_datesec(line, CVS_DATE_RFC822, 1);
1.1       jfb       504:        return (0);
                    505: }
                    506:
                    507:
                    508: /*
                    509:  * cvs_resp_updated()
                    510:  *
1.4       jfb       511:  * Handler for the `Updated', `Update-existing', `Created', `Merged' and
                    512:  * `Patched' responses, which all have a very similar format.
1.1       jfb       513:  */
                    514:
                    515: static int
                    516: cvs_resp_updated(struct cvsroot *root, int type, char *line)
                    517: {
                    518:        mode_t fmode;
1.4       jfb       519:        char path[MAXPATHLEN], cksum_buf[CVS_CKSUM_LEN];
1.1       jfb       520:        BUF *fbuf;
1.4       jfb       521:        CVSFILE *cf;
1.12    ! jfb       522:        CVSENTRIES *entfile;
1.1       jfb       523:        struct cvs_ent *ep;
1.2       jfb       524:        struct timeval tv[2];
1.1       jfb       525:
1.4       jfb       526:        STRIP_SLASH(line);
                    527:
                    528:        /* find parent directory of file */
                    529:        cf = cvs_file_find(cvs_files, line);
                    530:        if (cf == NULL) {
                    531:                cvs_log(LP_ERR, "failed to find directory %s", line);
                    532:                return (-1);
                    533:        }
1.1       jfb       534:
                    535:        /* read the remote path of the file */
1.4       jfb       536:        if (cvs_getln(root, path, sizeof(path)) < 0)
                    537:                return (-1);
1.1       jfb       538:
                    539:        /* read the new entry */
1.4       jfb       540:        if (cvs_getln(root, path, sizeof(path)) < 0)
1.1       jfb       541:                return (-1);
1.4       jfb       542:
                    543:        if ((ep = cvs_ent_parse(path)) == NULL)
                    544:                return (-1);
                    545:        snprintf(path, sizeof(path), "%s/%s", line, ep->ce_name);
1.1       jfb       546:
1.12    ! jfb       547:        entfile = cvs_ent_open(line, O_WRONLY);
        !           548:        if (entfile == NULL) {
        !           549:                cvs_ent_free(ep);
        !           550:                return (-1);
        !           551:        }
        !           552:
1.1       jfb       553:        if (type == CVS_RESP_CREATED) {
                    554:                /* set the timestamp as the last one received from Mod-time */
1.4       jfb       555:                ep->ce_mtime = cvs_modtime;
1.12    ! jfb       556:                cvs_ent_add(entfile, ep);
        !           557:        } else if ((type == CVS_RESP_UPDEXIST) || (type == CVS_RESP_UPDATED)) {
        !           558:                if (cvs_ent_remove(entfile, ep->ce_name) < 0)
        !           559:                        cvs_log(LP_WARN, "failed to remove entry for `%s'",
        !           560:                            ep->ce_name);
        !           561:
        !           562:                cvs_ent_add(entfile, ep);
        !           563:        } else if (type == CVS_RESP_MERGED) {
1.1       jfb       564:        }
                    565:
                    566:        fbuf = cvs_recvfile(root, &fmode);
                    567:        if (fbuf == NULL)
                    568:                return (-1);
                    569:
                    570:        cvs_buf_write(fbuf, path, fmode);
1.2       jfb       571:
1.12    ! jfb       572:        if (cvs_modtime != CVS_DATE_DMSEC) {
        !           573:                tv[0].tv_sec = (long)cvs_modtime;
        !           574:                tv[0].tv_usec = 0;
        !           575:                tv[1].tv_sec = (long)cvs_modtime;
        !           576:                tv[1].tv_usec = 0;
        !           577:                if (utimes(path, tv) == -1)
        !           578:                        cvs_log(LP_ERRNO, "failed to set file timestamps");
        !           579:        }
1.1       jfb       580:
                    581:        /* now see if there is a checksum */
                    582:        if (cvs_fcksum != NULL) {
                    583:                if (cvs_cksum(path, cksum_buf, sizeof(cksum_buf)) < 0) {
                    584:                }
                    585:
                    586:                if (strcmp(cksum_buf, cvs_fcksum) != 0) {
                    587:                        cvs_log(LP_ERR, "checksum error on received file");
                    588:                        (void)unlink(line);
                    589:                }
                    590:
                    591:                free(cvs_fcksum);
                    592:                cvs_fcksum = NULL;
                    593:        }
                    594:
                    595:        return (0);
                    596: }
                    597:
                    598:
                    599: /*
                    600:  * cvs_resp_removed()
                    601:  *
1.10      jfb       602:  * Handler for the `Removed' and `Remove-entry' responses.  The `Removed'
                    603:  * response is received when both a file and its entry need to be removed from
                    604:  * the local copy.  The `Remove-entry' is received in cases where the file is
                    605:  * already gone but there is still an entry to remove in the Entries file.
1.1       jfb       606:  */
                    607:
                    608: static int
                    609: cvs_resp_removed(struct cvsroot *root, int type, char *line)
                    610: {
1.3       jfb       611:        char base[MAXPATHLEN], *file;
1.1       jfb       612:        CVSENTRIES *ef;
                    613:
1.3       jfb       614:        cvs_splitpath(line, base, sizeof(base), &file);
1.1       jfb       615:        ef = cvs_ent_open(base, O_RDWR);
1.10      jfb       616:        if (ef == NULL) {
                    617:                cvs_log(LP_ERR, "error handling `Removed' response");
                    618:                if (type == CVS_RESP_RMENTRY)
                    619:                        return (-1);
                    620:        } else {
                    621:                (void)cvs_ent_remove(ef, file);
                    622:                cvs_ent_close(ef);
                    623:        }
                    624:
                    625:        if ((type == CVS_RESP_REMOVED) && (unlink(line) == -1)) {
                    626:                cvs_log(LP_ERRNO, "failed to unlink `%s'", line);
1.1       jfb       627:                return (-1);
1.10      jfb       628:        }
1.1       jfb       629:
                    630:        return (0);
                    631: }
                    632:
                    633:
                    634: /*
                    635:  * cvs_resp_mode()
                    636:  *
                    637:  * Handler for the `Mode' response.
                    638:  */
                    639:
                    640: static int
                    641: cvs_resp_mode(struct cvsroot *root, int type, char *line)
                    642: {
                    643:        if (cvs_strtomode(line, &cvs_lastmode) < 0) {
1.12    ! jfb       644:                cvs_log(LP_ERR, "error handling Mode response");
1.1       jfb       645:                return (-1);
                    646:        }
                    647:        return (0);
                    648: }
                    649:
                    650:
                    651: /*
                    652:  * cvs_resp_modxpand()
                    653:  *
                    654:  * Handler for the `Module-expansion' response.
                    655:  */
                    656:
                    657: static int
                    658: cvs_resp_modxpand(struct cvsroot *root, int type, char *line)
                    659: {
                    660:        return (0);
                    661: }
                    662:
                    663: /*
                    664:  * cvs_resp_rcsdiff()
                    665:  *
                    666:  * Handler for the `Rcs-diff' response.
                    667:  */
                    668:
                    669: static int
                    670: cvs_resp_rcsdiff(struct cvsroot *root, int type, char *line)
                    671: {
                    672:        char file[MAXPATHLEN], buf[MAXPATHLEN], cksum_buf[CVS_CKSUM_LEN];
                    673:        char *fname, *orig, *patch;
                    674:        mode_t fmode;
                    675:        BUF *res, *fcont, *patchbuf;
                    676:        CVSENTRIES *entf;
                    677:        struct cvs_ent *ent;
                    678:
                    679:        /* get remote path and build local path of file to be patched */
                    680:        cvs_getln(root, buf, sizeof(buf));
                    681:        fname = strrchr(buf, '/');
                    682:        if (fname == NULL)
                    683:                fname = buf;
                    684:        snprintf(file, sizeof(file), "%s%s", line, fname);
                    685:
                    686:        /* get updated entry fields */
                    687:        cvs_getln(root, buf, sizeof(buf));
                    688:        ent = cvs_ent_parse(buf);
                    689:        if (ent == NULL) {
                    690:                return (-1);
                    691:        }
                    692:
                    693:        patchbuf = cvs_recvfile(root, &fmode);
                    694:        fcont = cvs_buf_load(file, BUF_AUTOEXT);
                    695:        if (fcont == NULL)
                    696:                return (-1);
                    697:
                    698:        cvs_buf_putc(patchbuf, '\0');
                    699:        cvs_buf_putc(fcont, '\0');
                    700:        orig = cvs_buf_release(fcont);
                    701:        patch = cvs_buf_release(patchbuf);
                    702:
                    703:        res = rcs_patch(orig, patch);
                    704:        if (res == NULL)
                    705:                return (-1);
                    706:
                    707:        cvs_buf_write(res, file, fmode);
                    708:
                    709:        /* now see if there is a checksum */
                    710:        if (cvs_fcksum != NULL) {
                    711:                if (cvs_cksum(file, cksum_buf, sizeof(cksum_buf)) < 0) {
                    712:                }
                    713:
                    714:                if (strcmp(cksum_buf, cvs_fcksum) != 0) {
                    715:                        cvs_log(LP_ERR, "checksum error on received file");
                    716:                        (void)unlink(file);
                    717:                }
                    718:
                    719:                free(cvs_fcksum);
                    720:                cvs_fcksum = NULL;
                    721:        }
                    722:
                    723:        /* update revision in entries */
                    724:        entf = cvs_ent_open(line, O_WRONLY);
                    725:        if (entf == NULL)
                    726:                return (-1);
                    727:
                    728:        cvs_ent_close(entf);
                    729:
                    730:        return (0);
                    731: }
                    732:
                    733:
                    734: /*
                    735:  * cvs_resp_template()
                    736:  *
                    737:  * Handler for the `Template' response.
                    738:  */
                    739:
                    740: static int
                    741: cvs_resp_template(struct cvsroot *root, int type, char *line)
                    742: {
                    743:        mode_t mode;
                    744:        BUF *tmpl;
                    745:
                    746:        tmpl = cvs_recvfile(root, &mode);
                    747:        if (tmpl == NULL)
                    748:                return (-1);
                    749:
                    750:        return (0);
                    751: }