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

Annotation of src/usr.bin/cvs/proto.c, Revision 1.87

1.87    ! xsa         1: /*     $OpenBSD: proto.c,v 1.86 2006/01/02 17:38:17 joris 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:  * CVS client/server protocol
                     28:  * ==========================
                     29:  *
                     30:  * The following code implements the CVS client/server protocol, which is
                     31:  * documented at the following URL:
1.72      joris      32:  *     http://www.iam.unibe.ch/~til/documentation/cvs/cvsclient_toc.html
                     33:  *     http://www.elegosoft.com/cvs/cvsclient_toc.html
1.1       jfb        34:  *
                     35:  * The protocol is split up into two parts; the first part is the client side
                     36:  * of things and is composed of all the response handlers, which are all named
                     37:  * with a prefix of "cvs_resp_".  The second part is the set of request
                     38:  * handlers used by the server.  These handlers process the request and
                     39:  * generate the appropriate response to send back.  The prefix for request
                     40:  * handlers is "cvs_req_".
                     41:  *
                     42:  */
                     43:
1.85      xsa        44: #include "includes.h"
1.1       jfb        45:
                     46: #include "cvs.h"
                     47: #include "log.h"
1.13      jfb        48: #include "proto.h"
1.1       jfb        49:
                     50:
1.11      jfb        51: /* request flags */
1.68      xsa        52: #define CVS_REQF_RESP  0x01
1.11      jfb        53:
                     54:
1.68      xsa        55: static int     cvs_initlog(void);
1.1       jfb        56:
1.18      jfb        57: struct cvs_req cvs_requests[] = {
                     58:        { CVS_REQ_DIRECTORY,     "Directory",         0             },
                     59:        { CVS_REQ_MAXDOTDOT,     "Max-dotdot",        0             },
                     60:        { CVS_REQ_STATICDIR,     "Static-directory",  0             },
                     61:        { CVS_REQ_STICKY,        "Sticky",            0             },
                     62:        { CVS_REQ_ENTRY,         "Entry",             0             },
                     63:        { CVS_REQ_ENTRYEXTRA,    "EntryExtra",        0             },
                     64:        { CVS_REQ_CHECKINTIME,   "Checkin-time",      0             },
                     65:        { CVS_REQ_MODIFIED,      "Modified",          0             },
                     66:        { CVS_REQ_ISMODIFIED,    "Is-modified",       0             },
                     67:        { CVS_REQ_UNCHANGED,     "Unchanged",         0             },
                     68:        { CVS_REQ_USEUNCHANGED,  "UseUnchanged",      0             },
                     69:        { CVS_REQ_NOTIFY,        "Notify",            0             },
                     70:        { CVS_REQ_NOTIFYUSER,    "NotifyUser",        0             },
                     71:        { CVS_REQ_QUESTIONABLE,  "Questionable",      0             },
                     72:        { CVS_REQ_CASE,          "Case",              0             },
                     73:        { CVS_REQ_UTF8,          "Utf8",              0             },
                     74:        { CVS_REQ_ARGUMENT,      "Argument",          0             },
                     75:        { CVS_REQ_ARGUMENTX,     "Argumentx",         0             },
                     76:        { CVS_REQ_GLOBALOPT,     "Global_option",     0             },
                     77:        { CVS_REQ_GZIPSTREAM,    "Gzip-stream",       0             },
                     78:        { CVS_REQ_READCVSRC2,    "read-cvsrc2",       0             },
                     79:        { CVS_REQ_READWRAP,      "read-cvswrappers",  0             },
                     80:        { CVS_REQ_READIGNORE,    "read-cvsignore",    0             },
                     81:        { CVS_REQ_ERRIFREADER,   "Error-If-Reader",   0             },
                     82:        { CVS_REQ_VALIDRCSOPT,   "Valid-RcsOptions",  0             },
                     83:        { CVS_REQ_SET,           "Set",               0             },
                     84:        { CVS_REQ_XPANDMOD,      "expand-modules",    CVS_REQF_RESP },
1.26      jfb        85:        { CVS_REQ_LOG,           "log",               CVS_REQF_RESP },
1.18      jfb        86:        { CVS_REQ_CO,            "co",                CVS_REQF_RESP },
                     87:        { CVS_REQ_EXPORT,        "export",            CVS_REQF_RESP },
1.26      jfb        88:        { CVS_REQ_ANNOTATE,      "annotate",          CVS_REQF_RESP },
                     89:        { CVS_REQ_RDIFF,         "rdiff",             CVS_REQF_RESP },
1.18      jfb        90:        { CVS_REQ_RTAG,          "rtag",              CVS_REQF_RESP },
                     91:        { CVS_REQ_INIT,          "init",              CVS_REQF_RESP },
                     92:        { CVS_REQ_STATUS,        "status",            CVS_REQF_RESP },
                     93:        { CVS_REQ_UPDATE,        "update",            CVS_REQF_RESP },
1.26      jfb        94:        { CVS_REQ_HISTORY,       "history",           CVS_REQF_RESP },
1.18      jfb        95:        { CVS_REQ_IMPORT,        "import",            CVS_REQF_RESP },
                     96:        { CVS_REQ_ADD,           "add",               CVS_REQF_RESP },
                     97:        { CVS_REQ_REMOVE,        "remove",            CVS_REQF_RESP },
                     98:        { CVS_REQ_RELEASE,       "release",           CVS_REQF_RESP },
                     99:        { CVS_REQ_ROOT,          "Root",              0             },
                    100:        { CVS_REQ_VALIDRESP,     "Valid-responses",   0             },
                    101:        { CVS_REQ_VALIDREQ,      "valid-requests",    CVS_REQF_RESP },
                    102:        { CVS_REQ_VERSION,       "version",           CVS_REQF_RESP },
                    103:        { CVS_REQ_NOOP,          "noop",              CVS_REQF_RESP },
                    104:        { CVS_REQ_DIFF,          "diff",              CVS_REQF_RESP },
1.29      jfb       105:        { CVS_REQ_CI,            "ci",                CVS_REQF_RESP },
1.35      jfb       106:        { CVS_REQ_TAG,           "tag",               CVS_REQF_RESP },
1.41      joris     107:        { CVS_REQ_ADMIN,         "admin",             CVS_REQF_RESP },
1.76      xsa       108:        { CVS_REQ_WATCHERS,      "watchers",          CVS_REQF_RESP },
1.79      moritz    109:        { CVS_REQ_WATCH_ON,      "watch-on",          CVS_REQF_RESP },
                    110:        { CVS_REQ_WATCH_OFF,     "watch-off",         CVS_REQF_RESP },
                    111:        { CVS_REQ_WATCH_ADD,     "watch-add",         CVS_REQF_RESP },
                    112:        { CVS_REQ_WATCH_REMOVE,  "watch-remove",      CVS_REQF_RESP },
1.78      xsa       113:        { CVS_REQ_EDITORS,       "editors",           CVS_REQF_RESP },
1.1       jfb       114: };
                    115:
