summaryrefslogtreecommitdiff
path: root/usr/src/lib/smbsrv/libmlsvc/common/wkssvc_svc.c
blob: 85aab133bcdb9870c27099b7a74f75392c8be90c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
 */

#include <netdb.h>
#include <sys/types.h>
#include <string.h>
#include <strings.h>
#include <smbsrv/libsmb.h>
#include <smbsrv/libmlsvc.h>
#include <smbsrv/smbinfo.h>
#include <smbsrv/nmpipes.h>
#include <smbsrv/ndl/srvsvc.ndl>

static int wkssvc_s_NetWkstaGetInfo(void *, ndr_xa_t *);
static int wkssvc_s_NetWkstaTransportEnum(void *, ndr_xa_t *);

static ndr_stub_table_t wkssvc_stub_table[] = {
	{ wkssvc_s_NetWkstaGetInfo,	WKSSVC_OPNUM_NetWkstaGetInfo },
	{ wkssvc_s_NetWkstaTransportEnum, WKSSVC_OPNUM_NetWkstaTransportEnum },
	{0}
};

static ndr_service_t wkssvc_service = {
	"Workstation",			/* name (WKSSVC or WKSTA) */
	"Workstation services",		/* desc */
	"\\wkssvc",			/* endpoint */
	PIPE_NTSVCS,			/* sec_addr_port */
	"6bffd098-a112-3610-9833-46c3f87e345a", 1,	/* abstract */
	NDR_TRANSFER_SYNTAX_UUID,		2,	/* transfer */
	0,				/* no bind_instance_size */
	0,				/* no bind_req() */
	0,				/* no unbind_and_close() */
	0,				/* use generic_call_stub() */
	&TYPEINFO(wkssvc_interface),	/* interface ti */
	wkssvc_stub_table		/* stub_table */
};

void
wkssvc_initialize(void)
{
	(void) ndr_svc_register(&wkssvc_service);
}

/*
 * WKSSVC NetWkstaGetInfo
 */
static int
wkssvc_s_NetWkstaGetInfo(void *arg, ndr_xa_t *mxa)
{
	struct mslm_NetWkstaGetInfo *param = arg;
	mslm_NetWkstaGetInfo_rb *rb;
	char hostname[MAXHOSTNAMELEN];
	char resource_domain[SMB_PI_MAX_DOMAIN];
	smb_version_t version;
	char *name;
	char *domain;
	DWORD status;
	int rc;

	(void) smb_getdomainname(resource_domain, SMB_PI_MAX_DOMAIN);

	rb = NDR_NEW(mxa, mslm_NetWkstaGetInfo_rb);

	if ((rc = smb_getnetbiosname(hostname, MAXHOSTNAMELEN)) == 0) {
		name = NDR_STRDUP(mxa, hostname);
		domain = NDR_STRDUP(mxa, resource_domain);
	}

	if ((rc != 0) || (rb == NULL) || (name == NULL) || (domain == NULL)) {
		bzero(param, sizeof (struct mslm_NetWkstaGetInfo));
		param->status = ERROR_NOT_ENOUGH_MEMORY;
		return (NDR_DRC_OK);
	}

	smb_config_get_version(&version);

	param->result.level = param->level;
	param->result.bufptr.nullptr = (void *)rb;

	switch (param->level) {
	case 100:
		rb->buf100.wki100_platform_id = SV_PLATFORM_ID_NT;
		rb->buf100.wki100_ver_major = version.sv_major;
		rb->buf100.wki100_ver_minor = version.sv_minor;
		rb->buf100.wki100_computername = (unsigned char *)name;
		rb->buf100.wki100_langroup = (unsigned char *)domain;
		status = ERROR_SUCCESS;
		break;

	case 101:
		rb->buf101.wki101_platform_id = SV_PLATFORM_ID_NT;
		rb->buf101.wki101_ver_major = version.sv_major;
		rb->buf101.wki101_ver_minor = version.sv_minor;
		rb->buf101.wki101_computername = (unsigned char *)name;
		rb->buf101.wki101_langroup = (unsigned char *)domain;
		rb->buf101.wki101_lanroot = (unsigned char *)"";
		status = ERROR_SUCCESS;
		break;

	case 102:
		rb->buf102.wki102_platform_id = SV_PLATFORM_ID_NT;
		rb->buf102.wki102_ver_major = version.sv_major;
		rb->buf102.wki102_ver_minor = version.sv_minor;
		rb->buf102.wki102_computername = (unsigned char *)name;
		rb->buf102.wki102_langroup = (unsigned char *)domain;
		rb->buf102.wki102_lanroot = (unsigned char *)"";
		rb->buf102.wki102_logged_on_users = 1;
		status = ERROR_SUCCESS;
		break;

	case 502:
		bzero(&rb->buf502, sizeof (struct mslm_WKSTA_INFO_502));
		rb->buf502.keep_connection = 600;
		rb->buf502.max_commands = 1024;
		rb->buf502.session_timeout = 5400;
		rb->buf502.size_char_buf = 1024;
		rb->buf502.max_threads = 1024;
		rb->buf502.use_opportunistic_locking = 1;
		rb->buf502.use_unlock_behind = 1;
		rb->buf502.use_close_behind = 1;
		rb->buf502.buf_named_pipes = 1;
		rb->buf502.use_lock_read_unlock = 1;
		rb->buf502.utilize_nt_caching = 1;
		rb->buf502.use_raw_read = 1;
		rb->buf502.use_raw_write = 1;
		status = ERROR_SUCCESS;
		break;

	default:
		param->result.bufptr.nullptr = 0;
		status = ERROR_INVALID_LEVEL;
		break;
	}

	if (status != ERROR_SUCCESS) {
		bzero(param, sizeof (struct mslm_NetWkstaGetInfo));
		param->status = status;
	}

	return (NDR_DRC_OK);
}

/*
 * WKSSVC NetWkstaTransportEnum
 */
static int
wkssvc_s_NetWkstaTransportEnum(void *arg, ndr_xa_t *mxa)
{
	struct mslm_NetWkstaTransportEnum *param = arg;
	struct mslm_NetWkstaTransportCtr0 *info0;
	struct mslm_NetWkstaTransportInfo0 *ti0;

	switch (param->info.level) {
	case 0:
		info0 = NDR_NEW(mxa, struct mslm_NetWkstaTransportCtr0);
		ti0 = NDR_NEW(mxa, struct mslm_NetWkstaTransportInfo0);

		if (info0 == NULL || ti0 == NULL) {
			bzero(param, sizeof (struct mslm_NetWkstaGetInfo));
			param->status = ERROR_NOT_ENOUGH_MEMORY;
			break;
		}

		ti0->quality_of_service = 65535;
		ti0->num_vcs = 0;
		ti0->transport_name = (unsigned char *)"\\Device\\NetbiosSmb";
		ti0->transport_address = (unsigned char *)"000000000000";
		ti0->wan_ish = 1024;

		info0->count = 1;
		info0->ti0 = ti0;
		param->info.ru.info0 = info0;
		param->total_entries = 1;

		if (param->resume_handle)
			*param->resume_handle = 0;

		param->status = ERROR_SUCCESS;
		break;

	default:
		bzero(param, sizeof (struct mslm_NetWkstaGetInfo));
		param->status = ERROR_INVALID_LEVEL;
	}

	return (NDR_DRC_OK);
}