1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
|
/* $OpenBSD: admin.c,v 1.60 2008/06/11 01:43:35 joris Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* Copyright (c) 2005 Joris Vink <joris@openbsd.org>
* Copyright (c) 2006, 2007 Xavier Santolaria <xsa@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/param.h>
#include <sys/dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <libgen.h>
#include <string.h>
#include <unistd.h>
#include "cvs.h"
#include "remote.h"
#define ADM_EFLAG 0x01
void cvs_admin_local(struct cvs_file *);
struct cvs_cmd cvs_cmd_admin = {
CVS_OP_ADMIN, CVS_USE_WDIR | CVS_LOCK_REPO, "admin",
{ "adm", "rcs" },
"Administrative front-end for RCS",
"[-ILqU] [-A oldfile] [-a users] [-b branch]\n"
"[-c string] [-e [users]] [-k mode] [-l [rev]] [-m rev:msg]\n"
"[-N tag[:rev]] [-n tag[:rev]] [-o rev] [-s state[:rev]]"
"[-t file | str]\n"
"[-u [rev]] file ...",
"A:a:b::c:e::Ik:l::Lm:N:n:o:qs:t:Uu::",
NULL,
cvs_admin
};
static int runflags = 0;
static int lkmode = RCS_LOCK_INVAL;
static char *alist, *comment, *elist, *logmsg, *logstr, *koptstr;
static char *oldfilename, *orange, *state, *statestr;
static RCSNUM *logrev;
int
cvs_admin(int argc, char **argv)
{
int ch;
int flags;
struct cvs_recursion cr;
flags = CR_RECURSE_DIRS;
alist = comment = elist = logmsg = logstr = NULL;
oldfilename = orange = state = statestr = NULL;
while ((ch = getopt(argc, argv, cvs_cmd_admin.cmd_opts)) != -1) {
switch (ch) {
case 'A':
oldfilename = optarg;
break;
case 'a':
alist = optarg;
break;
case 'b':
break;
case 'c':
comment = optarg;
break;
case 'e':
elist = optarg;
runflags |= ADM_EFLAG;
break;
case 'I':
break;
case 'k':
koptstr = optarg;
kflag = rcs_kflag_get(koptstr);
if (RCS_KWEXP_INVAL(kflag)) {
cvs_log(LP_ERR,
"invalid RCS keyword expansion mode");
fatal("%s", cvs_cmd_admin.cmd_synopsis);
}
break;
case 'L':
if (lkmode == RCS_LOCK_LOOSE) {
cvs_log(LP_ERR, "-L and -U are incompatible");
fatal("%s", cvs_cmd_admin.cmd_synopsis);
}
lkmode = RCS_LOCK_STRICT;
break;
case 'l':
break;
case 'm':
logstr = optarg;
break;
case 'N':
break;
case 'n':
break;
case 'o':
orange = optarg;
break;
case 'q':
verbosity = 0;
break;
case 's':
statestr = optarg;
break;
case 't':
break;
case 'U':
if (lkmode == RCS_LOCK_STRICT) {
cvs_log(LP_ERR, "-U and -L are incompatible");
fatal("%s", cvs_cmd_admin.cmd_synopsis);
}
lkmode = RCS_LOCK_LOOSE;
break;
case 'u':
break;
default:
fatal("%s", cvs_cmd_admin.cmd_synopsis);
}
}
argc -= optind;
argv += optind;
if (argc == 0)
fatal("%s", cvs_cmd_admin.cmd_synopsis);
cr.enterdir = NULL;
cr.leavedir = NULL;
if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
cvs_client_connect_to_server();
cr.fileproc = cvs_client_sendfile;
if (oldfilename != NULL)
cvs_client_send_request("Argument -A%s", oldfilename);
if (alist != NULL)
cvs_client_send_request("Argument -a%s", alist);
if (comment != NULL)
cvs_client_send_request("Argument -c%s", comment);
if (runflags & ADM_EFLAG)
cvs_client_send_request("Argument -e%s",
(elist != NULL) ? elist : "");
if (koptstr != NULL)
cvs_client_send_request("Argument -k%s", koptstr);
if (lkmode == RCS_LOCK_STRICT)
cvs_client_send_request("Argument -L");
else if (lkmode == RCS_LOCK_LOOSE)
cvs_client_send_request("Argument -U");
if (logstr != NULL)
cvs_client_send_logmsg(logstr);
if (orange != NULL)
cvs_client_send_request("Argument -o%s", orange);
if (statestr != NULL)
cvs_client_send_request("Argument -s%s", statestr);
if (verbosity == 0)
cvs_client_send_request("Argument -q");
} else {
flags |= CR_REPO;
cr.fileproc = cvs_admin_local;
}
cr.flags = flags;
cvs_file_run(argc, argv, &cr);
if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
cvs_client_send_files(argv, argc);
cvs_client_senddir(".");
cvs_client_send_request("admin");
cvs_client_get_responses();
}
return (0);
}
void
cvs_admin_local(struct cvs_file *cf)
{
int i;
cvs_log(LP_TRACE, "cvs_admin_local(%s)", cf->file_path);
cvs_file_classify(cf, cvs_directory_tag);
if (cf->file_type == CVS_DIR) {
if (verbosity > 1)
cvs_log(LP_NOTICE, "Administrating %s", cf->file_name);
return;
}
if (cf->file_status == FILE_UNKNOWN)
return;
else if (cf->file_status == FILE_ADDED) {
cvs_log(LP_ERR, "cannot admin newly added file `%s'",
cf->file_name);
return;
}
if (cf->file_rcs == NULL) {
cvs_log(LP_ERR, "lost RCS file for `%s'", cf->file_path);
return;
}
if (verbosity > 0)
cvs_printf("RCS file: %s\n", cf->file_rcs->rf_path);
if (oldfilename != NULL) {
struct cvs_file *ocf;
struct rcs_access *acp;
int ofd;
char *d, *f, fpath[MAXPATHLEN], repo[MAXPATHLEN];
if ((f = basename(oldfilename)) == NULL)
fatal("cvs_admin_local: basename failed");
if ((d = dirname(oldfilename)) == NULL)
fatal("cvs_admin_local: dirname failed");
cvs_get_repository_path(d, repo, MAXPATHLEN);
(void)xsnprintf(fpath, MAXPATHLEN, "%s/%s", repo, f);
if (strlcat(fpath, RCS_FILE_EXT, MAXPATHLEN) >= MAXPATHLEN)
fatal("cvs_admin_local: truncation");
if ((ofd = open(fpath, O_RDONLY)) == -1)
fatal("cvs_admin_local: open: `%s': %s", fpath,
strerror(errno));
/* XXX: S_ISREG() check instead of blindly using CVS_FILE? */
ocf = cvs_file_get_cf(d, f, ofd, CVS_FILE, 0);
ocf->file_rcs = rcs_open(fpath, ofd, RCS_READ, 0444);
if (ocf->file_rcs == NULL)
fatal("cvs_admin_local: rcs_open failed");
TAILQ_FOREACH(acp, &(ocf->file_rcs->rf_access), ra_list)
rcs_access_add(cf->file_rcs, acp->ra_name);
cvs_file_free(ocf);
}
if (alist != NULL) {
struct cvs_argvector *aargv;
aargv = cvs_strsplit(alist, ",");
for (i = 0; aargv->argv[i] != NULL; i++)
rcs_access_add(cf->file_rcs, aargv->argv[i]);
cvs_argv_destroy(aargv);
}
if (comment != NULL)
rcs_comment_set(cf->file_rcs, comment);
if (elist != NULL) {
struct cvs_argvector *eargv;
eargv = cvs_strsplit(elist, ",");
for (i = 0; eargv->argv[i] != NULL; i++)
rcs_access_remove(cf->file_rcs, eargv->argv[i]);
cvs_argv_destroy(eargv);
} else if (runflags & ADM_EFLAG) {
struct rcs_access *rap;
while (!TAILQ_EMPTY(&(cf->file_rcs->rf_access))) {
rap = TAILQ_FIRST(&(cf->file_rcs->rf_access));
TAILQ_REMOVE(&(cf->file_rcs->rf_access), rap, ra_list);
xfree(rap->ra_name);
xfree(rap);
}
/* no synced anymore */
cf->file_rcs->rf_flags &= ~RCS_SYNCED;
}
/* Default `-kv' is accepted here. */
if (kflag) {
if (cf->file_rcs->rf_expand == NULL ||
strcmp(cf->file_rcs->rf_expand, koptstr) != 0)
rcs_kwexp_set(cf->file_rcs, kflag);
}
if (logstr != NULL) {
if ((logmsg = strchr(logstr, ':')) == NULL) {
cvs_log(LP_ERR, "missing log message");
return;
}
*logmsg++ = '\0';
if ((logrev = rcsnum_parse(logstr)) == NULL) {
cvs_log(LP_ERR, "`%s' bad revision number", logstr);
return;
}
if (rcs_rev_setlog(cf->file_rcs, logrev, logmsg) < 0) {
cvs_log(LP_ERR, "failed to set logmsg for `%s' to `%s'",
logstr, logmsg);
rcsnum_free(logrev);
return;
}
rcsnum_free(logrev);
}
if (orange != NULL) {
struct rcs_delta *rdp, *nrdp;
char b[CVS_REV_BUFSZ];
cvs_revision_select(cf->file_rcs, orange);
for (rdp = TAILQ_FIRST(&(cf->file_rcs->rf_delta));
rdp != NULL; rdp = nrdp) {
nrdp = TAILQ_NEXT(rdp, rd_list);
/*
* Delete selected revisions.
*/
if (rdp->rd_flags & RCS_RD_SELECT) {
rcsnum_tostr(rdp->rd_num, b, sizeof(b));
if (verbosity > 0)
cvs_printf("deleting revision %s\n", b);
(void)rcs_rev_remove(cf->file_rcs, rdp->rd_num);
}
}
}
if (statestr != NULL) {
struct cvs_argvector *sargv;
sargv = cvs_strsplit(statestr, ":");
if (sargv->argv[1] != NULL) {
state = xstrdup(sargv->argv[0]);
if ((logrev = rcsnum_parse(sargv->argv[1])) == NULL) {
cvs_log(LP_ERR, "`%s' bad revision number", statestr);
cvs_argv_destroy(sargv);
xfree(state);
return;
}
} else {
state = xstrdup(statestr);
logrev = rcsnum_alloc();
rcsnum_cpy(cf->file_rcs->rf_head, logrev, 0);
}
if (rcs_state_check(state) < 0) {
cvs_log(LP_ERR, "invalid state `%s'", state);
cvs_argv_destroy(sargv);
rcsnum_free(logrev);
xfree(state);
return;
}
(void)rcs_state_set(cf->file_rcs, logrev, state);
cvs_argv_destroy(sargv);
rcsnum_free(logrev);
xfree(state);
}
if (lkmode != RCS_LOCK_INVAL)
(void)rcs_lock_setmode(cf->file_rcs, lkmode);
rcs_write(cf->file_rcs);
if (verbosity > 0)
cvs_printf("done\n");
}
|