1.18      jfb       116: struct cvs_resp cvs_responses[] = {
                    117:        { CVS_RESP_OK,         "ok"                     },
                    118:        { CVS_RESP_ERROR,      "error"                  },
                    119:        { CVS_RESP_VALIDREQ,   "Valid-requests"         },
                    120:        { CVS_RESP_M,          "M"                      },
                    121:        { CVS_RESP_MBINARY,    "Mbinary"                },
                    122:        { CVS_RESP_MT,         "MT"                     },
                    123:        { CVS_RESP_E,          "E"                      },
                    124:        { CVS_RESP_F,          "F"                      },
                    125:        { CVS_RESP_CREATED,    "Created"                },
                    126:        { CVS_RESP_UPDATED,    "Updated"                },
                    127:        { CVS_RESP_UPDEXIST,   "Update-existing"        },
                    128:        { CVS_RESP_MERGED,     "Merged"                 },
                    129:        { CVS_RESP_REMOVED,    "Removed"                },
1.63      joris     130:        { CVS_RESP_RMENTRY,    "Remove-entry"           },
1.18      jfb       131:        { CVS_RESP_CKSUM,      "Checksum"               },
                    132:        { CVS_RESP_CLRSTATDIR, "Clear-static-directory" },
                    133:        { CVS_RESP_SETSTATDIR, "Set-static-directory"   },
                    134:        { CVS_RESP_NEWENTRY,   "New-entry"              },
                    135:        { CVS_RESP_CHECKEDIN,  "Checked-in"             },
                    136:        { CVS_RESP_MODE,       "Mode"                   },
                    137:        { CVS_RESP_MODTIME,    "Mod-time"               },
                    138:        { CVS_RESP_MODXPAND,   "Module-expansion"       },
                    139:        { CVS_RESP_SETSTICKY,  "Set-sticky"             },
                    140:        { CVS_RESP_CLRSTICKY,  "Clear-sticky"           },
                    141:        { CVS_RESP_RCSDIFF,    "Rcs-diff"               },
                    142:        { CVS_RESP_TEMPLATE,   "Template"               },
1.34      jfb       143:        { CVS_RESP_COPYFILE,   "Copy-file"              },
1.1       jfb       144: };
                    145:
1.68      xsa       146: #define CVS_NBREQ      (sizeof(cvs_requests)/sizeof(cvs_requests[0]))
                    147: #define CVS_NBRESP     (sizeof(cvs_responses)/sizeof(cvs_responses[0]))
1.17      jfb       148:
                    149: /* hack to receive the remote version without outputting it */
1.18      jfb       150: u_int cvs_version_sent = 0;
1.17      jfb       151:
1.13      jfb       152: static char  cvs_proto_buf[4096];
                    153:
                    154: /*
1.37      david     155:  * Output files for protocol logging when the CVS_CLIENT_LOG environment
1.13      jfb       156:  * variable is set.
                    157:  */
                    158: static int   cvs_server_logon = 0;
                    159: static FILE *cvs_server_inlog = NULL;
                    160: static FILE *cvs_server_outlog = NULL;
                    161:
1.28      jfb       162: static pid_t cvs_subproc_pid;
                    163:
1.32      jfb       164: /* last directory sent with cvs_senddir() */
                    165: static char cvs_lastdir[MAXPATHLEN] = "";
                    166:
