4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1999 by Sun Microsystems, Inc.
24 * All rights reserved.
26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
30 #ident "%Z%%M% %I% %E% SMI" /* from SVR4 bnu:cpmv.c 2.13 */
35 * copy f1 to f2 locally
36 * f1 -> source file name
37 * f2 -> destination file name
47 register int fd1
, fd2
;
50 char *temp_p
, temp
[MAXFULLNAME
];
52 if ((fd1
= open(f1
, O_RDONLY
)) == -1)
56 (void) strcat(f2
, "/");
57 (void) strcat(f2
, BASENAME(f1
, '/'));
59 DEBUG(4, "file name is %s\n", f2
);
61 (void) strcpy(temp
, f2
);
62 if ((temp_p
= strrchr(temp
, '/')) == NULL
)
66 (void) strcpy(temp_p
, ".TM.XXXXXX");
68 DEBUG(4, "temp name is %s\n", temp_p
);
70 if ((fd2
= mkstemp(temp_p
)) == -1) {
71 /* open of temp may fail if called from uidxcp() */
72 /* in this case, try f2 since it is pre-created */
74 if ((fd2
= open(temp_p
, O_CREAT
| O_TRUNC
| O_WRONLY
,
75 PUB_FILEMODE
)) == -1) {
76 DEBUG(5, "open of file returned errno %d\n", errno
);
80 DEBUG(4, "using file name directly.%s\n", "");
82 (void) chmod(temp_p
, PUB_FILEMODE
);
84 /* copy, looking for read or write failures */
85 while ((nr
= read(fd1
, buf
, sizeof (buf
))) > 0 &&
86 (nw
= write(fd2
, buf
, nr
)) == nr
)
92 if (nr
!= 0 || nw
== -1) {
93 (void) unlink(temp_p
);
97 if (rename(temp_p
, f2
) != 0) {
98 DEBUG(5, "rename failed: errno %d\n", errno
);
99 (void) unlink(temp_p
);
108 * move f1 to f2 locally
116 register char *f1
, *f2
;
118 register int do_unlink
, ret
;
121 if (stat(f2
, &sbuf
) == 0)
122 do_unlink
= ((sbuf
.st_mode
& S_IFMT
) == S_IFREG
);
127 (void) unlink(f2
); /* i'm convinced this is the right */
129 if ((ret
= link(f1
, f2
)) < 0) {
140 * toCorrupt - move file to CORRUPTDIR
148 char corrupt
[MAXFULLNAME
];
150 (void) sprintf(corrupt
, "%s/%s", CORRUPTDIR
, BASENAME(file
, '/'));
151 (void) link(file
, corrupt
);
152 ASSERT(unlink(file
) == 0, Ct_UNLINK
, file
, errno
);
157 * f1 -> source FILE pointer
158 * f2 -> destination FILE pointer
163 * to avoid confusing mail, turn lines with just "." into "..".
167 register FILE *fp1
, *fp2
;
171 while (fgets(buf
, sizeof (buf
), fp1
) != NULL
) {
172 if (buf
[0] == '.' && buf
[1] == '\n')
177 return (ferror(fp1
) || ferror(fp2
) ? FAIL
: SUCCESS
);
182 * copy f1 to f2 locally under uid of uid argument
183 * f1 -> source file name
184 * f2 -> destination file name
185 * Uid and Euid are global
190 * for V7 systems, flip-flop between real and effective uid is
191 * not allowed, so fork must be done. This code will not
192 * work correctly when realuid is root on System 5 because of
201 char full
[MAXFULLNAME
];
203 (void) strcpy(full
, f2
);
205 (void) strcat(full
, "/");
206 (void) strcat(full
, BASENAME(f1
, '/'));
209 /* create full owned by uucp */
210 (void) close(creat(full
, PUB_FILEMODE
));
211 (void) chmod(full
, PUB_FILEMODE
);
213 /* do file copy as read uid */
216 status
= xcp(f1
, full
);
224 _exit(xcp(f1
, full
));
232 * put file in public place
233 * if successful, filename is modified
239 putinpub(file
, tmp
, user
)
240 char *file
, *user
, *tmp
;
243 char fullname
[MAXFULLNAME
];
245 (void) sprintf(fullname
, "%s/%s/", Pubdir
, user
);
246 if (mkdirs(fullname
, PUBMASK
) != 0) {
247 /* cannot make directories */
250 (void) strcat(fullname
, BASENAME(file
, '/'));
251 status
= xmv(tmp
, fullname
);
253 (void) strcpy(file
, fullname
);
254 (void) chmod(fullname
, PUB_FILEMODE
);