author | natalie li - Sun Microsystems - Irvine United States <Natalie.Li@Sun.COM> |
Tue, 28 Oct 2008 03:34:04 -0700 | |
changeset 7961 | 4b5e3051f38b |
parent 5772 | 237ac22142fe |
child 8334 | 5f1c6a3b0fad |
permissions | -rw-r--r-- |
5331 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
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. |
|
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 |
/* |
|
5772
237ac22142fe
6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents:
5521
diff
changeset
|
22 |
* Copyright 2008 Sun Microsystems, Inc. All rights reserved. |
5331 | 23 |
* Use is subject to license terms. |
24 |
*/ |
|
25 |
||
26 |
/* |
|
27 |
* The IPC connection information is encapsulated within SMB Redirector. |
|
28 |
* Utility functions are defined here to allow other modules to get and |
|
29 |
* set the ipc configuration, as well as, to rollback or commit the |
|
30 |
* changes to the original authentication information. |
|
31 |
*/ |
|
32 |
||
33 |
#include <string.h> |
|
34 |
#include <strings.h> |
|
35 |
#include <synch.h> |
|
36 |
||
37 |
#include <smbsrv/libsmbrdr.h> |
|
38 |
#include <smbsrv/mlsvc.h> |
|
39 |
#include <smbsrv/smbinfo.h> |
|
40 |
#include <smbrdr.h> |
|
41 |
#include <smbrdr_ipc_util.h> |
|
42 |
||
43 |
#define SMBRDR_IPC_GETDOMAIN_TIMEOUT 10000 |
|
44 |
||
45 |
static rwlock_t smbrdr_ipc_lock; |
|
46 |
static smbrdr_ipc_t ipc_info; |
|
47 |
static smbrdr_ipc_t orig_ipc_info; |
|
48 |
||
5521
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
49 |
static int |
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
50 |
smbrdr_get_machine_pwd_hash(unsigned char *hash) |
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
51 |
{ |
7961
4b5e3051f38b
6751647 TRANS2_FIND_NEXT continuation by filename restarts search at beginning of directory
natalie li - Sun Microsystems - Irvine United States <Natalie.Li@Sun.COM>
parents:
5772
diff
changeset
|
52 |
char pwd[SMB_PASSWD_MAXLEN + 1]; |
5521
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
53 |
int rc = 0; |
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
54 |
|
5772
237ac22142fe
6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents:
5521
diff
changeset
|
55 |
rc = smb_config_getstr(SMB_CI_MACHINE_PASSWD, pwd, sizeof (pwd)); |
237ac22142fe
6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents:
5521
diff
changeset
|
56 |
if ((rc != SMBD_SMF_OK) || *pwd == '\0') { |
5521
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
57 |
return (-1); |
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
58 |
} |
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
59 |
|
5772
237ac22142fe
6560095 SNAS shows SIDs for Built-in Groups members instead of name
as200622
parents:
5521
diff
changeset
|
60 |
if (smb_auth_ntlm_hash(pwd, hash) != 0) |
5521
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
61 |
rc = -1; |
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
62 |
|
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
63 |
return (rc); |
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
64 |
} |
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
65 |
|
5331 | 66 |
/* |
67 |
* smbrdr_ipc_init |
|
68 |
* |
|
69 |
* Get system configuration regarding IPC connection |
|
70 |
* credentials and initialize related variables. |
|
71 |
* This function will normally be called at startup |
|
72 |
* (i.e. at the time smbrdr gets loaded). |
|
73 |
*/ |
|
74 |
void |
|
75 |
smbrdr_ipc_init(void) |
|
76 |
{ |
|
5521
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
77 |
int rc; |
5331 | 78 |
|
5521
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
79 |
(void) rw_wrlock(&smbrdr_ipc_lock); |
5331 | 80 |
bzero(&ipc_info, sizeof (smbrdr_ipc_t)); |
81 |
bzero(&orig_ipc_info, sizeof (smbrdr_ipc_t)); |
|
82 |
||
7961
4b5e3051f38b
6751647 TRANS2_FIND_NEXT continuation by filename restarts search at beginning of directory
natalie li - Sun Microsystems - Irvine United States <Natalie.Li@Sun.COM>
parents:
5772
diff
changeset
|
83 |
(void) smb_getsamaccount(ipc_info.user, SMB_USERNAME_MAXLEN); |
5521
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
84 |
rc = smbrdr_get_machine_pwd_hash(ipc_info.passwd); |
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
85 |
if (rc != 0) |
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
86 |
*ipc_info.passwd = 0; |
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
87 |
(void) rw_unlock(&smbrdr_ipc_lock); |
5331 | 88 |
|
89 |
} |
|
90 |
||
91 |
/* |
|
92 |
* smbrdr_ipc_set |
|
93 |
* |
|
94 |
* The given username and password hash will be applied to the |
|
5521
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
95 |
* ipc_info, which will be used for setting up the authenticated IPC |
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
96 |
* channel during join domain. |
5331 | 97 |
* |
5521
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
98 |
* If domain join operation succeeds, smbrdr_ipc_commit() should be |
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
99 |
* invoked to set the ipc_info with host credentials. Otherwise, |
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
100 |
* smbrdr_ipc_rollback() should be called to restore the previous |
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
101 |
* credentials. |
5331 | 102 |
*/ |
103 |
void |
|
104 |
smbrdr_ipc_set(char *plain_user, unsigned char *passwd_hash) |
|
105 |
{ |
|
106 |
(void) rw_wrlock(&smbrdr_ipc_lock); |
|
107 |
(void) strlcpy(ipc_info.user, plain_user, sizeof (ipc_info.user)); |
|
108 |
(void) memcpy(ipc_info.passwd, passwd_hash, SMBAUTH_HASH_SZ); |
|
109 |
(void) rw_unlock(&smbrdr_ipc_lock); |
|
110 |
||
111 |
} |
|
112 |
||
113 |
/* |
|
114 |
* smbrdr_ipc_commit |
|
115 |
* |
|
5521
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
116 |
* Save the host credentials, which will be used for any authenticated |
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
117 |
* IPC channel establishment after domain join. |
5331 | 118 |
* |
5521
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
119 |
* The host credentials is also saved to the original IPC info as |
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
120 |
* rollback data in case the join domain process fails in the future. |
5331 | 121 |
*/ |
122 |
void |
|
123 |
smbrdr_ipc_commit() |
|
124 |
{ |
|
125 |
(void) rw_wrlock(&smbrdr_ipc_lock); |
|
7961
4b5e3051f38b
6751647 TRANS2_FIND_NEXT continuation by filename restarts search at beginning of directory
natalie li - Sun Microsystems - Irvine United States <Natalie.Li@Sun.COM>
parents:
5772
diff
changeset
|
126 |
(void) smb_getsamaccount(ipc_info.user, SMB_USERNAME_MAXLEN); |
5521
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
127 |
(void) smbrdr_get_machine_pwd_hash(ipc_info.passwd); |
5331 | 128 |
(void) memcpy(&orig_ipc_info, &ipc_info, sizeof (smbrdr_ipc_t)); |
129 |
(void) rw_unlock(&smbrdr_ipc_lock); |
|
130 |
} |
|
131 |
||
132 |
/* |
|
133 |
* smbrdr_ipc_rollback |
|
134 |
* |
|
135 |
* Restore the original credentials |
|
136 |
*/ |
|
137 |
void |
|
138 |
smbrdr_ipc_rollback() |
|
139 |
{ |
|
140 |
(void) rw_wrlock(&smbrdr_ipc_lock); |
|
141 |
(void) strlcpy(ipc_info.user, orig_ipc_info.user, |
|
142 |
sizeof (ipc_info.user)); |
|
143 |
(void) memcpy(ipc_info.passwd, orig_ipc_info.passwd, |
|
144 |
sizeof (ipc_info.passwd)); |
|
145 |
(void) rw_unlock(&smbrdr_ipc_lock); |
|
146 |
} |
|
147 |
||
148 |
/* |
|
149 |
* Get & Set functions |
|
150 |
*/ |
|
151 |
char * |
|
152 |
smbrdr_ipc_get_user() |
|
153 |
{ |
|
154 |
char *user; |
|
155 |
||
156 |
(void) rw_rdlock(&smbrdr_ipc_lock); |
|
157 |
user = ipc_info.user; |
|
158 |
(void) rw_unlock(&smbrdr_ipc_lock); |
|
159 |
return (user); |
|
160 |
} |
|
161 |
||
5521
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
162 |
unsigned char * |
5331 | 163 |
smbrdr_ipc_get_passwd() |
164 |
{ |
|
5521
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
165 |
unsigned char *passwd; |
5331 | 166 |
|
167 |
(void) rw_rdlock(&smbrdr_ipc_lock); |
|
168 |
passwd = ipc_info.passwd; |
|
169 |
(void) rw_unlock(&smbrdr_ipc_lock); |
|
170 |
return (passwd); |
|
171 |
} |
|
172 |
||
173 |
/* |
|
174 |
* smbrdr_ipc_skip_lsa_query |
|
175 |
* |
|
176 |
* Determine whether LSA monitor should skip the LSA query due to the |
|
177 |
* incomplete authentication information if IPC is configured to be |
|
178 |
* authenticated. |
|
179 |
*/ |
|
180 |
int |
|
181 |
smbrdr_ipc_skip_lsa_query() |
|
182 |
{ |
|
5521
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
183 |
char *user; |
cf62335046cd
6575640 rename/rmdir/remove on mixed file systems work incorrectly for mangled names
as200622
parents:
5331
diff
changeset
|
184 |
unsigned char *pwd; |
5331 | 185 |
|
186 |
||
187 |
(void) rw_rdlock(&smbrdr_ipc_lock); |
|
188 |
user = ipc_info.user; |
|
189 |
pwd = ipc_info.passwd; |
|
190 |
(void) rw_unlock(&smbrdr_ipc_lock); |
|
191 |
||
192 |
return (!(*user && *pwd)); |
|
193 |
} |