1.13      jfb       167:
                    168: /*
                    169:  * cvs_connect()
                    170:  *
                    171:  * Open a client connection to the cvs server whose address is given in
                    172:  * the <root> variable.  The method used to connect depends on the
                    173:  * setting of the CVS_RSH variable.
1.17      jfb       174:  * Once the connection has been established, we first send the list of
                    175:  * responses we support and request the list of supported requests from the
                    176:  * server.  Then, a version request is sent and various global flags are sent.
1.13      jfb       177:  */
1.82      joris     178: void
1.13      jfb       179: cvs_connect(struct cvsroot *root)
                    180: {
1.82      joris     181:        size_t len;
1.20      jfb       182:        int argc, infd[2], outfd[2], errfd[2];
1.71      xsa       183:        char *argv[16], *cvs_server_cmd, tmsg[1024], *vresp;
1.13      jfb       184:
1.82      joris     185:        if (root->cr_method == CVS_METHOD_PSERVER)
                    186:                fatal("no pserver support due to security issues");
                    187:        else if ((root->cr_method == CVS_METHOD_KSERVER) ||
1.36      jfb       188:            (root->cr_method == CVS_METHOD_GSERVER) ||
                    189:            (root->cr_method == CVS_METHOD_EXT) ||
1.82      joris     190:            (root->cr_method == CVS_METHOD_FORK))
                    191:                fatal("connection method not supported yet");
1.33      jfb       192:
                    193:        if (root->cr_flags & CVS_ROOT_CONNECTED) {
                    194:                cvs_log(LP_NOTICE, "already connected to CVSROOT");
1.82      joris     195:                return;
1.33      jfb       196:        }
                    197:
1.82      joris     198:        if (pipe(infd) == -1)
                    199:                fatal("failed to create input pipe for client connection");
1.13      jfb       200:
1.82      joris     201:        if (pipe(outfd) == -1)
                    202:                fatal("failed to create output pipe for client connection");
1.13      jfb       203:
1.82      joris     204:        if (pipe(errfd) == -1)
                    205:                fatal("failed to create error pipe for client connection");
1.20      jfb       206:
1.28      jfb       207:        cvs_subproc_pid = fork();
                    208:        if (cvs_subproc_pid == -1) {
1.82      joris     209:                fatal("failed to fork for cvs server connection");
1.30      deraadt   210:        } else if (cvs_subproc_pid == 0) {
1.13      jfb       211:                if ((dup2(infd[0], STDIN_FILENO) == -1) ||
1.82      joris     212:                    (dup2(outfd[1], STDOUT_FILENO) == -1))
1.84      reyk      213:                        fatal("failed to setup standard streams "
                    214:                            "for cvs server");
1.82      joris     215:
1.13      jfb       216:                (void)close(infd[1]);
                    217:                (void)close(outfd[0]);
1.20      jfb       218:                (void)close(errfd[0]);
1.13      jfb       219:
                    220:                argc = 0;
                    221:                argv[argc++] = cvs_rsh;
                    222:
                    223:                if (root->cr_user != NULL) {
                    224:                        argv[argc++] = "-l";
                    225:                        argv[argc++] = root->cr_user;
                    226:                }
                    227:
                    228:                cvs_server_cmd = getenv("CVS_SERVER");
                    229:                if (cvs_server_cmd == NULL)
1.20      jfb       230:                        cvs_server_cmd = CVS_SERVER_DEFAULT;
1.13      jfb       231:
                    232:                argv[argc++] = root->cr_host;
                    233:                argv[argc++] = cvs_server_cmd;
                    234:                argv[argc++] = "server";
                    235:                argv[argc] = NULL;
1.71      xsa       236:
                    237:                if (cvs_trace == 1) {
                    238:                        tmsg[0] = '\0';
                    239:                        for (argc = 0; argv[argc] != NULL; argc++) {
1.82      joris     240:                                len = strlcat(tmsg, argv[argc], sizeof(tmsg));
                    241:                                if (len >= sizeof(tmsg))
                    242:                                        fatal("truncation in cvs_connect");
                    243:
                    244:                                len = strlcat(tmsg, " ", sizeof(tmsg));
                    245:                                if (len >= sizeof(tmsg))
                    246:                                        fatal("truncation in cvs_connect");
1.71      xsa       247:                        }
                    248:                }
1.82      joris     249:
1.71      xsa       250:                cvs_log(LP_TRACE, "Starting server: %s", tmsg);
1.13      jfb       251:
                    252:                execvp(argv[0], argv);
1.82      joris     253:                fatal("failed to execute cvs server");
1.13      jfb       254:        }
                    255:
                    256:        /* we are the parent */
                    257:        (void)close(infd[0]);
                    258:        (void)close(outfd[1]);
1.20      jfb       259:        (void)close(errfd[1]);
1.13      jfb       260:
                    261:        root->cr_srvin = fdopen(infd[1], "w");
1.82      joris     262:        if (root->cr_srvin == NULL)
                    263:                fatal("failed to create pipe stream");
1.13      jfb       264:
                    265:        root->cr_srvout = fdopen(outfd[0], "r");
1.82      joris     266:        if (root->cr_srvout == NULL)
                    267:                fatal("failed to create pipe stream");
1.20      jfb       268:
1.13      jfb       269:        /* make the streams line-buffered */
1.75      xsa       270:        (void)setvbuf(root->cr_srvin, NULL, _IOLBF, (size_t)0);
                    271:        (void)setvbuf(root->cr_srvout, NULL, _IOLBF, (size_t)0);
1.13      jfb       272:
                    273:        cvs_initlog();
                    274:
                    275:        /*
                    276:         * Send the server the list of valid responses, then ask for valid
                    277:         * requests.
                    278:         */
                    279:
1.82      joris     280:        vresp = cvs_resp_getvalid();
                    281:        cvs_sendreq(root, CVS_REQ_VALIDRESP, vresp);
1.80      joris     282:        xfree(vresp);
1.13      jfb       283:
1.82      joris     284:        cvs_sendreq(root, CVS_REQ_VALIDREQ, NULL);
1.13      jfb       285:
1.62      xsa       286:        /* send the CVSROOT to the server */
1.82      joris     287:        cvs_sendreq(root, CVS_REQ_ROOT, root->cr_dir);
1.54      joris     288:
1.40      jfb       289:        /* don't fail if this request doesn't work */
1.82      joris     290:        cvs_sendreq(root, CVS_REQ_VERSION, NULL);
1.17      jfb       291:
1.13      jfb       292:        /* now share our global options with the server */
1.82      joris     293:        if (verbosity <= 1)
                    294:                cvs_sendreq(root, CVS_REQ_GLOBALOPT, "-q");
                    295:        if (verbosity == 0)
                    296:                cvs_sendreq(root, CVS_REQ_GLOBALOPT, "-Q");
                    297:
                    298:        if (cvs_noexec == 1)
                    299:                cvs_sendreq(root, CVS_REQ_GLOBALOPT, "-n");
                    300:
                    301:        if (cvs_nolog == 1)
                    302:                cvs_sendreq(root, CVS_REQ_GLOBALOPT, "-l");
                    303:
                    304:        if (cvs_readonly == 1)
                    305:                cvs_sendreq(root, CVS_REQ_GLOBALOPT, "-r");
1.40      jfb       306:
1.82      joris     307:        if (cvs_trace == 1)
                    308:                cvs_sendreq(root, CVS_REQ_GLOBALOPT, "-t");
1.13      jfb       309:
                    310:        /* not sure why, but we have to send this */
1.82      joris     311:        cvs_sendreq(root, CVS_REQ_USEUNCHANGED, NULL);
1.13      jfb       312:
                    313:        cvs_log(LP_DEBUG, "connected to %s", root->cr_host);
                    314:
1.33      jfb       315:        root->cr_flags |= CVS_ROOT_CONNECTED;
1.13      jfb       316: }
                    317:
                    318:
                    319: /*
                    320:  * cvs_disconnect()
                    321:  *
                    322:  * Disconnect from the cvs server.
                    323:  */
                    324: void
                    325: cvs_disconnect(struct cvsroot *root)
                    326: {
1.33      jfb       327:        if (!(root->cr_flags & CVS_ROOT_CONNECTED))
                    328:                return;
                    329:
1.13      jfb       330:        cvs_log(LP_DEBUG, "closing connection to %s", root->cr_host);
1.82      joris     331:
1.13      jfb       332:        if (root->cr_srvin != NULL) {
                    333:                (void)fclose(root->cr_srvin);
                    334:                root->cr_srvin = NULL;
                    335:        }
                    336:        if (root->cr_srvout != NULL) {
                    337:                (void)fclose(root->cr_srvout);
                    338:                root->cr_srvout = NULL;
                    339:        }
1.33      jfb       340:
                    341:        root->cr_flags &= ~CVS_ROOT_CONNECTED;
1.13      jfb       342: }
                    343:
