1 /* 2 * Copyright (C) 1986-2005 The Free Software Foundation, Inc. 3 * 4 * Portions Copyright (C) 1998-2005 Derek Price, Ximbiot <http://ximbiot.com>, 5 * and others. 6 * 7 * Portions Copyright (C) 1992, Brian Berliner and Jeff Polk 8 * Portions Copyright (C) 1989-1992, Brian Berliner 9 * 10 * You may distribute under the terms of the GNU General Public License as 11 * specified in the README file that comes with the CVS kit. */ 12 13 #include "cvs.h" 14 #include "getline.h" 15 #include "history.h" 16 #include "save-cwd.h" 17 18 #ifndef DBLKSIZ 19 #define DBLKSIZ 4096 /* since GNU ndbm doesn't define it */ 20 #endif 21 22 static int checkout_file (char *file, char *temp); 23 static char *make_tempfile (void); 24 static void rename_rcsfile (char *temp, char *real); 25 26 #ifndef MY_NDBM 27 static void rename_dbmfile (char *temp); 28 static void write_dbmfile (char *temp); 29 #endif /* !MY_NDBM */ 30 31 /* Structure which describes an administrative file. */ 32 struct admin_file { 33 /* Name of the file, within the CVSROOT directory. */ 34 char *filename; 35 36 /* This is a one line description of what the file is for. It is not 37 currently used, although one wonders whether it should be, somehow. 38 If NULL, then don't process this file in mkmodules (FIXME?: a bit of 39 a kludge; probably should replace this with a flags field). */ 40 char *errormsg; 41 42 /* Contents which the file should have in a new repository. To avoid 43 problems with brain-dead compilers which choke on long string constants, 44 this is a pointer to an array of char * terminated by NULL--each of 45 the strings is concatenated. 46 47 If this field is NULL, the file is not created in a new 48 repository, but it can be added with "cvs add" (just as if one 49 had created the repository with a version of CVS which didn't 50 know about the file) and the checked-out copy will be updated 51 without having to add it to checkoutlist. */ 52 const char * const *contents; 53 }; 54 55 static const char *const loginfo_contents[] = { 56 "# The \"loginfo\" file controls where \"cvs commit\" log information is\n", 57 "# sent. The first entry on a line is a regular expression which must\n", 58 "# match the directory that the change is being made to, relative to the\n", 59 "# $CVSROOT. If a match is found, then the remainder of the line is a\n", 60 "# filter program that should expect log information on its standard input.\n", 61 "#\n", 62 "# If the repository name does not match any of the regular expressions in this\n", 63 "# file, the \"DEFAULT\" line is used, if it is specified.\n", 64 "#\n", 65 "# If the name ALL appears as a regular expression it is always used\n", 66 "# in addition to the first matching regex or DEFAULT.\n", 67 "#\n", 68 "# If any format strings are present in the filter, they will be replaced\n", 69 "# as follows:\n", 70 "# %c = canonical name of the command being executed\n", 71 #ifdef PROXY_SUPPORT 72 "# %R = the name of the referrer, if any, otherwise the value NONE\n", 73 #endif 74 "# %p = path relative to repository\n", 75 "# %r = repository (path portion of $CVSROOT)\n", 76 "# %{sVv} = attribute list = file name, old version number (pre-checkin),\n", 77 "# new version number (post-checkin). When either old or new revision\n", 78 "# is unknown, doesn't exist, or isn't applicable, the string \"NONE\"\n", 79 "# will be placed on the command line instead.\n", 80 "#\n", 81 "# Note that %{sVv} is a list operator and not all elements are necessary.\n", 82 "# Thus %{sv} is a legal format string, but will only be replaced with\n", 83 "# file name and new revision.\n", 84 "# It also generates multiple arguments for each file being operated upon.\n", 85 "# That is, if two files, file1 & file2, are being commited from 1.1 to\n", 86 "# version 1.1.2.1 and from 1.1.2.2 to 1.1.2.3, respectively, %{sVv} will\n", 87 "# generate the following six arguments in this order:\n", 88 "# file1, 1.1, 1.1.2.1, file2, 1.1.2.2, 1.1.2.3.\n", 89 "#\n", 90 "# For example:\n", 91 "#DEFAULT (echo \"\"; id; echo %s; date; cat) >> $CVSROOT/CVSROOT/commitlog\n", 92 "# or\n", 93 "#DEFAULT (echo \"\"; id; echo %{sVv}; date; cat) >> $CVSROOT/CVSROOT/commitlog\n", 94 NULL 95 }; 96 97 static const char *const rcsinfo_contents[] = { 98 "# The \"rcsinfo\" file is used to control templates with which the editor\n", 99 "# is invoked on commit and import.\n", 100 "#\n", 101 "# The first entry on a line is a regular expression which is tested\n", 102 "# against the directory that the change is being made to, relative to the\n", 103 "# $CVSROOT. For the first match that is found, then the remainder of the\n", 104 "# line is the name of the file that contains the template.\n", 105 "#\n", 106 "# If the repository name does not match any of the regular expressions in this\n", 107 "# file, the \"DEFAULT\" line is used, if it is specified.\n", 108 "#\n", 109 "# If the name \"ALL\" appears as a regular expression it is always used\n", 110 "# in addition to the first matching regex or \"DEFAULT\".\n", 111 NULL 112 }; 113 114 115 116 static const char *const verifymsg_contents[] = { 117 "# The \"verifymsg\" file is used to allow verification of logging\n", 118 "# information. It works best when a template (as specified in the\n", 119 "# rcsinfo file) is provided for the logging procedure. Given a\n", 120 "# template with locations for, a bug-id number, a list of people who\n", 121 "# reviewed the code before it can be checked in, and an external\n", 122 "# process to catalog the differences that were code reviewed, the\n", 123 "# following test can be applied to the code:\n", 124 "#\n", 125 "# Making sure that the entered bug-id number is correct.\n", 126 "# Validating that the code that was reviewed is indeed the code being\n", 127 "# checked in (using the bug-id number or a seperate review\n", 128 "# number to identify this particular code set.).\n", 129 "#\n", 130 "# If any of the above test failed, then the commit would be aborted.\n", 131 "#\n", 132 "# Format strings present in the filter will be replaced as follows:\n", 133 "# %c = canonical name of the command being executed\n", 134 #ifdef PROXY_SUPPORT 135 "# %R = the name of the referrer, if any, otherwise the value NONE\n", 136 #endif 137 "# %p = path relative to repository\n", 138 "# %r = repository (path portion of $CVSROOT)\n", 139 "# %l = name of log file to be verified.\n", 140 "#\n", 141 "# If no format strings are present in the filter, a default \" %l\" will\n", 142 "# be appended to the filter, but this usage is deprecated.\n", 143 "#\n", 144 "# Actions such as mailing a copy of the report to each reviewer are\n", 145 "# better handled by an entry in the loginfo file.\n", 146 "#\n", 147 "# One thing that should be noted is the the ALL keyword is not\n", 148 "# supported. There can be only one entry that matches a given\n", 149 "# repository.\n", 150 NULL 151 }; 152 153 static const char *const commitinfo_contents[] = { 154 "# The \"commitinfo\" file is used to control pre-commit checks.\n", 155 "# The filter on the right is invoked with the repository and a list \n", 156 "# of files to check. A non-zero exit of the filter program will \n", 157 "# cause the commit to be aborted.\n", 158 "#\n", 159 "# The first entry on a line is a regular expression which is tested\n", 160 "# against the directory that the change is being committed to, relative\n", 161 "# to the $CVSROOT. For the first match that is found, then the remainder\n", 162 "# of the line is the name of the filter to run.\n", 163 "#\n", 164 "# Format strings present in the filter will be replaced as follows:\n", 165 "# %c = canonical name of the command being executed\n", 166 #ifdef PROXY_SUPPORT 167 "# %R = the name of the referrer, if any, otherwise the value NONE\n", 168 #endif 169 "# %p = path relative to repository\n", 170 "# %r = repository (path portion of $CVSROOT)\n", 171 "# %{s} = file name, file name, ...\n", 172 "#\n", 173 "# If no format strings are present in the filter string, a default of\n", 174 "# \" %r %s\" will be appended to the filter string, but this usage is\n", 175 "# deprecated.\n", 176 "#\n", 177 "# If the repository name does not match any of the regular expressions in this\n", 178 "# file, the \"DEFAULT\" line is used, if it is specified.\n", 179 "#\n", 180 "# If the name \"ALL\" appears as a regular expression it is always used\n", 181 "# in addition to the first matching regex or \"DEFAULT\".\n", 182 NULL 183 }; 184 185 static const char *const taginfo_contents[] = { 186 "# The \"taginfo\" file is used to control pre-tag checks.\n", 187 "# The filter on the right is invoked with the following arguments\n", 188 "# if no format strings are present:\n", 189 "#\n", 190 "# $1 -- tagname\n", 191 "# $2 -- operation \"add\" for tag, \"mov\" for tag -F, and \"del\" for tag -d\n", 192 "# $3 -- tagtype \"?\" on delete, \"T\" for branch, \"N\" for static\n", 193 "# $4 -- repository\n", 194 "# $5-> file revision [file revision ...]\n", 195 "#\n", 196 "# If any format strings are present in the filter, they will be replaced\n", 197 "# as follows:\n", 198 "# %b = branch mode = \"?\" (delete ops - unknown) | \"T\" (branch)\n", 199 "# | \"N\" (not branch)\n", 200 "# %o = operation = \"add\" | \"mov\" | \"del\"\n", 201 "# %c = canonical name of the command being executed\n", 202 #ifdef PROXY_SUPPORT 203 "# %R = the name of the referrer, if any, otherwise the value NONE\n", 204 #endif 205 "# %p = path relative to repository\n", 206 "# %r = repository (path portion of $CVSROOT)\n", 207 "# %t = tagname\n", 208 "# %{sVv} = attribute list = file name, old version tag will be deleted\n", 209 "# from, new version tag will be added to (or deleted from, but\n", 210 "# this feature is deprecated. When either old or new revision is\n", 211 "# unknown, doesn't exist, or isn't applicable, the string \"NONE\"\n", 212 "# will be placed on the command line.\n", 213 "#\n", 214 "# Note that %{sVv} is a list operator and not all elements are necessary.\n", 215 "# Thus %{sV} is a legal format string, but will only be replaced with file\n", 216 "# name and old revision. it also generates multiple arguments for each file\n", 217 "# being operated upon. i.e. if two files, file1 & file2, are having a tag\n", 218 "# moved from version 1.1 to version 1.1.2.9, %{sVv} will generate the\n", 219 "# following six arguments in this order:\n", 220 "# file1, 1.1, 1.1.2.9, file2, 1.1, 1.1.2.9.\n", 221 "#\n", 222 "# A non-zero exit of the filter program will cause the tag to be aborted.\n", 223 "#\n", 224 "# The first entry on a line is a regular expression which is tested\n", 225 "# against the directory that the change is being committed to, relative\n", 226 "# to the $CVSROOT. For the first match that is found, then the remainder\n", 227 "# of the line is the name of the filter to run.\n", 228 "#\n", 229 "# If the repository name does not match any of the regular expressions in this\n", 230 "# file, the \"DEFAULT\" line is used, if it is specified.\n", 231 "#\n", 232 "# If the name \"ALL\" appears as a regular expression it is always used\n", 233 "# in addition to the first matching regex or \"DEFAULT\".\n", 234 NULL 235 }; 236 237 static const char *const preproxy_contents[] = { 238 "# The \"preproxy\" file is called form the secondary server as soon as\n", 239 "# the secondary server determines that it will be proxying a write\n", 240 "# command to a primary server and immediately before it opens a\n", 241 "# connection to the primary server. This script might, for example, be\n", 242 "# used to launch a dial up or VPN connection to the primary server's\n", 243 "# network.\n", 244 "#\n", 245 "# If any format strings are present in the filter, they will be replaced\n", 246 "# as follows:\n", 247 "# %c = canonical name of the command being executed\n", 248 #ifdef PROXY_SUPPORT 249 "# %R = the name of the referrer, if any, otherwise the value NONE\n", 250 #endif 251 "# %p = path relative to repository (currently always \".\")\n", 252 "# %r = repository (path portion of $CVSROOT)\n", 253 "#\n", 254 "# The first entry on a line is a regular expression which is tested\n", 255 "# against the directory that the change is being committed to, relative\n", 256 "# to the $CVSROOT. For the first match that is found, then the remainder\n", 257 "# of the line is the name of the filter to run.\n", 258 "#\n", 259 "# If the repository name does not match any of the regular expressions in this\n", 260 "# file, the \"DEFAULT\" line is used, if it is specified.\n", 261 "#\n", 262 "# If the name \"ALL\" appears as a regular expression it is always used\n", 263 "# in addition to the first matching regex or \"DEFAULT\".\n", 264 NULL 265 }; 266 267 static const char *const postadmin_contents[] = { 268 "# The \"postadmin\" file is called after the \"admin\" command finishes\n", 269 "# processing a directory.\n", 270 "#\n", 271 "# If any format strings are present in the filter, they will be replaced\n", 272 "# as follows:\n", 273 "# %c = canonical name of the command being executed\n", 274 #ifdef PROXY_SUPPORT 275 "# %R = the name of the referrer, if any, otherwise the value NONE\n", 276 #endif 277 "# %p = path relative to repository\n", 278 "# %r = repository (path portion of $CVSROOT)\n", 279 "#\n", 280 "# The first entry on a line is a regular expression which is tested\n", 281 "# against the directory that the change is being committed to, relative\n", 282 "# to the $CVSROOT. For the first match that is found, then the remainder\n", 283 "# of the line is the name of the filter to run.\n", 284 "#\n", 285 "# If the repository name does not match any of the regular expressions in this\n", 286 "# file, the \"DEFAULT\" line is used, if it is specified.\n", 287 "#\n", 288 "# If the name \"ALL\" appears as a regular expression it is always used\n", 289 "# in addition to the first matching regex or \"DEFAULT\".\n", 290 NULL 291 }; 292 293 static const char *const postproxy_contents[] = { 294 "# The \"postproxy\" file is called from a secondary server as soon as\n", 295 "# the secondary server closes its connection to the primary server.\n", 296 "# This script might, for example, be used to shut down a dial up\n", 297 "# or VPN connection to the primary server's network.\n", 298 "#\n", 299 "# If any format strings are present in the filter, they will be replaced\n", 300 "# as follows:\n", 301 "# %c = canonical name of the command being executed\n", 302 #ifdef PROXY_SUPPORT 303 "# %R = the name of the referrer, if any, otherwise the value NONE\n", 304 #endif 305 "# %p = path relative to repository (currently always \".\")\n", 306 "# %r = repository (path portion of $CVSROOT)\n", 307 "#\n", 308 "# The first entry on a line is a regular expression which is tested\n", 309 "# against the directory that the change is being committed to, relative\n", 310 "# to the $CVSROOT. For the first match that is found, then the remainder\n", 311 "# of the line is the name of the filter to run.\n", 312 "#\n", 313 "# If the repository name does not match any of the regular expressions in this\n", 314 "# file, the \"DEFAULT\" line is used, if it is specified.\n", 315 "#\n", 316 "# If the name \"ALL\" appears as a regular expression it is always used\n", 317 "# in addition to the first matching regex or \"DEFAULT\".\n", 318 NULL 319 }; 320 321 static const char *const posttag_contents[] = { 322 "# The \"posttag\" file is called after the \"tag\" command finishes\n", 323 "# processing a directory.\n", 324 "#\n", 325 "# If any format strings are present in the filter, they will be replaced\n", 326 "# as follows:\n", 327 "# %b = branch mode = \"?\" (delete ops - unknown) | \"T\" (branch)\n", 328 "# | \"N\" (not branch)\n", 329 "# %o = operation = \"add\" | \"mov\" | \"del\"\n", 330 "# %c = canonical name of the command being executed\n", 331 #ifdef PROXY_SUPPORT 332 "# %R = the name of the referrer, if any, otherwise the value NONE\n", 333 #endif 334 "# %p = path relative to repository\n", 335 "# %r = repository (path portion of $CVSROOT)\n", 336 "# %t = tagname\n", 337 "# %{sVv} = attribute list = file name, old version tag will be deleted\n", 338 "# from, new version tag will be added to (or deleted from, but\n", 339 "# this feature is deprecated. When either old or new revision is\n", 340 "# unknown, doesn't exist, or isn't applicable, the string \"NONE\"\n", 341 "# will be placed on the command line.\n", 342 "#\n", 343 "# Note that %{sVv} is a list operator and not all elements are necessary.\n", 344 "# Thus %{sV} is a legal format string, but will only be replaced with file\n", 345 "# name and old revision. it also generates multiple arguments for each file\n", 346 "# being operated upon. i.e. if two files, file1 & file2, are having a tag\n", 347 "# moved from version 1.1 to version 1.1.2.9, %{sVv} will generate the\n", 348 "# following six arguments in this order:\n", 349 "# file1, 1.1, 1.1.2.9, file2, 1.1, 1.1.2.9.\n", 350 "#\n", 351 "# The first entry on a line is a regular expression which is tested\n", 352 "# against the directory that the change is being committed to, relative\n", 353 "# to the $CVSROOT. For the first match that is found, then the remainder\n", 354 "# of the line is the name of the filter to run.\n", 355 "#\n", 356 "# If the repository name does not match any of the regular expressions in this\n", 357 "# file, the \"DEFAULT\" line is used, if it is specified.\n", 358 "#\n", 359 "# If the name \"ALL\" appears as a regular expression it is always used\n", 360 "# in addition to the first matching regex or \"DEFAULT\".\n", 361 NULL 362 }; 363 364 static const char *const postwatch_contents[] = { 365 "# The \"postwatch\" file is called after any command finishes writing new\n", 366 "# file attibute (watch/edit) information in a directory.\n", 367 "#\n", 368 "# If any format strings are present in the filter, they will be replaced\n", 369 "# as follows:\n", 370 "# %c = canonical name of the command being executed\n", 371 #ifdef PROXY_SUPPORT 372 "# %R = the name of the referrer, if any, otherwise the value NONE\n", 373 #endif 374 "# %p = path relative to repository\n", 375 "# %r = repository (path portion of $CVSROOT)\n", 376 "#\n", 377 "# The first entry on a line is a regular expression which is tested\n", 378 "# against the directory that the change is being committed to, relative\n", 379 "# to the $CVSROOT. For the first match that is found, then the remainder\n", 380 "# of the line is the name of the filter to run.\n", 381 "#\n", 382 "# If the repository name does not match any of the regular expressions in this\n", 383 "# file, the \"DEFAULT\" line is used, if it is specified.\n", 384 "#\n", 385 "# If the name \"ALL\" appears as a regular expression it is always used\n", 386 "# in addition to the first matching regex or \"DEFAULT\".\n", 387 NULL 388 }; 389 390 static const char *const checkoutlist_contents[] = { 391 "# The \"checkoutlist\" file is used to support additional version controlled\n", 392 "# administrative files in $CVSROOT/CVSROOT, such as template files.\n", 393 "#\n", 394 "# The first entry on a line is a filename which will be checked out from\n", 395 "# the corresponding RCS file in the $CVSROOT/CVSROOT directory.\n", 396 "# The remainder of the line is an error message to use if the file cannot\n", 397 "# be checked out.\n", 398 "#\n", 399 "# File format:\n", 400 "#\n", 401 "# [<whitespace>]<filename>[<whitespace><error message>]<end-of-line>\n", 402 "#\n", 403 "# comment lines begin with '#'\n", 404 NULL 405 }; 406 407 static const char *const cvswrappers_contents[] = { 408 "# This file affects handling of files based on their names.\n", 409 "#\n", 410 #if 0 /* see comments in wrap_add in wrapper.c */ 411 "# The -t/-f options allow one to treat directories of files\n", 412 "# as a single file, or to transform a file in other ways on\n", 413 "# its way in and out of CVS.\n", 414 "#\n", 415 #endif 416 "# The -m option specifies whether CVS attempts to merge files.\n", 417 "#\n", 418 "# The -k option specifies keyword expansion (e.g. -kb for binary).\n", 419 "#\n", 420 "# Format of wrapper file ($CVSROOT/CVSROOT/cvswrappers or .cvswrappers)\n", 421 "#\n", 422 "# wildcard [option value][option value]...\n", 423 "#\n", 424 "# where option is one of\n", 425 "# -f from cvs filter value: path to filter\n", 426 "# -t to cvs filter value: path to filter\n", 427 "# -m update methodology value: MERGE or COPY\n", 428 "# -k expansion mode value: b, o, kkv, &c\n", 429 "#\n", 430 "# and value is a single-quote delimited value.\n", 431 "# For example:\n", 432 "#*.gif -k 'b'\n", 433 NULL 434 }; 435 436 static const char *const notify_contents[] = { 437 "# The \"notify\" file controls where notifications from watches set by\n", 438 "# \"cvs watch add\" or \"cvs edit\" are sent. The first entry on a line is\n", 439 "# a regular expression which is tested against the directory that the\n", 440 "# change is being made to, relative to the $CVSROOT. If it matches,\n", 441 "# then the remainder of the line is a filter program that should contain\n", 442 "# one occurrence of %s for the user to notify, and information on its\n", 443 "# standard input.\n", 444 "#\n", 445 "# \"ALL\" or \"DEFAULT\" can be used in place of the regular expression.\n", 446 "#\n", 447 "# format strings are replaceed as follows:\n", 448 "# %c = canonical name of the command being executed\n", 449 #ifdef PROXY_SUPPORT 450 "# %R = the name of the referrer, if any, otherwise the value NONE\n", 451 #endif 452 "# %p = path relative to repository\n", 453 "# %r = repository (path portion of $CVSROOT)\n", 454 "# %s = user to notify\n", 455 "#\n", 456 "# For example:\n", 457 "#ALL (echo Committed to %r/%p; cat) |mail %s -s \"CVS notification\"\n", 458 NULL 459 }; 460 461 static const char *const modules_contents[] = { 462 "# Three different line formats are valid:\n", 463 "# key -a aliases...\n", 464 "# key [options] directory\n", 465 "# key [options] directory files...\n", 466 "#\n", 467 "# Where \"options\" are composed of:\n", 468 "# -i prog Run \"prog\" on \"cvs commit\" from top-level of module.\n", 469 "# -o prog Run \"prog\" on \"cvs checkout\" of module.\n", 470 "# -e prog Run \"prog\" on \"cvs export\" of module.\n", 471 "# -t prog Run \"prog\" on \"cvs rtag\" of module.\n", 472 "# -u prog Run \"prog\" on \"cvs update\" of module.\n", 473 "# -d dir Place module in directory \"dir\" instead of module name.\n", 474 "# -l Top-level directory only -- do not recurse.\n", 475 "#\n", 476 "# NOTE: If you change any of the \"Run\" options above, you'll have to\n", 477 "# release and re-checkout any working directories of these modules.\n", 478 "#\n", 479 "# And \"directory\" is a path to a directory relative to $CVSROOT.\n", 480 "#\n", 481 "# The \"-a\" option specifies an alias. An alias is interpreted as if\n", 482 "# everything on the right of the \"-a\" had been typed on the command line.\n", 483 "#\n", 484 "# You can encode a module within a module by using the special '&'\n", 485 "# character to interpose another module into the current module. This\n", 486 "# can be useful for creating a module that consists of many directories\n", 487 "# spread out over the entire source repository.\n", 488 NULL 489 }; 490 491 static const char *const config_contents[] = { 492 "# Set `SystemAuth' to `no' if pserver shouldn't check system users/passwords.\n", 493 "#SystemAuth=no\n", 494 "\n", 495 "# Set `LocalKeyword' to specify a local alias for a standard keyword.\n", 496 "#LocalKeyword=MYCVS=CVSHeader\n", 497 "\n", 498 "# Set `KeywordExpand' to `i' followed by a list of keywords to expand or\n", 499 "# `e' followed by a list of keywords to not expand.\n" 500 "#KeywordExpand=iMYCVS,Name,Date\n", 501 "#KeywordExpand=eCVSHeader\n", 502 "\n", 503 #ifdef PRESERVE_PERMISSIONS_SUPPORT 504 "# Set `PreservePermissions' to `yes' to save file status information\n", 505 "# in the repository.\n", 506 "#PreservePermissions=no\n", 507 "\n", 508 #endif 509 "# Set `TopLevelAdmin' to `yes' to create a CVS directory at the top\n", 510 "# level of the new working directory when using the `cvs checkout'\n", 511 "# command.\n", 512 "#TopLevelAdmin=no\n", 513 "\n", 514 "# Put CVS lock files in this directory rather than directly in the repository.\n", 515 "#LockDir=/var/lock/cvs\n", 516 "\n", 517 "# Set `LogHistory' to `all' or `" ALL_HISTORY_REC_TYPES "' to log all transactions to the\n", 518 "# history file, or a subset as needed (ie `TMAR' logs all write operations)\n", 519 "#LogHistory=" ALL_HISTORY_REC_TYPES "\n", 520 "\n", 521 "# Set `RereadLogAfterVerify' to `always' (the default) to allow the verifymsg\n", 522 "# script to change the log message. Set it to `stat' to force CVS to verify\n", 523 "# that the file has changed before reading it (this can take up to an extra\n", 524 "# second per directory being committed, so it is not recommended for large\n", 525 "# repositories. Set it to `never' (the previous CVS behavior) to prevent\n", 526 "# verifymsg scripts from changing the log message.\n", 527 "#RereadLogAfterVerify=always\n", 528 "\n", 529 "# Set `UserAdminOptions' to the list of `cvs admin' commands (options)\n", 530 "# that users not in the `cvsadmin' group are allowed to run. This\n", 531 "# defaults to `k', or only allowing the changing of the default\n", 532 "# keyword expansion mode for files for users not in the `cvsadmin' group.\n", 533 "# This value is ignored if the `cvsadmin' group does not exist.\n", 534 "#\n", 535 "# The following string would enable all `cvs admin' commands for all\n", 536 "# users:\n", 537 "#UserAdminOptions=aAbceIklLmnNostuU\n", 538 #ifdef SUPPORT_OLD_INFO_FMT_STRINGS 539 "\n", 540 "# Set `UseNewInfoFmtStrings' to `no' if you must support a legacy system by\n", 541 "# enabling the deprecated old style info file command line format strings.\n", 542 "# Be warned that these strings could be disabled in any new version of CVS.\n", 543 "UseNewInfoFmtStrings=yes\n", 544 #endif /* SUPPORT_OLD_INFO_FMT_STRINGS */ 545 "\n", 546 "# Set `ImportNewFilesToVendorBranchOnly' to `yes' if you wish to force\n", 547 "# every `cvs import' command to behave as if the `-X' flag was\n", 548 "# specified.\n", 549 "#ImportNewFilesToVendorBranchOnly=no\n", 550 #ifdef PROXY_SUPPORT 551 "\n", 552 "# Set `PrimaryServer' to the CVSROOT to the primary, or write, server when\n", 553 "# establishing one or more read-only mirrors which serve as proxies for\n", 554 "# the write server in write mode or redirect the client to the primary for\n", 555 "# write requests.\n", 556 "#\n", 557 "# For example:\n", 558 "#\n", 559 "# PrimaryServer=:fork:localhost/cvsroot\n", 560 "\n", 561 "# Set `MaxProxyBufferSize' to the the maximum allowable secondary\n", 562 "# buffer memory cache size before the buffer begins being stored to disk, in\n", 563 "# bytes. Must be a positive integer but may end in `k', `M', `G', or `T' (for\n", 564 "# kiilo, mega, giga, & tera, respectively). If an otherwise valid number you\n", 565 "# specify is greater than the SIZE_MAX defined by your system's C compiler,\n", 566 "# then it will be resolved to SIZE_MAX without a warning. Defaults to 8M (8\n", 567 "# megabytes).\n", 568 "#\n", 569 "# High values for MaxProxyBufferSize may speed up a secondary server\n", 570 "# with old hardware and a lot of available memory but can actually slow a\n", 571 "# modern system down slightly.\n", 572 "#\n", 573 "# For example:\n", 574 "#\n", 575 "# MaxProxyBufferSize=1G\n", 576 #endif /* PROXY_SUPPORT */ 577 "\n", 578 "# Set `MaxCommentLeaderLength' to the maximum length permitted for the\n", 579 "# automagically determined comment leader used when expanding the Log\n", 580 "# keyword, in bytes. CVS's behavior when the automagically determined\n", 581 "# comment leader exceeds this length is dependant on the value of\n", 582 "# `UseArchiveCommentLeader' set in this file. `unlimited' is a valid\n", 583 "# setting for this value. Defaults to 20 bytes.\n", 584 "#\n", 585 "# For example:\n", 586 "#\n", 587 "# MaxCommentLeaderLength=20\n", 588 "\n", 589 "# Set `UseArchiveCommentLeader' to `yes' to cause CVS to fall back on\n", 590 "# the comment leader set in the RCS archive file, if any, when the\n", 591 "# automagically determined comment leader exceeds `MaxCommentLeaderLength'\n", 592 "# bytes. If `UseArchiveCommentLeader' is not set and a comment leader\n", 593 "# greater than `MaxCommentLeaderLength' is calculated, the Log keyword\n", 594 "# being examined will not be expanded. Defaults to `no'.\n", 595 "#\n", 596 "# For example:\n", 597 "#\n", 598 "# UseArchiveCommentLeader=no\n", 599 NULL 600 }; 601 602 static const struct admin_file filelist[] = { 603 {CVSROOTADM_CHECKOUTLIST, 604 "a %s file can specify extra CVSROOT files to auto-checkout", 605 checkoutlist_contents}, 606 {CVSROOTADM_COMMITINFO, 607 "a %s file can be used to configure 'cvs commit' checking", 608 commitinfo_contents}, 609 {CVSROOTADM_IGNORE, 610 "a %s file can be used to specify files to ignore", 611 NULL}, 612 {CVSROOTADM_LOGINFO, 613 "no logging of 'cvs commit' messages is done without a %s file", 614 &loginfo_contents[0]}, 615 {CVSROOTADM_MODULES, 616 /* modules is special-cased in mkmodules. */ 617 NULL, 618 modules_contents}, 619 {CVSROOTADM_NOTIFY, 620 "a %s file can be used to specify where notifications go", 621 notify_contents}, 622 {CVSROOTADM_POSTADMIN, 623 "a %s file can be used to configure 'cvs admin' logging", 624 postadmin_contents}, 625 {CVSROOTADM_POSTPROXY, 626 "a %s file can be used to close or log connections to a primary server", 627 postproxy_contents}, 628 {CVSROOTADM_POSTTAG, 629 "a %s file can be used to configure 'cvs tag' logging", 630 posttag_contents}, 631 {CVSROOTADM_POSTWATCH, 632 "a %s file can be used to configure 'cvs watch' logging", 633 postwatch_contents}, 634 {CVSROOTADM_PREPROXY, 635 "a %s file can be used to open or log connections to a primary server", 636 preproxy_contents}, 637 {CVSROOTADM_RCSINFO, 638 "a %s file can be used to configure 'cvs commit' templates", 639 rcsinfo_contents}, 640 {CVSROOTADM_READERS, 641 "a %s file specifies read-only users", 642 NULL}, 643 {CVSROOTADM_TAGINFO, 644 "a %s file can be used to configure 'cvs tag' checking", 645 taginfo_contents}, 646 {CVSROOTADM_VERIFYMSG, 647 "a %s file can be used to validate log messages", 648 verifymsg_contents}, 649 {CVSROOTADM_WRAPPER, 650 "a %s file can be used to specify files to treat as wrappers", 651 cvswrappers_contents}, 652 {CVSROOTADM_WRITERS, 653 "a %s file specifies read/write users", 654 NULL}, 655 656 /* Some have suggested listing CVSROOTADM_PASSWD here too. This 657 would mean that CVS commands which operate on the 658 CVSROOTADM_PASSWD file would transmit hashed passwords over the 659 net. This might seem to be no big deal, as pserver normally 660 transmits cleartext passwords, but the difference is that 661 CVSROOTADM_PASSWD contains *all* passwords, not just the ones 662 currently being used. For example, it could be too easy to 663 accidentally give someone readonly access to CVSROOTADM_PASSWD 664 (e.g. via anonymous CVS or cvsweb), and then if there are any 665 guessable passwords for read/write access (usually there will be) 666 they get read/write access. 667 668 Another worry is the implications of storing old passwords--if 669 someone used a password in the past they might be using it 670 elsewhere, using a similar password, etc, and so saving old 671 passwords, even hashed, is probably not a good idea. */ 672 673 {CVSROOTADM_CONFIG, 674 "a %s file configures various behaviors", 675 config_contents}, 676 {NULL, NULL, NULL} 677 }; 678 679 /* Rebuild the checked out administrative files in directory DIR. */ 680 int 681 mkmodules (char *dir) 682 { 683 struct saved_cwd cwd; 684 char *temp; 685 char *cp, *last, *fname; 686 #ifdef MY_NDBM 687 DBM *db; 688 #endif 689 FILE *fp; 690 char *line = NULL; 691 size_t line_allocated = 0; 692 const struct admin_file *fileptr; 693 694 if (noexec) 695 return 0; 696 697 if (save_cwd (&cwd)) 698 error (1, errno, "Failed to save current directory."); 699 700 if (CVS_CHDIR (dir) < 0) 701 error (1, errno, "cannot chdir to %s", dir); 702 703 /* 704 * First, do the work necessary to update the "modules" database. 705 */ 706 temp = make_tempfile (); 707 switch (checkout_file (CVSROOTADM_MODULES, temp)) 708 { 709 710 case 0: /* everything ok */ 711 #ifdef MY_NDBM 712 /* open it, to generate any duplicate errors */ 713 if ((db = dbm_open (temp, O_RDONLY, 0666)) != NULL) 714 dbm_close (db); 715 #else 716 write_dbmfile (temp); 717 rename_dbmfile (temp); 718 #endif 719 rename_rcsfile (temp, CVSROOTADM_MODULES); 720 break; 721 722 default: 723 error (0, 0, 724 "'cvs checkout' is less functional without a %s file", 725 CVSROOTADM_MODULES); 726 break; 727 } /* switch on checkout_file() */ 728 729 if (unlink_file (temp) < 0 730 && !existence_error (errno)) 731 error (0, errno, "cannot remove %s", temp); 732 free (temp); 733 734 /* Checkout the files that need it in CVSROOT dir */ 735 for (fileptr = filelist; fileptr && fileptr->filename; fileptr++) { 736 if (fileptr->errormsg == NULL) 737 continue; 738 temp = make_tempfile (); 739 if (checkout_file (fileptr->filename, temp) == 0) 740 rename_rcsfile (temp, fileptr->filename); 741 /* else 742 * If there was some problem other than the file not existing, 743 * checkout_file already printed a real error message. If the 744 * file does not exist, it is harmless--it probably just means 745 * that the repository was created with an old version of CVS 746 * which didn't have so many files in CVSROOT. 747 */ 748 749 if (unlink_file (temp) < 0 750 && !existence_error (errno)) 751 error (0, errno, "cannot remove %s", temp); 752 free (temp); 753 } 754 755 fp = CVS_FOPEN (CVSROOTADM_CHECKOUTLIST, "r"); 756 if (fp) 757 { 758 /* 759 * File format: 760 * [<whitespace>]<filename>[<whitespace><error message>]<end-of-line> 761 * 762 * comment lines begin with '#' 763 */ 764 while (getline (&line, &line_allocated, fp) >= 0) 765 { 766 /* skip lines starting with # */ 767 if (line[0] == '#') 768 continue; 769 770 if ((last = strrchr (line, '\n')) != NULL) 771 *last = '\0'; /* strip the newline */ 772 773 /* Skip leading white space. */ 774 for (fname = line; 775 *fname && isspace ((unsigned char) *fname); 776 fname++) 777 ; 778 779 /* Find end of filename. */ 780 for (cp = fname; *cp && !isspace ((unsigned char) *cp); cp++) 781 ; 782 *cp = '\0'; 783 784 temp = make_tempfile (); 785 if (checkout_file (fname, temp) == 0) 786 { 787 rename_rcsfile (temp, fname); 788 } 789 else 790 { 791 /* Skip leading white space before the error message. */ 792 for (cp++; 793 cp < last && *cp && isspace ((unsigned char) *cp); 794 cp++) 795 ; 796 if (cp < last && *cp) 797 error (0, 0, "%s", cp); 798 } 799 if (unlink_file (temp) < 0 800 && !existence_error (errno)) 801 error (0, errno, "cannot remove %s", temp); 802 free (temp); 803 } 804 if (line) 805 free (line); 806 if (ferror (fp)) 807 error (0, errno, "cannot read %s", CVSROOTADM_CHECKOUTLIST); 808 if (fclose (fp) < 0) 809 error (0, errno, "cannot close %s", CVSROOTADM_CHECKOUTLIST); 810 } 811 else 812 { 813 /* Error from CVS_FOPEN. */ 814 if (!existence_error (errno)) 815 error (0, errno, "cannot open %s", CVSROOTADM_CHECKOUTLIST); 816 } 817 818 if (restore_cwd (&cwd)) 819 error (1, errno, "Failed to restore current directory, `%s'.", 820 cwd.name); 821 free_cwd (&cwd); 822 823 return 0; 824 } 825 826 827 828 /* 829 * Yeah, I know, there are NFS race conditions here. 830 */ 831 static char * 832 make_tempfile (void) 833 { 834 static int seed = 0; 835 int fd; 836 char *temp; 837 838 if (seed == 0) 839 seed = getpid (); 840 temp = xmalloc (sizeof (BAKPREFIX) + 40); 841 while (1) 842 { 843 (void) sprintf (temp, "%s%d", BAKPREFIX, seed++); 844 if ((fd = CVS_OPEN (temp, O_CREAT|O_EXCL|O_RDWR, 0666)) != -1) 845 break; 846 if (errno != EEXIST) 847 error (1, errno, "cannot create temporary file %s", temp); 848 } 849 if (close(fd) < 0) 850 error(1, errno, "cannot close temporary file %s", temp); 851 return temp; 852 } 853 854 855 856 /* Get a file. If the file does not exist, return 1 silently. If 857 there is an error, print a message and return 1 (FIXME: probably 858 not a very clean convention). On success, return 0. */ 859 static int 860 checkout_file (char *file, char *temp) 861 { 862 char *rcs; 863 RCSNode *rcsnode; 864 int retcode = 0; 865 866 if (noexec) 867 return 0; 868 869 rcs = Xasprintf ("%s%s", file, RCSEXT); 870 if (!isfile (rcs)) 871 { 872 free (rcs); 873 return 1; 874 } 875 876 rcsnode = RCS_parsercsfile (rcs); 877 if (!rcsnode) 878 { 879 /* Probably not necessary (?); RCS_parsercsfile already printed a 880 message. */ 881 error (0, 0, "Failed to parse `%s'.", rcs); 882 free (rcs); 883 return 1; 884 } 885 886 retcode = RCS_checkout (rcsnode, NULL, NULL, NULL, NULL, temp, NULL, NULL); 887 if (retcode != 0) 888 { 889 /* Probably not necessary (?); RCS_checkout already printed a 890 message. */ 891 error (0, 0, "failed to check out %s file", 892 file); 893 } 894 freercsnode (&rcsnode); 895 free (rcs); 896 return retcode; 897 } 898 899 900 901 #ifndef MY_NDBM 902 903 static void 904 write_dbmfile( char *temp ) 905 { 906 char line[DBLKSIZ], value[DBLKSIZ]; 907 FILE *fp; 908 DBM *db; 909 char *cp, *vp; 910 datum key, val; 911 int len, cont, err = 0; 912 913 fp = xfopen (temp, "r"); 914 if ((db = dbm_open (temp, O_RDWR | O_CREAT | O_TRUNC, 0666)) == NULL) 915 error (1, errno, "cannot open dbm file %s for creation", temp); 916 for (cont = 0; fgets (line, sizeof (line), fp) != NULL;) 917 { 918 if ((cp = strrchr (line, '\n')) != NULL) 919 *cp = '\0'; /* strip the newline */ 920 921 /* 922 * Add the line to the value, at the end if this is a continuation 923 * line; otherwise at the beginning, but only after any trailing 924 * backslash is removed. 925 */ 926 vp = value; 927 if (cont) 928 vp += strlen (value); 929 930 /* 931 * See if the line we read is a continuation line, and strip the 932 * backslash if so. 933 */ 934 len = strlen (line); 935 if (len > 0) 936 cp = &line[len - 1]; 937 else 938 cp = line; 939 if (*cp == '\\') 940 { 941 cont = 1; 942 *cp = '\0'; 943 } 944 else 945 { 946 cont = 0; 947 } 948 (void) strcpy (vp, line); 949 if (value[0] == '#') 950 continue; /* comment line */ 951 vp = value; 952 while (*vp && isspace ((unsigned char) *vp)) 953 vp++; 954 if (*vp == '\0') 955 continue; /* empty line */ 956 957 /* 958 * If this was not a continuation line, add the entry to the database 959 */ 960 if (!cont) 961 { 962 key.dptr = vp; 963 while (*vp && !isspace ((unsigned char) *vp)) 964 vp++; 965 key.dsize = vp - key.dptr; 966 *vp++ = '\0'; /* NULL terminate the key */ 967 while (*vp && isspace ((unsigned char) *vp)) 968 vp++; /* skip whitespace to value */ 969 if (*vp == '\0') 970 { 971 error (0, 0, "warning: NULL value for key `%s'", key.dptr); 972 continue; 973 } 974 val.dptr = vp; 975 val.dsize = strlen (vp); 976 if (dbm_store (db, key, val, DBM_INSERT) == 1) 977 { 978 error (0, 0, "duplicate key found for `%s'", key.dptr); 979 err++; 980 } 981 } 982 } 983 dbm_close (db); 984 if (fclose (fp) < 0) 985 error (0, errno, "cannot close %s", temp); 986 if (err) 987 { 988 /* I think that the size of the buffer needed here is 989 just determined by sizeof (CVSROOTADM_MODULES), the 990 filenames created by make_tempfile, and other things that won't 991 overflow. */ 992 char dotdir[50], dotpag[50], dotdb[50]; 993 994 (void) sprintf (dotdir, "%s.dir", temp); 995 (void) sprintf (dotpag, "%s.pag", temp); 996 (void) sprintf (dotdb, "%s.db", temp); 997 if (unlink_file (dotdir) < 0 998 && !existence_error (errno)) 999 error (0, errno, "cannot remove %s", dotdir); 1000 if (unlink_file (dotpag) < 0 1001 && !existence_error (errno)) 1002 error (0, errno, "cannot remove %s", dotpag); 1003 if (unlink_file (dotdb) < 0 1004 && !existence_error (errno)) 1005 error (0, errno, "cannot remove %s", dotdb); 1006 error (1, 0, "DBM creation failed; correct above errors"); 1007 } 1008 } 1009 1010 static void 1011 rename_dbmfile( char *temp ) 1012 { 1013 /* I think that the size of the buffer needed here is 1014 just determined by sizeof (CVSROOTADM_MODULES), the 1015 filenames created by make_tempfile, and other things that won't 1016 overflow. */ 1017 char newdir[50], newpag[50], newdb[50]; 1018 char dotdir[50], dotpag[50], dotdb[50]; 1019 char bakdir[50], bakpag[50], bakdb[50]; 1020 1021 int dir1_errno = 0, pag1_errno = 0, db1_errno = 0; 1022 int dir2_errno = 0, pag2_errno = 0, db2_errno = 0; 1023 int dir3_errno = 0, pag3_errno = 0, db3_errno = 0; 1024 1025 (void) sprintf (dotdir, "%s.dir", CVSROOTADM_MODULES); 1026 (void) sprintf (dotpag, "%s.pag", CVSROOTADM_MODULES); 1027 (void) sprintf (dotdb, "%s.db", CVSROOTADM_MODULES); 1028 (void) sprintf (bakdir, "%s%s.dir", BAKPREFIX, CVSROOTADM_MODULES); 1029 (void) sprintf (bakpag, "%s%s.pag", BAKPREFIX, CVSROOTADM_MODULES); 1030 (void) sprintf (bakdb, "%s%s.db", BAKPREFIX, CVSROOTADM_MODULES); 1031 (void) sprintf (newdir, "%s.dir", temp); 1032 (void) sprintf (newpag, "%s.pag", temp); 1033 (void) sprintf (newdb, "%s.db", temp); 1034 1035 (void) chmod (newdir, 0666); 1036 (void) chmod (newpag, 0666); 1037 (void) chmod (newdb, 0666); 1038 1039 /* don't mess with me */ 1040 SIG_beginCrSect (); 1041 1042 /* rm .#modules.dir .#modules.pag */ 1043 if (unlink_file (bakdir) < 0) 1044 dir1_errno = errno; 1045 if (unlink_file (bakpag) < 0) 1046 pag1_errno = errno; 1047 if (unlink_file (bakdb) < 0) 1048 db1_errno = errno; 1049 1050 /* mv modules.dir .#modules.dir */ 1051 if (CVS_RENAME (dotdir, bakdir) < 0) 1052 dir2_errno = errno; 1053 /* mv modules.pag .#modules.pag */ 1054 if (CVS_RENAME (dotpag, bakpag) < 0) 1055 pag2_errno = errno; 1056 /* mv modules.db .#modules.db */ 1057 if (CVS_RENAME (dotdb, bakdb) < 0) 1058 db2_errno = errno; 1059 1060 /* mv "temp".dir modules.dir */ 1061 if (CVS_RENAME (newdir, dotdir) < 0) 1062 dir3_errno = errno; 1063 /* mv "temp".pag modules.pag */ 1064 if (CVS_RENAME (newpag, dotpag) < 0) 1065 pag3_errno = errno; 1066 /* mv "temp".db modules.db */ 1067 if (CVS_RENAME (newdb, dotdb) < 0) 1068 db3_errno = errno; 1069 1070 /* OK -- make my day */ 1071 SIG_endCrSect (); 1072 1073 /* I didn't want to call error() when we had signals blocked 1074 (unnecessary?), but do it now. */ 1075 if (dir1_errno && !existence_error (dir1_errno)) 1076 error (0, dir1_errno, "cannot remove %s", bakdir); 1077 if (pag1_errno && !existence_error (pag1_errno)) 1078 error (0, pag1_errno, "cannot remove %s", bakpag); 1079 if (db1_errno && !existence_error (db1_errno)) 1080 error (0, db1_errno, "cannot remove %s", bakdb); 1081 1082 if (dir2_errno && !existence_error (dir2_errno)) 1083 error (0, dir2_errno, "cannot remove %s", bakdir); 1084 if (pag2_errno && !existence_error (pag2_errno)) 1085 error (0, pag2_errno, "cannot remove %s", bakpag); 1086 if (db2_errno && !existence_error (db2_errno)) 1087 error (0, db2_errno, "cannot remove %s", bakdb); 1088 1089 if (dir3_errno && !existence_error (dir3_errno)) 1090 error (0, dir3_errno, "cannot remove %s", bakdir); 1091 if (pag3_errno && !existence_error (pag3_errno)) 1092 error (0, pag3_errno, "cannot remove %s", bakpag); 1093 if (db3_errno && !existence_error (db3_errno)) 1094 error (0, db3_errno, "cannot remove %s", bakdb); 1095 } 1096 1097 #endif /* !MY_NDBM */ 1098 1099 static void 1100 rename_rcsfile (char *temp, char *real) 1101 { 1102 char *bak; 1103 struct stat statbuf; 1104 char *rcs; 1105 1106 /* Set "x" bits if set in original. */ 1107 rcs = Xasprintf ("%s%s", real, RCSEXT); 1108 statbuf.st_mode = 0; /* in case rcs file doesn't exist, but it should... */ 1109 if (stat (rcs, &statbuf) < 0 1110 && !existence_error (errno)) 1111 error (0, errno, "cannot stat %s", rcs); 1112 free (rcs); 1113 1114 if (chmod (temp, 0444 | (statbuf.st_mode & 0111)) < 0) 1115 error (0, errno, "warning: cannot chmod %s", temp); 1116 bak = Xasprintf ("%s%s", BAKPREFIX, real); 1117 1118 /* rm .#loginfo */ 1119 if (unlink_file (bak) < 0 1120 && !existence_error (errno)) 1121 error (0, errno, "cannot remove %s", bak); 1122 1123 /* mv loginfo .#loginfo */ 1124 if (CVS_RENAME (real, bak) < 0 1125 && !existence_error (errno)) 1126 error (0, errno, "cannot rename %s to %s", real, bak); 1127 1128 /* mv "temp" loginfo */ 1129 if (CVS_RENAME (temp, real) < 0 1130 && !existence_error (errno)) 1131 error (0, errno, "cannot rename %s to %s", temp, real); 1132 1133 free (bak); 1134 } 1135 1136 const char *const init_usage[] = { 1137 "Usage: %s %s\n", 1138 "(Specify the --help global option for a list of other help options)\n", 1139 NULL 1140 }; 1141 1142 int 1143 init (int argc, char **argv) 1144 { 1145 /* Name of CVSROOT directory. */ 1146 char *adm; 1147 /* Name of this administrative file. */ 1148 char *info; 1149 /* Name of ,v file for this administrative file. */ 1150 char *info_v; 1151 /* Exit status. */ 1152 int err = 0; 1153 1154 const struct admin_file *fileptr; 1155 1156 umask (cvsumask); 1157 1158 if (argc == -1 || argc > 1) 1159 usage (init_usage); 1160 1161 #ifdef CLIENT_SUPPORT 1162 if (current_parsed_root->isremote) 1163 { 1164 start_server (); 1165 1166 ign_setup (); 1167 send_init_command (); 1168 return get_responses_and_close (); 1169 } 1170 #endif /* CLIENT_SUPPORT */ 1171 1172 /* Note: we do *not* create parent directories as needed like the 1173 old cvsinit.sh script did. Few utilities do that, and a 1174 non-existent parent directory is as likely to be a typo as something 1175 which needs to be created. */ 1176 mkdir_if_needed (current_parsed_root->directory); 1177 1178 adm = Xasprintf ("%s/%s", current_parsed_root->directory, CVSROOTADM); 1179 mkdir_if_needed (adm); 1180 1181 /* This is needed because we pass "fileptr->filename" not "info" 1182 to add_rcs_file below. I think this would be easy to change, 1183 thus nuking the need for CVS_CHDIR here, but I haven't looked 1184 closely (e.g. see wrappers calls within add_rcs_file). */ 1185 if ( CVS_CHDIR (adm) < 0) 1186 error (1, errno, "cannot change to directory %s", adm); 1187 1188 /* Make Emptydir so it's there if we need it */ 1189 mkdir_if_needed (CVSNULLREPOS); 1190 1191 /* 80 is long enough for all the administrative file names, plus 1192 "/" and so on. */ 1193 info = xmalloc (strlen (adm) + 80); 1194 info_v = xmalloc (strlen (adm) + 80); 1195 for (fileptr = filelist; fileptr && fileptr->filename; ++fileptr) 1196 { 1197 if (fileptr->contents == NULL) 1198 continue; 1199 strcpy (info, adm); 1200 strcat (info, "/"); 1201 strcat (info, fileptr->filename); 1202 strcpy (info_v, info); 1203 strcat (info_v, RCSEXT); 1204 if (isfile (info_v)) 1205 /* We will check out this file in the mkmodules step. 1206 Nothing else is required. */ 1207 ; 1208 else 1209 { 1210 int retcode; 1211 1212 if (!isfile (info)) 1213 { 1214 FILE *fp; 1215 const char * const *p; 1216 1217 fp = xfopen (info, "w"); 1218 for (p = fileptr->contents; *p != NULL; ++p) 1219 if (fputs (*p, fp) < 0) 1220 error (1, errno, "cannot write %s", info); 1221 if (fclose (fp) < 0) 1222 error (1, errno, "cannot close %s", info); 1223 } 1224 /* The message used to say " of " and fileptr->filename after 1225 "initial checkin" but I fail to see the point as we know what 1226 file it is from the name. */ 1227 retcode = add_rcs_file ("initial checkin", info_v, 1228 fileptr->filename, "1.1", NULL, 1229 1230 /* No vendor branch. */ 1231 NULL, NULL, 0, NULL, 1232 1233 NULL, 0, NULL, 0); 1234 if (retcode != 0) 1235 /* add_rcs_file already printed an error message. */ 1236 err = 1; 1237 } 1238 } 1239 1240 /* Turn on history logging by default. The user can remove the file 1241 to disable it. */ 1242 strcpy (info, adm); 1243 strcat (info, "/"); 1244 strcat (info, CVSROOTADM_HISTORY); 1245 if (!isfile (info)) 1246 { 1247 FILE *fp; 1248 1249 fp = xfopen (info, "w"); 1250 if (fclose (fp) < 0) 1251 error (1, errno, "cannot close %s", info); 1252 1253 /* Make the new history file world-writeable, since every CVS 1254 user will need to be able to write to it. We use chmod() 1255 because xchmod() is too shy. */ 1256 chmod (info, 0666); 1257 } 1258 1259 /* Make an empty val-tags file to prevent problems creating it later. */ 1260 strcpy (info, adm); 1261 strcat (info, "/"); 1262 strcat (info, CVSROOTADM_VALTAGS); 1263 if (!isfile (info)) 1264 { 1265 FILE *fp; 1266 1267 fp = xfopen (info, "w"); 1268 if (fclose (fp) < 0) 1269 error (1, errno, "cannot close %s", info); 1270 1271 /* Make the new val-tags file world-writeable, since every CVS 1272 user will need to be able to write to it. We use chmod() 1273 because xchmod() is too shy. */ 1274 chmod (info, 0666); 1275 } 1276 1277 free (info); 1278 free (info_v); 1279 1280 mkmodules (adm); 1281 1282 free (adm); 1283 return err; 1284 } 1285