5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 *
25 * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
26 */
27
28 #include <syslog.h>
29 #include <stdlib.h>
30 #include <unistd.h>
31 #include <limits.h>
32 #include <strings.h>
33 #include <synch.h>
34 #include <errno.h>
35 #include <sys/types.h>
36 #include <sys/stat.h>
37 #include <sys/avl.h>
38 #include <fcntl.h>
39 #include <thread.h>
40 #include <pwd.h>
41 #include <dlfcn.h>
42 #include <link.h>
43 #include <assert.h>
44 #include <smbsrv/libsmb.h>
45
261 int err;
262
263 if (smb_pwd_ops.pwop_getpwnam != NULL)
264 return (smb_pwd_ops.pwop_getpwnam(name, smbpw));
265
266 err = smb_pwd_lock();
267 if (err != SMB_PWE_SUCCESS) {
268 syslog(LOG_WARNING, "smb_pwdutil: lock failed, err=%d", err);
269 return (NULL);
270 }
271
272 if ((fp = fopen(SMB_PASSWD, "rF")) == NULL) {
273 syslog(LOG_WARNING, "smb_pwdutil: open failed, %m");
274 (void) smb_pwd_unlock();
275 return (NULL);
276 }
277
278 pwbuf.pw_pwd = smbpw;
279
280 while (smb_pwd_fgetent(fp, &pwbuf, SMB_PWD_GETF_ALL) != NULL) {
281 if (strcmp(name, smbpw->pw_name) == 0) {
282 found = B_TRUE;
283 break;
284 }
285 }
286
287 (void) fclose(fp);
288 (void) smb_pwd_unlock();
289
290 if (!found) {
291 bzero(smbpw, sizeof (smb_passwd_t));
292 return (NULL);
293 }
294
295 return (smbpw);
296 }
297
298 /*
299 * smb_pwd_getpwuid
300 *
301 * Returns a smb password structure for the given UID
507 err = SMB_PWE_OPEN_FAILED;
508 (void) fclose(dst);
509 (void) unlink(SMB_PASSTEMP);
510 goto passwd_exit;
511 }
512
513 if (smb_config_getnum(SMB_CI_LM_LEVEL, &lm_level) != SMBD_SMF_OK)
514 lm_level = 4;
515
516 if (lm_level >= 4)
517 control |= SMB_PWC_NOLM;
518
519 pwbuf.pw_pwd = &smbpw;
520
521 /*
522 * copy old password entries to temporary file while replacing
523 * the entry that matches "name"
524 */
525 while (smb_pwd_fgetent(src, &pwbuf, SMB_PWD_GETF_ALL) != NULL) {
526 if (strcmp(smbpw.pw_name, name) == 0) {
527 err = smb_pwd_chgpwent(&smbpw, password, control);
528 if (err == SMB_PWE_USER_DISABLE)
529 user_disable = B_TRUE;
530 err = smb_pwd_fputent(dst, &pwbuf);
531 newent = B_FALSE;
532 } else {
533 err = smb_pwd_fputent(dst, &pwbuf);
534 }
535
536 if (err != SMB_PWE_SUCCESS) {
537 (void) fclose(src);
538 (void) fclose(dst);
539 goto passwd_exit;
540 }
541 }
542
543 if (newent) {
544 if (getpwnam_r(name, &uxpw, uxbuf, sizeof (uxbuf))) {
545 bzero(&smbpw, sizeof (smb_passwd_t));
546 (void) strlcpy(smbpw.pw_name, uxpw.pw_name,
|
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 *
25 * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
26 */
27
28 #include <syslog.h>
29 #include <stdlib.h>
30 #include <unistd.h>
31 #include <limits.h>
32 #include <strings.h>
33 #include <synch.h>
34 #include <errno.h>
35 #include <sys/types.h>
36 #include <sys/stat.h>
37 #include <sys/avl.h>
38 #include <fcntl.h>
39 #include <thread.h>
40 #include <pwd.h>
41 #include <dlfcn.h>
42 #include <link.h>
43 #include <assert.h>
44 #include <smbsrv/libsmb.h>
45
261 int err;
262
263 if (smb_pwd_ops.pwop_getpwnam != NULL)
264 return (smb_pwd_ops.pwop_getpwnam(name, smbpw));
265
266 err = smb_pwd_lock();
267 if (err != SMB_PWE_SUCCESS) {
268 syslog(LOG_WARNING, "smb_pwdutil: lock failed, err=%d", err);
269 return (NULL);
270 }
271
272 if ((fp = fopen(SMB_PASSWD, "rF")) == NULL) {
273 syslog(LOG_WARNING, "smb_pwdutil: open failed, %m");
274 (void) smb_pwd_unlock();
275 return (NULL);
276 }
277
278 pwbuf.pw_pwd = smbpw;
279
280 while (smb_pwd_fgetent(fp, &pwbuf, SMB_PWD_GETF_ALL) != NULL) {
281 if (strcasecmp(name, smbpw->pw_name) == 0) {
282 found = B_TRUE;
283 break;
284 }
285 }
286
287 (void) fclose(fp);
288 (void) smb_pwd_unlock();
289
290 if (!found) {
291 bzero(smbpw, sizeof (smb_passwd_t));
292 return (NULL);
293 }
294
295 return (smbpw);
296 }
297
298 /*
299 * smb_pwd_getpwuid
300 *
301 * Returns a smb password structure for the given UID
507 err = SMB_PWE_OPEN_FAILED;
508 (void) fclose(dst);
509 (void) unlink(SMB_PASSTEMP);
510 goto passwd_exit;
511 }
512
513 if (smb_config_getnum(SMB_CI_LM_LEVEL, &lm_level) != SMBD_SMF_OK)
514 lm_level = 4;
515
516 if (lm_level >= 4)
517 control |= SMB_PWC_NOLM;
518
519 pwbuf.pw_pwd = &smbpw;
520
521 /*
522 * copy old password entries to temporary file while replacing
523 * the entry that matches "name"
524 */
525 while (smb_pwd_fgetent(src, &pwbuf, SMB_PWD_GETF_ALL) != NULL) {
526 if (strcmp(smbpw.pw_name, name) == 0) {
527 if ((control & SMB_PWC_DELETE) != 0) {
528 /* exclude the entry from the new passwd file */
529 newent = B_FALSE;
530 err = SMB_PWE_SUCCESS;
531 continue;
532 }
533 err = smb_pwd_chgpwent(&smbpw, password, control);
534 if (err == SMB_PWE_USER_DISABLE)
535 user_disable = B_TRUE;
536 err = smb_pwd_fputent(dst, &pwbuf);
537 newent = B_FALSE;
538 } else {
539 err = smb_pwd_fputent(dst, &pwbuf);
540 }
541
542 if (err != SMB_PWE_SUCCESS) {
543 (void) fclose(src);
544 (void) fclose(dst);
545 goto passwd_exit;
546 }
547 }
548
549 if (newent) {
550 if (getpwnam_r(name, &uxpw, uxbuf, sizeof (uxbuf))) {
551 bzero(&smbpw, sizeof (smb_passwd_t));
552 (void) strlcpy(smbpw.pw_name, uxpw.pw_name,
|