1.1       jfb       344:
                    345: /*
                    346:  * cvs_req_getbyid()
                    347:  *
                    348:  */
1.13      jfb       349: struct cvs_req*
1.1       jfb       350: cvs_req_getbyid(int reqid)
                    351: {
                    352:        u_int i;
                    353:
                    354:        for (i = 0; i < CVS_NBREQ; i++)
                    355:                if (cvs_requests[i].req_id == reqid)
1.13      jfb       356:                        return &(cvs_requests[i]);
1.31      tedu      357:
1.1       jfb       358:        return (NULL);
                    359: }
                    360:
                    361:
                    362: /*
                    363:  * cvs_req_getbyname()
                    364:  */
1.13      jfb       365: struct cvs_req*
1.1       jfb       366: cvs_req_getbyname(const char *rname)
                    367: {
                    368:        u_int i;
                    369:
                    370:        for (i = 0; i < CVS_NBREQ; i++)
                    371:                if (strcmp(cvs_requests[i].req_str, rname) == 0)
1.13      jfb       372:                        return &(cvs_requests[i]);
1.1       jfb       373:
1.13      jfb       374:        return (NULL);
1.1       jfb       375: }
                    376:
                    377:
                    378: /*
                    379:  * cvs_req_getvalid()
                    380:  *
                    381:  * Build a space-separated list of all the requests that this protocol
                    382:  * implementation supports.
                    383:  */
1.67      xsa       384: char *
1.1       jfb       385: cvs_req_getvalid(void)
                    386: {
                    387:        u_int i;
                    388:        size_t len;
                    389:        char *vrstr;
                    390:        BUF *buf;
                    391:
1.75      xsa       392:        buf = cvs_buf_alloc((size_t)512, BUF_AUTOEXT);
1.1       jfb       393:
                    394:        cvs_buf_set(buf, cvs_requests[0].req_str,
1.75      xsa       395:            strlen(cvs_requests[0].req_str), (size_t)0);
1.1       jfb       396:
                    397:        for (i = 1; i < CVS_NBREQ; i++) {
1.81      xsa       398:                cvs_buf_putc(buf, ' ');
                    399:                cvs_buf_append(buf, cvs_requests[i].req_str,
                    400:                    strlen(cvs_requests[i].req_str));
1.1       jfb       401:        }
                    402:
                    403:        /* NUL-terminate */
1.81      xsa       404:        cvs_buf_putc(buf, '\0');
1.1       jfb       405:
1.70      moritz    406:        len = cvs_buf_len(buf);
1.80      joris     407:        vrstr = (char *)xmalloc(len);
1.75      xsa       408:        cvs_buf_copy(buf, (size_t)0, vrstr, len);
1.1       jfb       409:        cvs_buf_free(buf);
                    410:
                    411:        return (vrstr);
                    412: }
                    413:
                    414:
                    415: /*
                    416:  * cvs_resp_getbyid()
                    417:  *
                    418:  */
1.13      jfb       419: struct cvs_resp*
1.1       jfb       420: cvs_resp_getbyid(int respid)
                    421: {
                    422:        u_int i;
                    423:
1.44      tedu      424:        for (i = 0; i < CVS_NBRESP; i++)
1.13      jfb       425:                if (cvs_responses[i].resp_id == (u_int)respid)
                    426:                        return &(cvs_responses[i]);
1.31      tedu      427:
1.1       jfb       428:        return (NULL);
                    429: }
                    430:
                    431:
                    432: /*
                    433:  * cvs_resp_getbyname()
                    434:  */
1.67      xsa       435: struct cvs_resp *
1.1       jfb       436: cvs_resp_getbyname(const char *rname)
                    437: {
                    438:        u_int i;
                    439:
1.44      tedu      440:        for (i = 0; i < CVS_NBRESP; i++)
1.1       jfb       441:                if (strcmp(cvs_responses[i].resp_str, rname) == 0)
1.13      jfb       442:                        return &(cvs_responses[i]);
1.1       jfb       443:
1.13      jfb       444:        return (NULL);
1.1       jfb       445: }
                    446:
                    447:
                    448: /*
                    449:  * cvs_resp_getvalid()
                    450:  *
                    451:  * Build a space-separated list of all the responses that this protocol
                    452:  * implementation supports.
                    453:  */
1.67      xsa       454: char *
1.1       jfb       455: cvs_resp_getvalid(void)
                    456: {
                    457:        u_int i;
                    458:        size_t len;
                    459:        char *vrstr;
                    460:        BUF *buf;
                    461:
1.75      xsa       462:        buf = cvs_buf_alloc((size_t)512, BUF_AUTOEXT);
1.1       jfb       463:
                    464:        cvs_buf_set(buf, cvs_responses[0].resp_str,
1.75      xsa       465:            strlen(cvs_responses[0].resp_str), (size_t)0);
1.1       jfb       466:
                    467:        for (i = 1; i < CVS_NBRESP; i++) {
1.81      xsa       468:                cvs_buf_putc(buf, ' ');
                    469:                cvs_buf_append(buf, cvs_responses[i].resp_str,
                    470:                    strlen(cvs_responses[i].resp_str));
1.1       jfb       471:        }
                    472:
                    473:        /* NUL-terminate */
1.81      xsa       474:        cvs_buf_putc(buf, '\0');
1.1       jfb       475:
1.70      moritz    476:        len = cvs_buf_len(buf);
1.80      joris     477:        vrstr = (char *)xmalloc(len);
1.75      xsa       478:        cvs_buf_copy(buf, (size_t)0, vrstr, len);
1.1       jfb       479:        cvs_buf_free(buf);
                    480:
                    481:        return (vrstr);
                    482: }
                    483:
                    484:
                    485: /*
                    486:  * cvs_sendfile()
                    487:  *
                    488:  * Send the mode and size of a file followed by the file's contents.
                    489:  * Returns 0 on success, or -1 on failure.
                    490:  */
