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 1995 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI"
34 If mail file does not exist create it
37 void createmf(uid
, file
)
43 void (*istat
)(), (*qstat
)(), (*hstat
)();
45 if (access(file
, A_EXIST
) == CERROR
) {
46 istat
= signal(SIGINT
, SIG_IGN
);
47 qstat
= signal(SIGQUIT
, SIG_IGN
);
48 hstat
= signal(SIGHUP
, SIG_IGN
);
50 if ((fd
= creat(file
, MFMODE
)) == -1)
55 (void) signal(SIGINT
, istat
);
56 (void) signal(SIGQUIT
, qstat
);
57 (void) signal(SIGHUP
, hstat
);
73 if (lstat(path
, &sb
)) {
74 /* file/symlink does not exist, so create one */
76 O_APPEND
|O_CREAT
|O_EXCL
|O_WRONLY
, S_IRUSR
|S_IWUSR
|S_IRGRP
|S_IWGRP
);
78 /* if someone create a symlink/file just ahead */
79 /* of us, the create will failed with EEXIST */
80 /* This is what we want, because we do not */
81 /* want someone to re-direct our "create" */
82 /* request to a another location. */
88 /* file/symlink exist, make sure it is not linked */
89 } else if (sb
.st_nlink
!= 1 || S_ISLNK(sb
.st_mode
)) {
91 "%s: security violation, '%s' should not be linked to other file\n", program
, path
);
95 /* if we get here, there is a pre-existing file, */
96 /* and it is not a symlink... */
97 /* open it, and make sure it is the same file */
98 /* we lstat() before... */
99 /* this is to guard against someone deleting the */
100 /* old file and creat a new symlink in its place */
101 /* We are not createing a new file here, but we */
102 /* do not want append to the worng file either */
103 mbfd
= open(path
, O_APPEND
|O_WRONLY
, 0);
105 (fstat(mbfd
, &fsb
) || fsb
.st_nlink
!= 1 ||
106 S_ISLNK(fsb
.st_mode
) || sb
.st_dev
!= fsb
.st_dev
||
107 sb
.st_ino
!= fsb
.st_ino
)) {
108 /* file changed after open */
109 fprintf(stderr
, "%s: security violation, '%s' inode changed after open\n", program
, path
);