smbfs_ctx.c revision 2
2N/A * Copyright (c) 2000, Boris Popov 2N/A * All rights reserved. 2N/A * Redistribution and use in source and binary forms, with or without 2N/A * modification, are permitted provided that the following conditions 2N/A * 1. Redistributions of source code must retain the above copyright 2N/A * notice, this list of conditions and the following disclaimer. 2N/A * 2. Redistributions in binary form must reproduce the above copyright 2N/A * notice, this list of conditions and the following disclaimer in the 2N/A * documentation and/or other materials provided with the distribution. 2N/A * 3. All advertising materials mentioning features or use of this software 2N/A * must display the following acknowledgement: 2N/A * This product includes software developed by Boris Popov. 2N/A * 4. Neither the name of the author nor the names of any co-contributors 2N/A * may be used to endorse or promote products derived from this software 2N/A * without specific prior written permission. 2N/A * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 2N/A * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2N/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2N/A * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2N/A * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2N/A * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2N/A * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2N/A * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2N/A * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2N/A * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2N/A * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. 2N/A/* These two may be set by commands. */ 2N/A * Defaults for new contexts (connections to servers). 2N/A * These are set by smbfs_set_default_... 2N/A * Give the RPC library a callback hook that will be 2N/A * called whenever we destroy or reinit an smb_ctx_t. 2N/A * [The legacy name is rpc_cleanup_smbctx(), and was 2N/A * originally a direct call into the RPC code.] 2N/A * Get configurations from SMF. 2N/A * The LM authentication levels are shown in the table below. 2N/A * To enable Kerberos authentication, Kerberos flag is always set with all LM 2N/A * compatibility levels during SMB context initialization. 2N/A * +---+------------------------------+-----------------------------+ 2N/A * | 1 | Uses LM and NTLM | Accepts LM, NTLM and NTLMv2 | 2N/A * | | authentication | authentication | 2N/A * +---+------------------------------+-----------------------------+ 2N/A * | 2 | Uses NTLM authentication | Accepts LM, NTLM and NTLMv2 | 2N/A * | | | authentication | 2N/A * +---+------------------------------+-----------------------------+ 2N/A * | 3 | Uses NTLMv2 authentication | Accepts LM, NTLM and NTLMv2 | 2N/A * | | | authentication | 2N/A * +---+------------------------------+-----------------------------+ 2N/A * | 4 | Uses NTLMv2 authentication | Accepts NTLM and NTLMv2 | 2N/A * | | | authentication | 2N/A * +---+------------------------------+-----------------------------+ 2N/A * | 5 | Uses NTLMv2 authentication | Accepts NTLMv2 | 2N/A * | | | authentication | 2N/A * +---+------------------------------+-----------------------------+ 2N/A /* no change from default: SMB_AT_DEFAULT */ 2N/A * Initialize an smb_ctx struct (defaults) 2N/A * By default, SMB signing is enabled but not require. 2N/A /* Fill in defaults */ 2N/A * Default domain, user, ... 2N/A * Parse the UNC path. Here we expect something like 2N/A * "//host[/share[/path]]" 2N/A * This may be called outside of _scan_argv, 2N/A * so make sure these get initialized. 2N/A /* Work on a temporary copy, fix back slashes. */ 2N/A "UNC should start with '//'"), 0);
2N/A /* Find the share part, if any. */ 2N/A /* restore the slash */ 2N/A /* Find the path part, if any. */ 2N/A "empty share name"), 0);
2N/A "no share name required"), 0);
2N/A * Special case UNC names like: 2N/A * to have share: IPC$ 2N/A /* restore the slash */ 2N/A * Parse the string: domuser, which may be any of: 2N/A * and return pointers to the domain and user parts. 2N/A * Modifies the string domuser in-place. Returned 2N/A * string pointers are within the string domusr. 2N/A /* No separators - whole string is the user. */ 2N/A /* Have two strings. */ 2N/A sc = *p;
/* Save the sep. char */ 2N/A *p++ =
'\0';
/* zap it */ 2N/A /* Enforce just one separator */ 2N/A * Now, which order are they? 2N/A "user name '%s' too long"), 0,
name);
2N/A * Don't overwrite a value from the command line 2N/A * with one from anywhere else. 2N/A /* Mark this as "from the command line". */ 2N/A * Realm is obtained by converting the domain name to uppercase. 2N/A * Set realm by getting domain name from the resolver if either the full DNS 2N/A * domain name or the first label of the DNS domain name matches the passed 2N/A * Don't overwrite a domain name from the 2N/A * command line with one from anywhere else. 2N/A * See smbfs_ctx_init() for notes about this. 2N/A "workgroup name '%s' too long"), 0,
name);
2N/A * Don't overwrite a value from the command line 2N/A * with one from anywhere else. 2N/A /* Mark this as "from the command line". */ 2N/A * If called again after comand line parsing, 2N/A * don't overwrite a value from the command line 2N/A * with one from any stored config. 2N/A * Compute LM hash, NT hash. 2N/A /* Mark this as "from the command line". */ 2N/A * Use this to set NTLM auth. info (hashes) 2N/A * when we don't have the password. 2N/A /* Need ct_password to be non-null. */ 2N/A /* The LM hash is optional */ 2N/A * SMB client name resolution - normal, and/or NetBIOS. 2N/A * Returns an EAI_xxx error number like getaddrinfo(3) 2N/A * If the user specified an address, use it, 2N/A * and don't do NetBIOS lookup. 2N/A * Default the server name we'll use in the 2N/A * protocol (i.e. NTLM, tree connect). 2N/A * Try to lookup the host address using the 2N/A * normal name-to-IP address mechanisms. 2N/A * If that fails, we MAY try NetBIOS. 2N/A * If regular IP name lookup failed, try NetBIOS, 2N/A * but only if given a valid NetBIOS name and if 2N/A * NetBIOS name lookup is enabled. 2N/A * Return the original error from getaddrinfo 2N/A "getaddrinfo: %s: %s"), 0,
2N/A * Verify context info. before connect operation(s), 2N/A * lookup specified server and try to fill all forgotten fields. 2N/A * Legacy name used by commands. 2N/A "no server name specified"), 0);
2N/A "no share name specified for %s@%s"),
2N/A * Lookup the IP address and fill in ct_addrinfo. 2N/A * Note: smbfs_ctx_getaddr() returns a EAI_xxx 2N/A * error value like getaddrinfo(3), but this 2N/A * function needs to return an errno value. 2N/A "can't resolve name \"%s\", %s"),
2N/A * If we have a user name but no password, 2N/A * check for a keychain entry. 2N/A * XXX: Only for auth NTLM? 2N/A * No user name (anonymous session). 2N/A * If we don't have a p/w yet, 2N/A "no valid auth. types"), 0);
2N/A /* This handle controls per-process resources. */ 2N/A "failed to open driver"),
err);
2N/A * Check the driver version (paranoia) 2N/A "incorrect driver version"), 0);
2N/A * Find or create a connection + logon session 2N/A * Check whether the driver already has a VC 2N/A * we can use. If so, we're done! 2N/A * This calls the IOD to create a new session. 2N/A * Call findvc again. The new VC sould be 2N/A * found in the driver this time. 2N/A * Find or create a tree connection 2N/A /* The share name */ 2N/A /* The share "use" type. */ 2N/A * Todo: share passwords for share-level security. 2N/A * The driver does the actual TCON call. 2N/A * Check the returned share type 2N/A "%s: incompatible share type"),
2N/A * Return the hflags2 word for an smb_ctx. 2N/A "can't get flags2 for a session"),
errno);
2N/A * Get the transport level session key. 2N/A * Must already have an active SMB session. 2N/A * if the user name is not specified some other way, 2N/A * use the current user name (built-in default) 2N/A * Leave default domain empty. (That's valid). 2N/A * API for seting NetBIOS name lookup flags: 2N/A * NetBIOS name lookup enable, 2N/A * NetBIOS broadcast enable. 2N/A * Currently this APIs is unused. 2N/A * API for library consumer to set wins1, wins2 2N/A * API for library consumer to set NB scope.