1.82      joris     491: void
1.13      jfb       492: cvs_sendfile(struct cvsroot *root, const char *path)
1.1       jfb       493: {
1.51      xsa       494:        int fd, l;
1.1       jfb       495:        ssize_t ret;
                    496:        char buf[4096];
                    497:        struct stat st;
                    498:
1.38      jfb       499:        cvs_log(LP_TRACE, "Sending file `%s' to server", basename(path));
                    500:
1.1       jfb       501:        if (stat(path, &st) == -1) {
1.82      joris     502:                fatal("cvs_sendfile(): stat failed on '%s': %s",
                    503:                    path, strerror(errno));
1.1       jfb       504:        }
                    505:
1.82      joris     506:        cvs_modetostr(st.st_mode, buf, sizeof(buf));
1.24      jfb       507:
1.1       jfb       508:        fd = open(path, O_RDONLY, 0);
                    509:        if (fd == -1) {
1.82      joris     510:                fatal("cvs_sendfile(): failed to open '%s': %s",
                    511:                    path, strerror(errno));
1.1       jfb       512:        }
                    513:
1.82      joris     514:        cvs_sendln(root, buf);
                    515:
1.51      xsa       516:        l = snprintf(buf, sizeof(buf), "%lld\n", st.st_size);
                    517:        if (l == -1 || l >= (int)sizeof(buf))
1.82      joris     518:                fatal("overflow in cvs_sendfile");
1.51      xsa       519:
1.82      joris     520:        cvs_sendln(root, buf);
1.1       jfb       521:
                    522:        while ((ret = read(fd, buf, sizeof(buf))) != 0) {
                    523:                if (ret == -1) {
1.24      jfb       524:                        (void)close(fd);
1.82      joris     525:                        fatal("cvs_sendfile: read error on '%s'", path);
1.1       jfb       526:                }
                    527:
1.82      joris     528:                cvs_sendraw(root, buf, (size_t)ret);
1.1       jfb       529:        }
                    530:
                    531:        (void)close(fd);
                    532: }
                    533:
                    534:
                    535: /*
                    536:  * cvs_recvfile()
                    537:  *
                    538:  * Receive the mode and size of a file followed the file's contents and
                    539:  * create or update the file whose path is <path> with the received
                    540:  * information.
                    541:  */
1.14      jfb       542: BUF*
                    543: cvs_recvfile(struct cvsroot *root, mode_t *mode)
1.1       jfb       544: {
                    545:        size_t len;
                    546:        ssize_t ret;
                    547:        off_t fsz, cnt;
                    548:        char buf[4096], *ep;
1.14      jfb       549:        BUF *fbuf;
                    550:
                    551:        fbuf = cvs_buf_alloc(sizeof(buf), BUF_AUTOEXT);
1.1       jfb       552:
1.83      joris     553:        cvs_getln(root, buf, sizeof(buf));
                    554:        cvs_strtomode(buf, mode);
1.1       jfb       555:
1.83      joris     556:        cvs_getln(root, buf, sizeof(buf));
1.1       jfb       557:
                    558:        fsz = (off_t)strtol(buf, &ep, 10);
1.83      joris     559:        if (*ep != '\0')
                    560:                fatal("parse error in file size transmission");
1.1       jfb       561:
                    562:        cnt = 0;
                    563:        do {
                    564:                len = MIN(sizeof(buf), (size_t)(fsz - cnt));
1.6       jfb       565:                if (len == 0)
                    566:                        break;
1.13      jfb       567:                ret = cvs_recvraw(root, buf, len);
1.83      joris     568:                cvs_buf_append(fbuf, buf, (size_t)ret);
1.1       jfb       569:                cnt += (off_t)ret;
                    570:        } while (cnt < fsz);
                    571:
1.14      jfb       572:        return (fbuf);
1.1       jfb       573: }
1.12      jfb       574:
                    575: /*
                    576:  * cvs_sendreq()
                    577:  *
                    578:  * Send a request to the server of type <rid>, with optional arguments
                    579:  * contained in <arg>, which should not be terminated by a newline.
                    580:  * Returns 0 on success, or -1 on failure.
                    581:  */
1.82      joris     582: void
1.13      jfb       583: cvs_sendreq(struct cvsroot *root, u_int rid, const char *arg)
1.12      jfb       584: {
1.51      xsa       585:        int ret, l;
1.13      jfb       586:        struct cvs_req *req;
1.12      jfb       587:
1.82      joris     588:        if (root->cr_srvin == NULL)
                    589:                fatal("cannot send request %u: Not connected", rid);
1.12      jfb       590:
1.13      jfb       591:        req = cvs_req_getbyid(rid);
1.82      joris     592:        if (req == NULL)
                    593:                fatal("unsupported request type %u", rid);
1.12      jfb       594:
1.18      jfb       595:        /* is this request supported by the server? */
                    596:        if (!CVS_GETVR(root, req->req_id)) {
1.57      joris     597:                if (rid == CVS_REQ_VERSION) {
1.82      joris     598:                        cvs_sendreq(root, CVS_REQ_NOOP, arg);
1.57      joris     599:                } else {
                    600:                        cvs_log(LP_WARN,
                    601:                            "remote end does not support request `%s'",
                    602:                            req->req_str);
                    603:                }
1.84      reyk      604:
1.82      joris     605:                return;
1.18      jfb       606:        }
                    607:
1.51      xsa       608:        l = snprintf(cvs_proto_buf, sizeof(cvs_proto_buf), "%s%s%s\n",
1.13      jfb       609:            req->req_str, (arg == NULL) ? "" : " ", (arg == NULL) ? "" : arg);
1.51      xsa       610:        if (l == -1 || l >= (int)sizeof(cvs_proto_buf))
1.82      joris     611:                fatal("overflow in cvs_sendreq");
1.12      jfb       612:
                    613:        if (cvs_server_inlog != NULL)
1.13      jfb       614:                fputs(cvs_proto_buf, cvs_server_inlog);
1.12      jfb       615:
1.13      jfb       616:        ret = fputs(cvs_proto_buf, root->cr_srvin);
1.82      joris     617:        if (ret == EOF)
                    618:                fatal("failed to send request to server");
1.17      jfb       619:
                    620:        if (rid == CVS_REQ_VERSION)
                    621:                cvs_version_sent = 1;
1.12      jfb       622:
1.13      jfb       623:        if (req->req_flags & CVS_REQF_RESP)
1.82      joris     624:                cvs_getresp(root);
1.12      jfb       625: }
                    626:
                    627:
                    628: /*
                    629:  * cvs_getresp()
                    630:  *
                    631:  * Get a response from the server.  This call will actually read and handle
                    632:  * responses from the server until one of the response handlers returns
1.37      david     633:  * non-zero (either an error occurred or the end of the response was reached).
1.12      jfb       634:  * Returns the number of handled commands on success, or -1 on failure.
                    635:  */
