4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 #include <sys/types.h>
28 #include <sys/types.h>
35 #include "passwdutil.h"
38 __set_authtoken_attr(char *name
, char *oldpw
, pwu_repository_t
*rep
,
39 attrlist
*items
, int *updated_reps
)
44 void *buf
; /* workspace for repository specific funcs */
45 int err
= PWU_NOT_FOUND
;
46 int rep_success
= REP_NOREP
; /* first successfull update */
47 int updated
= REP_NOREP
; /* (bitmask) all updates */
49 /* Can't set name uid or flag */
50 for (p
= items
; p
!= NULL
; p
= p
->next
) {
59 repositories
= get_ns(rep
, PWU_WRITE
);
61 if (repositories
== 0)
62 return (PWU_SYSTEM_ERROR
);
65 * updating requires that either
66 * - PAM_REPOSITORY is set: we know what to update
67 * - PAM_REPOSITORY is not set, but we recognize the nsswitch.conf
70 if (repositories
== REP_ERANGE
|| repositories
== REP_NSS
)
71 return (PWU_REPOSITORY_ERROR
);
74 * Loop over selected repositories to update
75 * We should update the remote repositories first, FILES last.
77 for (i
= REP_LAST
; i
; i
>>= 1) {
78 if (repositories
& i
) {
81 if (rops
[i
]->lock
&& (err
= rops
[i
]->lock())) {
85 if (rops
[i
]->getpwnam
) {
86 err
= rops
[i
]->getpwnam(name
, items
, rep
, &buf
);
89 if ((err
== PWU_SUCCESS
) && rops
[i
]->update
)
90 err
= rops
[i
]->update(items
, rep
, buf
);
92 if ((err
== PWU_SUCCESS
) && rops
[i
]->putpwnam
)
93 err
= rops
[i
]->putpwnam(name
, oldpw
, rep
, buf
);
96 (void) rops
[i
]->unlock();
102 if (err
== PWU_SUCCESS
) {
103 rep_success
= i
; /* this rep succeeded */
105 } else if (err
!= PWU_SUCCESS
&& err
!= PWU_NOT_FOUND
) {
114 *updated_reps
= (updated
!= REP_NOREP
) ? updated
: i
;
117 * err contains either
118 * PWU_SUCCESS : everyting went OK
119 * PWU_NOT_FOUND : none of the repositories contained the user
120 * error-code : the specific error that occurred
122 if (rep_success
!= REP_NOREP
) {
123 return (PWU_SUCCESS
);