Merge commit '42a3762d0138d6dd0c0f96964be98d0b21ab6bef'
[unleashed.git] / usr / src / cmd / smbsrv / smbd / smbd_logon.c
blob51f0e8f3e065efbb5d0b4978ede10b192b2e1a03
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
22 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
26 #include <sys/types.h>
27 #include <errno.h>
28 #include <synch.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <unistd.h>
32 #include <string.h>
33 #include <strings.h>
34 #include <syslog.h>
35 #include <fcntl.h>
36 #include <pwd.h>
37 #include <nss_dbdefs.h>
38 #include <sys/idmap.h>
39 #include "smbd.h"
42 * Invoked at user logon due to SmbSessionSetupX.
44 * On error, returns NULL, and status in user_info->lg_status
46 smb_token_t *
47 smbd_user_auth_logon(smb_logon_t *user_info)
49 smb_token_t *token = NULL;
50 smb_logon_t tmp_user;
51 char *p;
52 char *buf = NULL;
54 if (user_info->lg_username == NULL ||
55 user_info->lg_domain == NULL ||
56 user_info->lg_workstation == NULL) {
57 user_info->lg_status = NT_STATUS_INVALID_PARAMETER;
58 return (NULL);
62 * Avoid modifying the caller-provided struct because it
63 * may or may not point to allocated strings etc.
64 * Copy to tmp_user, auth, then copy the (out) lg_status
65 * member back to the caller-provided struct.
67 tmp_user = *user_info;
68 if (tmp_user.lg_username[0] == '\0') {
69 tmp_user.lg_flags |= SMB_ATF_ANON;
70 tmp_user.lg_e_username = "anonymous";
71 } else {
72 tmp_user.lg_e_username = tmp_user.lg_username;
75 /* Handle user@domain format. */
76 if (tmp_user.lg_domain[0] == '\0' &&
77 (p = strchr(tmp_user.lg_e_username, '@')) != NULL) {
78 buf = strdup(tmp_user.lg_e_username);
79 if (buf == NULL)
80 goto errout;
81 p = buf + (p - tmp_user.lg_e_username);
82 *p = '\0';
83 tmp_user.lg_e_domain = p + 1;
84 tmp_user.lg_e_username = buf;
85 } else {
86 tmp_user.lg_e_domain = tmp_user.lg_domain;
89 token = smb_logon(&tmp_user);
90 user_info->lg_status = tmp_user.lg_status;
92 return (token);
94 errout:
95 free(buf);
96 smb_token_destroy(token);
97 return NULL;