1.82      joris     636: void
1.13      jfb       637: cvs_getresp(struct cvsroot *root)
1.12      jfb       638: {
1.82      joris     639:        int ret;
1.13      jfb       640:        size_t len;
1.12      jfb       641:
                    642:        do {
                    643:                /* wait for incoming data */
1.74      xsa       644:                if (fgets(cvs_proto_buf, (int)sizeof(cvs_proto_buf),
1.12      jfb       645:                    root->cr_srvout) == NULL) {
                    646:                        if (feof(root->cr_srvout))
1.82      joris     647:                                return;
                    648:                        fatal("failed to read response from server");
1.12      jfb       649:                }
                    650:
                    651:                if (cvs_server_outlog != NULL)
1.13      jfb       652:                        fputs(cvs_proto_buf, cvs_server_outlog);
1.12      jfb       653:
1.13      jfb       654:                if ((len = strlen(cvs_proto_buf)) != 0) {
1.42      joris     655:                        /* if len - 1 != '\n' the line is truncated */
1.43      joris     656:                        if (cvs_proto_buf[len - 1] == '\n')
1.13      jfb       657:                                cvs_proto_buf[--len] = '\0';
1.12      jfb       658:                }
                    659:
1.13      jfb       660:                ret = cvs_resp_handle(root, cvs_proto_buf);
1.12      jfb       661:        } while (ret == 0);
                    662: }
                    663:
                    664:
                    665: /*
1.13      jfb       666:  * cvs_getln()
                    667:  *
1.18      jfb       668:  * Get a line from the remote end and store it in <lbuf>.  The terminating
1.13      jfb       669:  * newline character is stripped from the result.
                    670:  */
1.83      joris     671: void
1.13      jfb       672: cvs_getln(struct cvsroot *root, char *lbuf, size_t len)
                    673: {
                    674:        size_t rlen;
1.18      jfb       675:        FILE *in;
1.13      jfb       676:
1.18      jfb       677:        if (cvs_cmdop == CVS_OP_SERVER)
                    678:                in = stdin;
                    679:        else
                    680:                in = root->cr_srvout;
                    681:
1.74      xsa       682:        if (fgets(lbuf, (int)len, in) == NULL) {
1.18      jfb       683:                if (ferror(in)) {
1.83      joris     684:                        fatal("cvs_getln: error reading server: %s",
                    685:                            strerror(errno));
1.13      jfb       686:                }
                    687:
1.18      jfb       688:                if (feof(in))
1.13      jfb       689:                        *lbuf = '\0';
                    690:        }
                    691:
                    692:        if (cvs_server_outlog != NULL)
                    693:                fputs(lbuf, cvs_server_outlog);
                    694:
                    695:        rlen = strlen(lbuf);
                    696:        if ((rlen > 0) && (lbuf[rlen - 1] == '\n'))
                    697:                lbuf[--rlen] = '\0';
                    698: }
                    699:
1.19      jfb       700:
1.13      jfb       701: /*
1.12      jfb       702:  * cvs_sendresp()
                    703:  *
1.19      jfb       704:  * Send a response of type <rid> to the client, with optional arguments
1.12      jfb       705:  * contained in <arg>, which should not be terminated by a newline.
                    706:  */
1.87    ! xsa       707: void
1.12      jfb       708: cvs_sendresp(u_int rid, const char *arg)
                    709: {
                    710:        int ret;
1.19      jfb       711:        struct cvs_resp *resp;
1.12      jfb       712:
1.87    ! xsa       713:        if ((resp = cvs_resp_getbyid(rid)) == NULL);
        !           714:                fatal("unsupported response type %u", rid);
1.12      jfb       715:
1.19      jfb       716:        ret = fputs(resp->resp_str, stdout);
1.12      jfb       717:        if (ret == EOF) {
                    718:                cvs_log(LP_ERRNO, "failed to send response to client");
1.30      deraadt   719:        } else {
1.19      jfb       720:                if (arg != NULL) {
                    721:                        putc(' ', stdout);
                    722:                        fputs(arg, stdout);
                    723:                }
1.12      jfb       724:                putc('\n', stdout);
                    725:        }
                    726: }
                    727:
                    728:
                    729: /*
                    730:  * cvs_sendln()
                    731:  *
1.18      jfb       732:  * Send a single line <line> string to the remote end.  The line is sent as is,
1.12      jfb       733:  * without any modifications.
                    734:  */
1.82      joris     735: void
1.12      jfb       736: cvs_sendln(struct cvsroot *root, const char *line)
                    737: {
                    738:        int nl;
                    739:        size_t len;
1.18      jfb       740:        FILE *out;
                    741:
                    742:        if (cvs_cmdop == CVS_OP_SERVER)
                    743:                out = stdout;
                    744:        else
                    745:                out = root->cr_srvin;
1.12      jfb       746:
                    747:        nl = 0;
                    748:        len = strlen(line);
                    749:
                    750:        if ((len > 0) && (line[len - 1] != '\n'))
                    751:                nl = 1;
                    752:
                    753:        if (cvs_server_inlog != NULL) {
                    754:                fputs(line, cvs_server_inlog);
                    755:                if (nl)
1.55      jfb       756:                        putc('\n', cvs_server_inlog);
1.12      jfb       757:        }
1.18      jfb       758:        fputs(line, out);
1.12      jfb       759:        if (nl)
1.55      jfb       760:                putc('\n', out);
1.12      jfb       761: }
                    762:
                    763:
                    764: /*
1.13      jfb       765:  * cvs_sendraw()
1.12      jfb       766:  *
                    767:  * Send the first <len> bytes from the buffer <src> to the server.
                    768:  */
