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 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
28 #include <sys/types.h>
38 #include <nss_dbdefs.h>
43 edit_project(char *login
, char *new_login
, projid_t projids
[], int overwrite
)
46 char t_name
[] = "/etc/projtmp.XXXXXX";
47 FILE *e_fptr
, *t_fptr
;
48 struct project
*p_ptr
;
49 struct project p_work
;
50 char workbuf
[NSS_LINELEN_PROJECT
];
54 char p_string
[NSS_LINELEN_PROJECT
];
59 if ((e_fptr
= fopen(PROJF_PATH
, "r")) == NULL
) {
63 if (fstat(fileno(e_fptr
), &sbuf
) != 0)
66 if ((fd
= mkstemp(t_name
)) < 0) {
70 if ((t_fptr
= fdopen(fd
, "w+")) == NULL
) {
72 (void) unlink(t_name
);
77 * Get ownership and permissions correct
80 if (fchmod(fd
, sbuf
.st_mode
) != 0 ||
81 fchown(fd
, sbuf
.st_uid
, sbuf
.st_gid
) != 0) {
82 (void) fclose(t_fptr
);
83 (void) unlink(t_name
);
87 p_curr
= ftell(e_fptr
);
89 /* Make TMP file look like we want project file to look */
91 while (fgets(p_string
, NSS_LINELEN_PROJECT
- 1, e_fptr
)) {
92 /* While there is another group string */
94 p_length
= strlen(p_string
);
95 (void) fseek(e_fptr
, p_curr
, SEEK_SET
);
96 p_ptr
= fgetprojent(e_fptr
, &p_work
, &workbuf
,
98 p_curr
= ftell(e_fptr
);
102 * tried to parse a proj string over
103 * NSS_LINELEN_PROJECT chars
105 errmsg(M_PROJ_ENTRY_OVF
, NSS_LINELEN_PROJECT
);
106 modified
= 0; /* bad project file: cannot rebuild */
110 /* first delete the login from the project, if it's there */
111 if (overwrite
|| !projids
) {
112 if (p_ptr
->pj_users
!= NULL
) {
113 for (memptr
= p_ptr
->pj_users
; *memptr
;
115 if (strcmp(*memptr
, login
) == 0) {
116 /* Delete this one */
117 char **from
= memptr
+ 1;
118 p_length
-= (strlen(*memptr
)+1);
130 /* now check to see if project is one to add to */
132 for (i
= 0; projids
[i
] != -1; i
++) {
133 if (p_ptr
->pj_projid
== projids
[i
]) {
136 for (memptr
= p_ptr
->pj_users
; *memptr
;
138 if (strncmp(*memptr
, new_login
?
140 strlen(*memptr
)) == 0)
143 p_length
+= strlen(new_login
?
144 new_login
: login
) + 1;
147 NSS_LINELEN_PROJECT
- 1) {
148 errmsg(M_PROJ_ENTRY_OVF
,
149 NSS_LINELEN_PROJECT
);
153 *memptr
++ = new_login
?
162 putprojent(p_ptr
, t_fptr
);
165 (void) fclose(e_fptr
);
166 (void) fclose(t_fptr
);
168 /* Now, update project file, if it was modified */
169 if (modified
&& rename(t_name
, PROJF_PATH
) < 0) {
170 (void) unlink(t_name
);
174 (void) unlink(t_name
);