4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
24 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
28 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
29 /* All Rights Reserved */
32 #pragma ident "%Z%%M% %I% %E% SMI"
35 * lssmb.c: Contains all code specific to the MS-NET file server.
36 * Undef SMBSERVER to remove SMB support.
42 #include <sys/param.h>
43 #include <sys/tiuser.h>
54 * Dlevel - Debug level for DEBUG((level, ... ) type calls
55 * Msnet - Who is logging this message (the SMB code is)
59 #define Msnet "SMB parser:"
61 extern char *malloc();
62 char *bytes_to_ascii();
63 void getword(char *addr
, short *w
);
66 * In the event of an error, it may be necessary to send a response to
67 * the remote node before closing the virtual circuit. The following
68 * is the return message that should be sent. (Initially, I am not
69 * bothering to send the response message; I am assuming that the
70 * MS-NET client will be able to figure out that things went wrong, but
71 * we may find that is not the case.
74 static unsigned char errbuf
[] = {
75 /* NegProt Return */ 0xff, 'S', 'M', 'B', 0x72,
78 /* SMBerror */ 0x1, 0,
80 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
85 /* no dialects */ 0xff, 0xff,
93 * Function called by listener process when it receives a connect
94 * request from a node that wants to talk Microsoft's MS-NET Core
95 * Protocol...the functions gets called after the listener forks.
99 smbservice(bp
, bufsize
, argv
)
100 char *bp
; /* pointer to message buffer */
101 int bufsize
; /* size of message */
102 char **argv
; /* server arguments */
104 char *server
= *argv
; /* path of server */
113 * Is this really a correct negotiate protocol message?
116 if (*(bp
+FSP_COM
) != FSPnegprot
){
117 sprintf(logbuf
, "%s: Bad Command Code, 0x%x",
118 Msnet
, *(bp
+FSP_COM
));
123 * Are there exactly 0 argument words in the message?
126 if (*(bp
+FSP_WCNT
) != 0){
127 sprintf(logbuf
, "%s: Incorrect # of Parameter Words, 0x%x",
128 Msnet
, *(bp
+FSP_WCNT
));
133 * get the size of the data in the message
140 * make sure the data is valid; it should have a series of
141 * "dialect" strings, which are of the form [02 string 00].
142 * if(twos == nulls) then the data is well formed, else something
148 for(q
= p
; q
< p
+ size
; ++q
){
156 sprintf(logbuf
, "%s: Bad Data Format, twos=%d, nulls=%d",
162 * Count the number of arguments that were passed
163 * to me by the listener...
166 for(i
=0, args
=argv
; *args
; ++args
, ++i
)
170 * There are a few kinds of arguments that I will pass to the server:
172 * -D<string> - means "the client speaks this dialect . . ."
173 * there me be more than one of these, if the client
174 * is able to speak multiple dialects.
176 * Any arguments passed to me by the listener will be passed along
179 * Allocate an array of "char *"s that will let me point to all
181 * 1. As many -D options as are needed (the exact number is
182 * contained in the variable "twos"),
183 * 2. One -A option for the single logical name
185 * 3. As many positions as are needed to pass along the arguments
186 * passed to me by the listener (variable "i"),
187 * 4. The name of the Server executable file (always arg[0]), and
188 * 5. "Ascii-ized" version of input message as last arg.
189 * 6. A NULL terminator.
192 m_size
= sizeof(char *) * (twos
+ i
+ 4);
193 if((args
= (char **)malloc((unsigned)m_size
)) == 0){
194 sprintf(logbuf
, "%s: Can't malloc arg space, %d bytes",
200 * put together the first argument to exec(2) which should be
201 * the full pathname of the executable server file.
207 * Send dialect strings down, in order of preference
210 for(i
=1, q
=p
; q
< p
+ size
; ++i
, ++q
){
211 q
= strchr(q
, 02); /* find start of string */
213 m_size
= strlen(++q
) + 1 + 2;
214 if((args
[i
] = malloc((unsigned)m_size
)) == 0){
216 "%s: Can't malloc Server Path buf, %d bytes",
221 strcpy(args
[i
], "-D");
222 strcat(args
[i
], q
); /* put -Ddialect\0 in arglist */
223 q
= strchr(q
, '\0'); /* find end of string */
227 * Add in arguments that were passed to me by the listener
228 * first arg is server path, so we ignore that.
231 for( ++argv
; *argv
; ++argv
, ++i
)
235 * add ascii-ized version of message
238 args
[i
++] = bytes_to_ascii(bp
, bufsize
);
241 * NULL terminate the list
246 exec_cmd((dbf_t
*)0, args
);
247 return; /* error logged in start_server */
257 * move a word from an arbitrary position in a character buffer, into
258 * a short, and flip the bytes.
259 * (NOTE that word is a 16-bit iapx-286 word).
263 getword(char *addr
, short *w
)
265 lobyte(*w
) = *addr
++;
269 /* b y t e s _ t o _ a s c i i
270 * Routine to convert a binary array to a printable sequence of
271 * characters. For example, if the input to this routine were:
273 * inbuf = "012", and n = 3
275 * then the output would be a pointer to the string:
279 * No assumption is made about NULL terminators on input, because
280 * it is probably binary, and not a string.
285 bytes_to_ascii(inbuf
, n
)
286 char *inbuf
; /* initialized buffer of binary data */
287 int n
; /* size of input buffer */
289 char *outbuf
; /* return string */
290 char *p
; /* scratch pointer */
291 int i
; /* scratch variable */
293 /* malloc 2x space for output plus one for NULL */
294 if (outbuf
= malloc(n
* 2 + 1)) {
295 /* Fill in output buffer, with 2 character, capitalized hex. */
296 for (i
= 0, p
= outbuf
; i
< n
; ++inbuf
, p
+= 2, ++i
) {
297 sprintf(p
, "%2.2X", *inbuf
);
310 smbservice(bp
, size
, argv
)
311 char *bp
; /* pointer to message buffer */
312 int size
; /* size of message */
313 char **argv
; /* server arguments */
315 logmessage("SMB service NOT supported");
318 #endif /* SMBSERVICE */