1.82      joris     769: void
1.13      jfb       770: cvs_sendraw(struct cvsroot *root, const void *src, size_t len)
1.12      jfb       771: {
1.18      jfb       772:        FILE *out;
                    773:
                    774:        if (cvs_cmdop == CVS_OP_SERVER)
                    775:                out = stdout;
                    776:        else
                    777:                out = root->cr_srvin;
                    778:
1.12      jfb       779:        if (cvs_server_inlog != NULL)
                    780:                fwrite(src, sizeof(char), len, cvs_server_inlog);
1.82      joris     781:        if (fwrite(src, sizeof(char), len, out) < len)
                    782:                fatal("failed to send data");
1.12      jfb       783: }
                    784:
                    785:
                    786: /*
1.13      jfb       787:  * cvs_recvraw()
1.12      jfb       788:  *
                    789:  * Receive the first <len> bytes from the buffer <src> to the server.
                    790:  */
1.83      joris     791: size_t
1.13      jfb       792: cvs_recvraw(struct cvsroot *root, void *dst, size_t len)
1.12      jfb       793: {
                    794:        size_t ret;
1.18      jfb       795:        FILE *in;
                    796:
                    797:        if (cvs_cmdop == CVS_OP_SERVER)
                    798:                in = stdin;
                    799:        else
                    800:                in = root->cr_srvout;
1.12      jfb       801:
1.18      jfb       802:        ret = fread(dst, sizeof(char), len, in);
1.83      joris     803:        if (ret == 0) {
                    804:                if (ferror(in)) {
                    805:                        fatal("cvs_recvraw: error reading from server: %s",
                    806:                            strerror(errno));
                    807:                }
                    808:        } else {
                    809:                if (cvs_server_outlog != NULL)
                    810:                        fwrite(dst, sizeof(char), len, cvs_server_outlog);
                    811:        }
                    812:
                    813:        return (ret);
1.12      jfb       814: }
                    815:
                    816:
                    817: /*
1.13      jfb       818:  * cvs_senddir()
1.12      jfb       819:  *
1.32      jfb       820:  * Send a `Directory' request along with the 2 paths that follow it.  If
                    821:  * the directory info to be sent is the same as the last info sent, the
                    822:  * call does nothing and simply returns without an error.
1.12      jfb       823:  */
1.82      joris     824: void
1.31      tedu      825: cvs_senddir(struct cvsroot *root, CVSFILE *dir)
1.12      jfb       826: {
1.60      xsa       827:        size_t len;
1.28      jfb       828:        char lbuf[MAXPATHLEN], rbuf[MAXPATHLEN];
1.12      jfb       829:
1.47      jfb       830:        if (dir->cf_type != DT_DIR)
1.82      joris     831:                fatal("cvs_senddir(): cf_type != DT_DIR: %d", dir->cf_type);
1.47      jfb       832:
1.32      jfb       833:        cvs_file_getpath(dir, lbuf, sizeof(lbuf));
1.45      joris     834:        if (strcmp(lbuf, cvs_lastdir) == 0 && cvs_cmdop != CVS_OP_CHECKOUT)
1.82      joris     835:                return;
1.32      jfb       836:
1.82      joris     837:        if (dir->cf_repo == NULL) {
                    838:                len = strlcpy(rbuf, root->cr_dir, sizeof(rbuf));
                    839:                if (len >= sizeof(rbuf))
                    840:                        fatal("cvs_senddir: path truncation");
                    841:        } else {
1.60      xsa       842:                len = cvs_path_cat(root->cr_dir, dir->cf_repo, rbuf,
                    843:                    sizeof(rbuf));
                    844:                if (len >= sizeof(rbuf))
1.82      joris     845:                        fatal("cvs_senddir: path truncation");
1.51      xsa       846:        }
1.12      jfb       847:
1.82      joris     848:        cvs_sendreq(root, CVS_REQ_DIRECTORY, lbuf);
                    849:        cvs_sendln(root, rbuf);
1.28      jfb       850:
1.82      joris     851:        len = strlcpy(cvs_lastdir, lbuf, sizeof(cvs_lastdir));
                    852:        if (len >= sizeof(lbuf))
                    853:                fatal("path truncation in cvs_senddir");
1.12      jfb       854: }
                    855:
                    856:
                    857: /*
1.13      jfb       858:  * cvs_sendarg()
1.12      jfb       859:  *
                    860:  * Send the argument <arg> to the server.  The argument <append> is used to
                    861:  * determine if the argument should be simply appended to the last argument
                    862:  * sent or if it should be created as a new argument (0).
                    863:  */
1.82      joris     864: void
1.13      jfb       865: cvs_sendarg(struct cvsroot *root, const char *arg, int append)
1.12      jfb       866: {
1.82      joris     867:        cvs_sendreq(root, ((append == 0) ? CVS_REQ_ARGUMENT :
                    868:            CVS_REQ_ARGUMENTX), arg);
1.12      jfb       869: }
                    870:
                    871:
                    872: /*
1.13      jfb       873:  * cvs_sendentry()
1.12      jfb       874:  *
                    875:  * Send an `Entry' request to the server along with the mandatory fields from
                    876:  * the CVS entry <ent> (which are the name and revision).
                    877:  */
