2 * Copyright (C) 1986-2005 The Free Software Foundation, Inc.
4 * Portions Copyright (C) 1998-2005 Derek Price, Ximbiot <http://ximbiot.com>,
7 * Portions Copyright (C) 1992, Brian Berliner and Jeff Polk
8 * Portions Copyright (C) 1989-1992, Brian Berliner
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. */
19 #define DBLKSIZ 4096 /* since GNU ndbm doesn't define it */
22 static int checkout_file (char *file
, char *temp
);
23 static char *make_tempfile (void);
24 static void rename_rcsfile (char *temp
, char *real
);
27 static void rename_dbmfile (char *temp
);
28 static void write_dbmfile (char *temp
);
31 /* Structure which describes an administrative file. */
33 /* Name of the file, within the CVSROOT directory. */
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). */
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.
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
;
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",
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",
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",
68 "# If any format strings are present in the filter, they will be replaced\n",
70 "# %c = canonical name of the command being executed\n",
72 "# %R = the name of the referrer, if any, otherwise the value NONE\n",
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",
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",
91 "#DEFAULT (echo \"\"; id; echo %s; date; cat) >> $CVSROOT/CVSROOT/commitlog\n",
93 "#DEFAULT (echo \"\"; id; echo %{sVv}; date; cat) >> $CVSROOT/CVSROOT/commitlog\n",
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",
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",
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",
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",
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",
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",
130 "# If any of the above test failed, then the commit would be aborted.\n",
132 "# Format strings present in the filter will be replaced as follows:\n",
133 "# %c = canonical name of the command being executed\n",
135 "# %R = the name of the referrer, if any, otherwise the value NONE\n",
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",
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",
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",
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",
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",
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",
164 "# Format strings present in the filter will be replaced as follows:\n",
165 "# %c = canonical name of the command being executed\n",
167 "# %R = the name of the referrer, if any, otherwise the value NONE\n",
169 "# %p = path relative to repository\n",
170 "# %r = repository (path portion of $CVSROOT)\n",
171 "# %{s} = file name, file name, ...\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",
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",
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",
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",
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",
196 "# If any format strings are present in the filter, they will be replaced\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",
203 "# %R = the name of the referrer, if any, otherwise the value NONE\n",
205 "# %p = path relative to repository\n",
206 "# %r = repository (path portion of $CVSROOT)\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",
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",
222 "# A non-zero exit of the filter program will cause the tag to be aborted.\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",
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",
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",
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",
245 "# If any format strings are present in the filter, they will be replaced\n",
247 "# %c = canonical name of the command being executed\n",
249 "# %R = the name of the referrer, if any, otherwise the value NONE\n",
251 "# %p = path relative to repository (currently always \".\")\n",
252 "# %r = repository (path portion of $CVSROOT)\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",
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",
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",
267 static const char *const postadmin_contents
[] = {
268 "# The \"postadmin\" file is called after the \"admin\" command finishes\n",
269 "# processing a directory.\n",
271 "# If any format strings are present in the filter, they will be replaced\n",
273 "# %c = canonical name of the command being executed\n",
275 "# %R = the name of the referrer, if any, otherwise the value NONE\n",
277 "# %p = path relative to repository\n",
278 "# %r = repository (path portion of $CVSROOT)\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",
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",
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",
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",
299 "# If any format strings are present in the filter, they will be replaced\n",
301 "# %c = canonical name of the command being executed\n",
303 "# %R = the name of the referrer, if any, otherwise the value NONE\n",
305 "# %p = path relative to repository (currently always \".\")\n",
306 "# %r = repository (path portion of $CVSROOT)\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",
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",
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",
321 static const char *const posttag_contents
[] = {
322 "# The \"posttag\" file is called after the \"tag\" command finishes\n",
323 "# processing a directory.\n",
325 "# If any format strings are present in the filter, they will be replaced\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",
332 "# %R = the name of the referrer, if any, otherwise the value NONE\n",
334 "# %p = path relative to repository\n",
335 "# %r = repository (path portion of $CVSROOT)\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",
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",
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",
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",
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",
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",
368 "# If any format strings are present in the filter, they will be replaced\n",
370 "# %c = canonical name of the command being executed\n",
372 "# %R = the name of the referrer, if any, otherwise the value NONE\n",
374 "# %p = path relative to repository\n",
375 "# %r = repository (path portion of $CVSROOT)\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",
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",
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",
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",
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",
401 "# [<whitespace>]<filename>[<whitespace><error message>]<end-of-line>\n",
403 "# comment lines begin with '#'\n",
407 static const char *const cvswrappers_contents
[] = {
408 "# This file affects handling of files based on their names.\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",
416 "# The -m option specifies whether CVS attempts to merge files.\n",
418 "# The -k option specifies keyword expansion (e.g. -kb for binary).\n",
420 "# Format of wrapper file ($CVSROOT/CVSROOT/cvswrappers or .cvswrappers)\n",
422 "# wildcard [option value][option value]...\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",
430 "# and value is a single-quote delimited value.\n",
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",
445 "# \"ALL\" or \"DEFAULT\" can be used in place of the regular expression.\n",
447 "# format strings are replaceed as follows:\n",
448 "# %c = canonical name of the command being executed\n",
450 "# %R = the name of the referrer, if any, otherwise the value NONE\n",
452 "# %p = path relative to repository\n",
453 "# %r = repository (path portion of $CVSROOT)\n",
454 "# %s = user to notify\n",
457 "#ALL (echo Committed to %r/%p; cat) |mail %s -s \"CVS notification\"\n",
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",
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",
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",
479 "# And \"directory\" is a path to a directory relative to $CVSROOT.\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",
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",
491 static const char *const config_contents
[] = {
492 "# Set `SystemAuth' to `no' if pserver shouldn't check system users/passwords.\n",
495 "# Set `LocalKeyword' to specify a local alias for a standard keyword.\n",
496 "#LocalKeyword=MYCVS=CVSHeader\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",
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",
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",
512 "#TopLevelAdmin=no\n",
514 "# Put CVS lock files in this directory rather than directly in the repository.\n",
515 "#LockDir=/var/lock/cvs\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",
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",
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",
535 "# The following string would enable all `cvs admin' commands for all\n",
537 "#AdminGroup=wheel\n",
538 "#AdminOptions=aAbceIklLmnNostuU\n",
539 #ifdef SUPPORT_OLD_INFO_FMT_STRINGS
541 "# Set `UseNewInfoFmtStrings' to `no' if you must support a legacy system by\n",
542 "# enabling the deprecated old style info file command line format strings.\n",
543 "# Be warned that these strings could be disabled in any new version of CVS.\n",
544 "UseNewInfoFmtStrings=yes\n",
545 #endif /* SUPPORT_OLD_INFO_FMT_STRINGS */
547 "# Set `ImportNewFilesToVendorBranchOnly' to `yes' if you wish to force\n",
548 "# every `cvs import' command to behave as if the `-X' flag was\n",
550 "#ImportNewFilesToVendorBranchOnly=no\n",
553 "# Set `PrimaryServer' to the CVSROOT to the primary, or write, server when\n",
554 "# establishing one or more read-only mirrors which serve as proxies for\n",
555 "# the write server in write mode or redirect the client to the primary for\n",
556 "# write requests.\n",
560 "# PrimaryServer=:fork:localhost/cvsroot\n",
562 "# Set `MaxProxyBufferSize' to the the maximum allowable secondary\n",
563 "# buffer memory cache size before the buffer begins being stored to disk, in\n",
564 "# bytes. Must be a positive integer but may end in `k', `M', `G', or `T' (for\n",
565 "# kiilo, mega, giga, & tera, respectively). If an otherwise valid number you\n",
566 "# specify is greater than the SIZE_MAX defined by your system's C compiler,\n",
567 "# then it will be resolved to SIZE_MAX without a warning. Defaults to 8M (8\n",
570 "# High values for MaxProxyBufferSize may speed up a secondary server\n",
571 "# with old hardware and a lot of available memory but can actually slow a\n",
572 "# modern system down slightly.\n",
576 "# MaxProxyBufferSize=1G\n",
577 #endif /* PROXY_SUPPORT */
579 "# Set `MaxCommentLeaderLength' to the maximum length permitted for the\n",
580 "# automagically determined comment leader used when expanding the Log\n",
581 "# keyword, in bytes. CVS's behavior when the automagically determined\n",
582 "# comment leader exceeds this length is dependant on the value of\n",
583 "# `UseArchiveCommentLeader' set in this file. `unlimited' is a valid\n",
584 "# setting for this value. Defaults to 20 bytes.\n",
588 "# MaxCommentLeaderLength=20\n",
590 "# Set `UseArchiveCommentLeader' to `yes' to cause CVS to fall back on\n",
591 "# the comment leader set in the RCS archive file, if any, when the\n",
592 "# automagically determined comment leader exceeds `MaxCommentLeaderLength'\n",
593 "# bytes. If `UseArchiveCommentLeader' is not set and a comment leader\n",
594 "# greater than `MaxCommentLeaderLength' is calculated, the Log keyword\n",
595 "# being examined will not be expanded. Defaults to `no'.\n",
599 "# UseArchiveCommentLeader=no\n",
601 "# Set this to the name of a local tag to use in addition to Id\n",
606 static const struct admin_file filelist
[] = {
607 {CVSROOTADM_CHECKOUTLIST
,
608 "a %s file can specify extra CVSROOT files to auto-checkout",
609 checkoutlist_contents
},
610 {CVSROOTADM_COMMITINFO
,
611 "a %s file can be used to configure 'cvs commit' checking",
612 commitinfo_contents
},
614 "a %s file can be used to specify files to ignore",
617 "no logging of 'cvs commit' messages is done without a %s file",
618 &loginfo_contents
[0]},
620 /* modules is special-cased in mkmodules. */
624 "a %s file can be used to specify where notifications go",
626 {CVSROOTADM_POSTADMIN
,
627 "a %s file can be used to configure 'cvs admin' logging",
629 {CVSROOTADM_POSTPROXY
,
630 "a %s file can be used to close or log connections to a primary server",
633 "a %s file can be used to configure 'cvs tag' logging",
635 {CVSROOTADM_POSTWATCH
,
636 "a %s file can be used to configure 'cvs watch' logging",
638 {CVSROOTADM_PREPROXY
,
639 "a %s file can be used to open or log connections to a primary server",
642 "a %s file can be used to configure 'cvs commit' templates",
645 "a %s file specifies read-only users",
648 "a %s file can be used to configure 'cvs tag' checking",
650 {CVSROOTADM_VERIFYMSG
,
651 "a %s file can be used to validate log messages",
654 "a %s file can be used to specify files to treat as wrappers",
655 cvswrappers_contents
},
657 "a %s file specifies read/write users",
660 /* Some have suggested listing CVSROOTADM_PASSWD here too. This
661 would mean that CVS commands which operate on the
662 CVSROOTADM_PASSWD file would transmit hashed passwords over the
663 net. This might seem to be no big deal, as pserver normally
664 transmits cleartext passwords, but the difference is that
665 CVSROOTADM_PASSWD contains *all* passwords, not just the ones
666 currently being used. For example, it could be too easy to
667 accidentally give someone readonly access to CVSROOTADM_PASSWD
668 (e.g. via anonymous CVS or cvsweb), and then if there are any
669 guessable passwords for read/write access (usually there will be)
670 they get read/write access.
672 Another worry is the implications of storing old passwords--if
673 someone used a password in the past they might be using it
674 elsewhere, using a similar password, etc, and so saving old
675 passwords, even hashed, is probably not a good idea. */
678 "a %s file configures various behaviors",
683 /* Rebuild the checked out administrative files in directory DIR. */
685 mkmodules (char *dir
)
687 struct saved_cwd cwd
;
689 char *cp
, *last
, *fname
;
695 size_t line_allocated
= 0;
696 const struct admin_file
*fileptr
;
702 error (1, errno
, "Failed to save current directory.");
704 if (CVS_CHDIR (dir
) < 0)
705 error (1, errno
, "cannot chdir to %s", dir
);
708 * First, do the work necessary to update the "modules" database.
710 temp
= make_tempfile ();
711 switch (checkout_file (CVSROOTADM_MODULES
, temp
))
714 case 0: /* everything ok */
716 /* open it, to generate any duplicate errors */
717 if ((db
= dbm_open (temp
, O_RDONLY
, 0666)) != NULL
)
720 write_dbmfile (temp
);
721 rename_dbmfile (temp
);
723 rename_rcsfile (temp
, CVSROOTADM_MODULES
);
728 "'cvs checkout' is less functional without a %s file",
731 } /* switch on checkout_file() */
733 if (unlink_file (temp
) < 0
734 && !existence_error (errno
))
735 error (0, errno
, "cannot remove %s", temp
);
738 /* Checkout the files that need it in CVSROOT dir */
739 for (fileptr
= filelist
; fileptr
&& fileptr
->filename
; fileptr
++) {
740 if (fileptr
->errormsg
== NULL
)
742 temp
= make_tempfile ();
743 if (checkout_file (fileptr
->filename
, temp
) == 0)
744 rename_rcsfile (temp
, fileptr
->filename
);
746 * If there was some problem other than the file not existing,
747 * checkout_file already printed a real error message. If the
748 * file does not exist, it is harmless--it probably just means
749 * that the repository was created with an old version of CVS
750 * which didn't have so many files in CVSROOT.
753 if (unlink_file (temp
) < 0
754 && !existence_error (errno
))
755 error (0, errno
, "cannot remove %s", temp
);
759 fp
= CVS_FOPEN (CVSROOTADM_CHECKOUTLIST
, "r");
764 * [<whitespace>]<filename>[<whitespace><error message>]<end-of-line>
766 * comment lines begin with '#'
768 while (getline (&line
, &line_allocated
, fp
) >= 0)
770 /* skip lines starting with # */
774 if ((last
= strrchr (line
, '\n')) != NULL
)
775 *last
= '\0'; /* strip the newline */
777 /* Skip leading white space. */
779 *fname
&& isspace ((unsigned char) *fname
);
783 /* Find end of filename. */
784 for (cp
= fname
; *cp
&& !isspace ((unsigned char) *cp
); cp
++)
788 temp
= make_tempfile ();
789 if (checkout_file (fname
, temp
) == 0)
791 rename_rcsfile (temp
, fname
);
795 /* Skip leading white space before the error message. */
797 cp
< last
&& *cp
&& isspace ((unsigned char) *cp
);
800 if (cp
< last
&& *cp
)
801 error (0, 0, "%s", cp
);
803 if (unlink_file (temp
) < 0
804 && !existence_error (errno
))
805 error (0, errno
, "cannot remove %s", temp
);
811 error (0, errno
, "cannot read %s", CVSROOTADM_CHECKOUTLIST
);
813 error (0, errno
, "cannot close %s", CVSROOTADM_CHECKOUTLIST
);
817 /* Error from CVS_FOPEN. */
818 if (!existence_error (errno
))
819 error (0, errno
, "cannot open %s", CVSROOTADM_CHECKOUTLIST
);
822 if (restore_cwd (&cwd
))
823 error (1, errno
, "Failed to restore current directory, `%s'.",
833 * Yeah, I know, there are NFS race conditions here.
844 temp
= xmalloc (sizeof (BAKPREFIX
) + 40);
847 (void) sprintf (temp
, "%s%d", BAKPREFIX
, seed
++);
848 if ((fd
= CVS_OPEN (temp
, O_CREAT
|O_EXCL
|O_RDWR
, 0666)) != -1)
851 error (1, errno
, "cannot create temporary file %s", temp
);
854 error(1, errno
, "cannot close temporary file %s", temp
);
860 /* Get a file. If the file does not exist, return 1 silently. If
861 there is an error, print a message and return 1 (FIXME: probably
862 not a very clean convention). On success, return 0. */
864 checkout_file (char *file
, char *temp
)
873 rcs
= Xasprintf ("%s%s", file
, RCSEXT
);
880 rcsnode
= RCS_parsercsfile (rcs
);
883 /* Probably not necessary (?); RCS_parsercsfile already printed a
885 error (0, 0, "Failed to parse `%s'.", rcs
);
890 retcode
= RCS_checkout (rcsnode
, NULL
, NULL
, NULL
, NULL
, temp
, NULL
, NULL
);
893 /* Probably not necessary (?); RCS_checkout already printed a
895 error (0, 0, "failed to check out %s file",
898 freercsnode (&rcsnode
);
908 write_dbmfile( char *temp
)
910 char line
[DBLKSIZ
], value
[DBLKSIZ
];
915 int len
, cont
, err
= 0;
917 fp
= xfopen (temp
, "r");
918 if ((db
= dbm_open (temp
, O_RDWR
| O_CREAT
| O_TRUNC
, 0666)) == NULL
)
919 error (1, errno
, "cannot open dbm file %s for creation", temp
);
920 for (cont
= 0; fgets (line
, sizeof (line
), fp
) != NULL
;)
922 if ((cp
= strrchr (line
, '\n')) != NULL
)
923 *cp
= '\0'; /* strip the newline */
926 * Add the line to the value, at the end if this is a continuation
927 * line; otherwise at the beginning, but only after any trailing
928 * backslash is removed.
932 vp
+= strlen (value
);
935 * See if the line we read is a continuation line, and strip the
952 (void) strcpy (vp
, line
);
954 continue; /* comment line */
956 while (*vp
&& isspace ((unsigned char) *vp
))
959 continue; /* empty line */
962 * If this was not a continuation line, add the entry to the database
967 while (*vp
&& !isspace ((unsigned char) *vp
))
969 key
.dsize
= vp
- key
.dptr
;
970 *vp
++ = '\0'; /* NULL terminate the key */
971 while (*vp
&& isspace ((unsigned char) *vp
))
972 vp
++; /* skip whitespace to value */
975 error (0, 0, "warning: NULL value for key `%s'", key
.dptr
);
979 val
.dsize
= strlen (vp
);
980 if (dbm_store (db
, key
, val
, DBM_INSERT
) == 1)
982 error (0, 0, "duplicate key found for `%s'", key
.dptr
);
989 error (0, errno
, "cannot close %s", temp
);
992 /* I think that the size of the buffer needed here is
993 just determined by sizeof (CVSROOTADM_MODULES), the
994 filenames created by make_tempfile, and other things that won't
996 char dotdir
[50], dotpag
[50], dotdb
[50];
998 (void) sprintf (dotdir
, "%s.dir", temp
);
999 (void) sprintf (dotpag
, "%s.pag", temp
);
1000 (void) sprintf (dotdb
, "%s.db", temp
);
1001 if (unlink_file (dotdir
) < 0
1002 && !existence_error (errno
))
1003 error (0, errno
, "cannot remove %s", dotdir
);
1004 if (unlink_file (dotpag
) < 0
1005 && !existence_error (errno
))
1006 error (0, errno
, "cannot remove %s", dotpag
);
1007 if (unlink_file (dotdb
) < 0
1008 && !existence_error (errno
))
1009 error (0, errno
, "cannot remove %s", dotdb
);
1010 error (1, 0, "DBM creation failed; correct above errors");
1015 rename_dbmfile( char *temp
)
1017 /* I think that the size of the buffer needed here is
1018 just determined by sizeof (CVSROOTADM_MODULES), the
1019 filenames created by make_tempfile, and other things that won't
1021 char newdir
[50], newpag
[50], newdb
[50];
1022 char dotdir
[50], dotpag
[50], dotdb
[50];
1023 char bakdir
[50], bakpag
[50], bakdb
[50];
1025 int dir1_errno
= 0, pag1_errno
= 0, db1_errno
= 0;
1026 int dir2_errno
= 0, pag2_errno
= 0, db2_errno
= 0;
1027 int dir3_errno
= 0, pag3_errno
= 0, db3_errno
= 0;
1029 (void) sprintf (dotdir
, "%s.dir", CVSROOTADM_MODULES
);
1030 (void) sprintf (dotpag
, "%s.pag", CVSROOTADM_MODULES
);
1031 (void) sprintf (dotdb
, "%s.db", CVSROOTADM_MODULES
);
1032 (void) sprintf (bakdir
, "%s%s.dir", BAKPREFIX
, CVSROOTADM_MODULES
);
1033 (void) sprintf (bakpag
, "%s%s.pag", BAKPREFIX
, CVSROOTADM_MODULES
);
1034 (void) sprintf (bakdb
, "%s%s.db", BAKPREFIX
, CVSROOTADM_MODULES
);
1035 (void) sprintf (newdir
, "%s.dir", temp
);
1036 (void) sprintf (newpag
, "%s.pag", temp
);
1037 (void) sprintf (newdb
, "%s.db", temp
);
1039 (void) chmod (newdir
, 0666);
1040 (void) chmod (newpag
, 0666);
1041 (void) chmod (newdb
, 0666);
1043 /* don't mess with me */
1046 /* rm .#modules.dir .#modules.pag */
1047 if (unlink_file (bakdir
) < 0)
1049 if (unlink_file (bakpag
) < 0)
1051 if (unlink_file (bakdb
) < 0)
1054 /* mv modules.dir .#modules.dir */
1055 if (CVS_RENAME (dotdir
, bakdir
) < 0)
1057 /* mv modules.pag .#modules.pag */
1058 if (CVS_RENAME (dotpag
, bakpag
) < 0)
1060 /* mv modules.db .#modules.db */
1061 if (CVS_RENAME (dotdb
, bakdb
) < 0)
1064 /* mv "temp".dir modules.dir */
1065 if (CVS_RENAME (newdir
, dotdir
) < 0)
1067 /* mv "temp".pag modules.pag */
1068 if (CVS_RENAME (newpag
, dotpag
) < 0)
1070 /* mv "temp".db modules.db */
1071 if (CVS_RENAME (newdb
, dotdb
) < 0)
1074 /* OK -- make my day */
1077 /* I didn't want to call error() when we had signals blocked
1078 (unnecessary?), but do it now. */
1079 if (dir1_errno
&& !existence_error (dir1_errno
))
1080 error (0, dir1_errno
, "cannot remove %s", bakdir
);
1081 if (pag1_errno
&& !existence_error (pag1_errno
))
1082 error (0, pag1_errno
, "cannot remove %s", bakpag
);
1083 if (db1_errno
&& !existence_error (db1_errno
))
1084 error (0, db1_errno
, "cannot remove %s", bakdb
);
1086 if (dir2_errno
&& !existence_error (dir2_errno
))
1087 error (0, dir2_errno
, "cannot remove %s", bakdir
);
1088 if (pag2_errno
&& !existence_error (pag2_errno
))
1089 error (0, pag2_errno
, "cannot remove %s", bakpag
);
1090 if (db2_errno
&& !existence_error (db2_errno
))
1091 error (0, db2_errno
, "cannot remove %s", bakdb
);
1093 if (dir3_errno
&& !existence_error (dir3_errno
))
1094 error (0, dir3_errno
, "cannot remove %s", bakdir
);
1095 if (pag3_errno
&& !existence_error (pag3_errno
))
1096 error (0, pag3_errno
, "cannot remove %s", bakpag
);
1097 if (db3_errno
&& !existence_error (db3_errno
))
1098 error (0, db3_errno
, "cannot remove %s", bakdb
);
1101 #endif /* !MY_NDBM */
1104 rename_rcsfile (char *temp
, char *real
)
1107 struct stat statbuf
;
1110 /* Set "x" bits if set in original. */
1111 rcs
= Xasprintf ("%s%s", real
, RCSEXT
);
1112 statbuf
.st_mode
= 0; /* in case rcs file doesn't exist, but it should... */
1113 if (stat (rcs
, &statbuf
) < 0
1114 && !existence_error (errno
))
1115 error (0, errno
, "cannot stat %s", rcs
);
1118 if (chmod (temp
, 0444 | (statbuf
.st_mode
& 0111)) < 0)
1119 error (0, errno
, "warning: cannot chmod %s", temp
);
1120 bak
= Xasprintf ("%s%s", BAKPREFIX
, real
);
1123 if (unlink_file (bak
) < 0
1124 && !existence_error (errno
))
1125 error (0, errno
, "cannot remove %s", bak
);
1127 /* mv loginfo .#loginfo */
1128 if (CVS_RENAME (real
, bak
) < 0
1129 && !existence_error (errno
))
1130 error (0, errno
, "cannot rename %s to %s", real
, bak
);
1132 /* mv "temp" loginfo */
1133 if (CVS_RENAME (temp
, real
) < 0
1134 && !existence_error (errno
))
1135 error (0, errno
, "cannot rename %s to %s", temp
, real
);
1140 const char *const init_usage
[] = {
1142 "(Specify the --help global option for a list of other help options)\n",
1147 init (int argc
, char **argv
)
1149 /* Name of CVSROOT directory. */
1151 /* Name of this administrative file. */
1153 /* Name of ,v file for this administrative file. */
1158 const struct admin_file
*fileptr
;
1162 if (!admin_group_member ())
1163 error (1, 0, "usage is restricted to members of the group %s",
1164 config
->UserAdminGroup
);
1166 if (argc
== -1 || argc
> 1)
1169 #ifdef CLIENT_SUPPORT
1170 if (current_parsed_root
->isremote
)
1175 send_init_command ();
1176 return get_responses_and_close ();
1178 #endif /* CLIENT_SUPPORT */
1180 /* Note: we do *not* create parent directories as needed like the
1181 old cvsinit.sh script did. Few utilities do that, and a
1182 non-existent parent directory is as likely to be a typo as something
1183 which needs to be created. */
1184 mkdir_if_needed (current_parsed_root
->directory
);
1186 adm
= Xasprintf ("%s/%s", current_parsed_root
->directory
, CVSROOTADM
);
1187 mkdir_if_needed (adm
);
1189 /* This is needed because we pass "fileptr->filename" not "info"
1190 to add_rcs_file below. I think this would be easy to change,
1191 thus nuking the need for CVS_CHDIR here, but I haven't looked
1192 closely (e.g. see wrappers calls within add_rcs_file). */
1193 if ( CVS_CHDIR (adm
) < 0)
1194 error (1, errno
, "cannot change to directory %s", adm
);
1196 /* Make Emptydir so it's there if we need it */
1197 mkdir_if_needed (CVSNULLREPOS
);
1199 /* 80 is long enough for all the administrative file names, plus
1201 info
= xmalloc (strlen (adm
) + 80);
1202 info_v
= xmalloc (strlen (adm
) + 80);
1203 for (fileptr
= filelist
; fileptr
&& fileptr
->filename
; ++fileptr
)
1205 if (fileptr
->contents
== NULL
)
1209 strcat (info
, fileptr
->filename
);
1210 strcpy (info_v
, info
);
1211 strcat (info_v
, RCSEXT
);
1212 if (isfile (info_v
))
1213 /* We will check out this file in the mkmodules step.
1214 Nothing else is required. */
1223 const char * const *p
;
1225 fp
= xfopen (info
, "w");
1226 for (p
= fileptr
->contents
; *p
!= NULL
; ++p
)
1227 if (fputs (*p
, fp
) < 0)
1228 error (1, errno
, "cannot write %s", info
);
1229 if (fclose (fp
) < 0)
1230 error (1, errno
, "cannot close %s", info
);
1232 /* The message used to say " of " and fileptr->filename after
1233 "initial checkin" but I fail to see the point as we know what
1234 file it is from the name. */
1235 retcode
= add_rcs_file ("initial checkin", info_v
,
1236 fileptr
->filename
, "1.1", NULL
,
1238 /* No vendor branch. */
1239 NULL
, NULL
, 0, NULL
,
1243 /* add_rcs_file already printed an error message. */
1248 /* Turn on history logging by default. The user can remove the file
1252 strcat (info
, CVSROOTADM_HISTORY
);
1257 fp
= xfopen (info
, "w");
1258 if (fclose (fp
) < 0)
1259 error (1, errno
, "cannot close %s", info
);
1261 /* Make the new history file world-writeable, since every CVS
1262 user will need to be able to write to it. We use chmod()
1263 because xchmod() is too shy. */
1267 /* Make an empty val-tags file to prevent problems creating it later. */
1270 strcat (info
, CVSROOTADM_VALTAGS
);
1275 fp
= xfopen (info
, "w");
1276 if (fclose (fp
) < 0)
1277 error (1, errno
, "cannot close %s", info
);
1279 /* Make the new val-tags file world-writeable, since every CVS
1280 user will need to be able to write to it. We use chmod()
1281 because xchmod() is too shy. */