1.82      joris     878: void
1.47      jfb       879: cvs_sendentry(struct cvsroot *root, const CVSFILE *file)
1.12      jfb       880: {
1.51      xsa       881:        int l;
1.77      xsa       882:        char ebuf[CVS_ENT_MAXLINELEN], numbuf[64];
1.12      jfb       883:
1.82      joris     884:        if (file->cf_type != DT_REG)
                    885:                fatal("cvs_sendentry: cf_type != DT_REG: %d", file->cf_type);
1.48      joris     886:
                    887:        /* don't send Entry for unknown files */
                    888:        if (file->cf_cvstat == CVS_FST_UNKNOWN)
1.82      joris     889:                return;
1.47      jfb       890:
1.51      xsa       891:        l = snprintf(ebuf, sizeof(ebuf), "/%s/%s%s///", file->cf_name,
1.49      joris     892:            (file->cf_cvstat == CVS_FST_REMOVED) ? "-" : "",
1.47      jfb       893:            rcsnum_tostr(file->cf_lrev, numbuf, sizeof(numbuf)));
1.82      joris     894:        if (l == -1 || l >= (int)sizeof(ebuf))
                    895:                fatal("cvs_sendentry: overflow when creating entry buffer");
1.12      jfb       896:
1.82      joris     897:        cvs_sendreq(root, CVS_REQ_ENTRY, ebuf);
1.12      jfb       898: }
                    899:
                    900:
                    901: /*
1.13      jfb       902:  * cvs_initlog()
1.12      jfb       903:  *
                    904:  * Initialize protocol logging if the CVS_CLIENT_LOG environment variable is
                    905:  * set.  In this case, the variable's value is used as a path to which the
                    906:  * appropriate suffix is added (".in" for server input and ".out" for server
                    907:  * output.
                    908:  * Returns 0 on success, or -1 on failure.
                    909:  */
                    910: static int
1.13      jfb       911: cvs_initlog(void)
1.12      jfb       912: {
1.52      joris     913:        int l;
                    914:        u_int i;
                    915:        char *env, *envdup, buf[MAXPATHLEN], fpath[MAXPATHLEN];
                    916:        char rpath[MAXPATHLEN], *s;
                    917:        struct stat st;
                    918:        time_t now;
                    919:        struct passwd *pwd;
1.12      jfb       920:
1.13      jfb       921:        /* avoid doing it more than once */
                    922:        if (cvs_server_logon)
                    923:                return (0);
                    924:
1.12      jfb       925:        env = getenv("CVS_CLIENT_LOG");
                    926:        if (env == NULL)
                    927:                return (0);
                    928:
1.80      joris     929:        envdup = xstrdup(env);
1.52      joris     930:        if ((s = strchr(envdup, '%')) != NULL)
                    931:                *s = '\0';
                    932:
                    933:        strlcpy(buf, env, sizeof(buf));
                    934:        strlcpy(rpath, envdup, sizeof(rpath));
1.80      joris     935:        xfree(envdup);
1.52      joris     936:
                    937:        s = buf;
                    938:        while ((s = strchr(s, '%')) != NULL) {
                    939:                *s++;
                    940:                switch (*s) {
                    941:                case 'c':
                    942:                        strlcpy(fpath, cvs_command, sizeof(fpath));
                    943:                        break;
                    944:                case 'd':
                    945:                        time(&now);
1.59      niallo    946:                        strlcpy(fpath, ctime(&now), sizeof(fpath));
1.52      joris     947:                        break;
                    948:                case 'p':
                    949:                        snprintf(fpath, sizeof(fpath), "%d", getpid());
                    950:                        break;
                    951:                case 'u':
                    952:                        if ((pwd = getpwuid(getuid())) != NULL)
                    953:                                strlcpy(fpath, pwd->pw_name, sizeof(fpath));
                    954:                        else
                    955:                                fpath[0] = '\0';
                    956:                        endpwent();
                    957:                        break;
                    958:                default:
                    959:                        fpath[0] = '\0';
                    960:                        break;
1.58      joris     961:                }
1.52      joris     962:
                    963:                if (fpath[0] != '\0') {
                    964:                        strlcat(rpath, "-", sizeof(rpath));
                    965:                        strlcat(rpath, fpath, sizeof(rpath));
                    966:                }
                    967:        }
                    968:
                    969:        for (i = 0; i < UINT_MAX; i++) {
                    970:                l = snprintf(fpath, sizeof(fpath), "%s-%d.in", rpath, i);
                    971:                if (l == -1 || l >= (int)sizeof(fpath)) {
                    972:                        errno = ENAMETOOLONG;
                    973:                        cvs_log(LP_ERRNO, "%s", fpath);
                    974:                        return (-1);
                    975:                }
                    976:
                    977:                if (stat(fpath, &st) != -1)
                    978:                        continue;
                    979:
                    980:                if (errno != ENOENT)
                    981:                        return (-1);
                    982:
                    983:                break;
                    984:        }
                    985:
1.12      jfb       986:        cvs_server_inlog = fopen(fpath, "w");
                    987:        if (cvs_server_inlog == NULL) {
                    988:                cvs_log(LP_ERRNO, "failed to open server input log `%s'",
                    989:                    fpath);
                    990:                return (-1);
                    991:        }
                    992:
1.52      joris     993:        for (i = 0; i < UINT_MAX; i++) {
                    994:                l = snprintf(fpath, sizeof(fpath), "%s-%d.out", rpath, i);
                    995:                if (l == -1 || l >= (int)sizeof(fpath)) {
                    996:                        errno = ENAMETOOLONG;
                    997:                        cvs_log(LP_ERRNO, "%s", fpath);
                    998:                        return (-1);
                    999:                }
                   1000:
                   1001:                if (stat(fpath, &st) != -1)
                   1002:                        continue;
                   1003:
                   1004:                if (errno != ENOENT)
                   1005:                        return (-1);
                   1006:
                   1007:                break;
                   1008:        }
                   1009:
1.12      jfb      1010:        cvs_server_outlog = fopen(fpath, "w");
                   1011:        if (cvs_server_outlog == NULL) {
                   1012:                cvs_log(LP_ERRNO, "failed to open server output log `%s'",
                   1013:                    fpath);
                   1014:                return (-1);
                   1015:        }
                   1016:
                   1017:        /* make the streams line-buffered */
1.75      xsa      1018:        setvbuf(cvs_server_inlog, NULL, _IOLBF, (size_t)0);
                   1019:        setvbuf(cvs_server_outlog, NULL, _IOLBF, (size_t)0);
1.12      jfb      1020:
1.13      jfb      1021:        cvs_server_logon = 1;
1.12      jfb      1022:
                   1023:        return (0);
                   1024: }