2 * Unix SMB/CIFS implementation.
3 * fusermount smb2 client
5 * Copyright (C) Volker Lendecke 2016
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "source3/include/includes.h"
23 #include "popt_common_cmdline.h"
25 #include "libsmb/proto.h"
28 static struct cli_state *connect_one(const struct user_auth_info *auth_info,
29 const char *server, int port,
32 struct cli_state *c = NULL;
36 nt_status = cli_full_connection_creds(&c, lp_netbios_name(), server,
39 get_cmdline_auth_info_creds(auth_info),
41 get_cmdline_auth_info_signing_state(auth_info));
42 if (!NT_STATUS_IS_OK(nt_status)) {
43 DBG_ERR("cli_full_connection failed! (%s)\n",
44 nt_errstr(nt_status));
48 if (get_cmdline_auth_info_smb_encrypt(auth_info)) {
49 nt_status = cli_cm_force_encryption_creds(
51 get_cmdline_auth_info_creds(auth_info),
53 if (!NT_STATUS_IS_OK(nt_status)) {
62 int main(int argc, char *argv[])
64 const char **argv_const = discard_const_p(const char *, argv);
65 TALLOC_CTX *frame = talloc_stackframe();
69 char *unc, *mountpoint, *server, *share;
70 struct cli_state *cli;
72 struct poptOption long_options[] = {
75 POPT_COMMON_CREDENTIALS
76 { "port", 'p', POPT_ARG_INT, &port, 'p', "Port to connect to",
82 setup_logging(argv[0], DEBUG_STDERR);
83 lp_set_cmdline("client min protocol", "SMB2");
84 lp_set_cmdline("client max protocol", "SMB3_11");
86 lp_load_global(get_dyn_CONFIGFILE());
89 pc = poptGetContext("smb2mount", argc, argv_const, long_options, 0);
90 poptSetOtherOptionHelp(pc, "//server1/share1 mountpoint");
92 while ((opt = poptGetNextOpt(pc)) != -1) {
97 fprintf(stderr, "Unknown Option: %c\n", opt);
102 if (!poptPeekArg(pc)) {
103 poptPrintUsage(pc, stderr, 0);
106 unc = talloc_strdup(frame, poptGetArg(pc));
110 string_replace(unc,'/','\\');
112 if (!poptPeekArg(pc)) {
113 poptPrintUsage(pc, stderr, 0);
116 mountpoint = talloc_strdup(frame, poptGetArg(pc));
117 if (mountpoint == NULL) {
122 popt_burn_cmdline_password(argc, argv);
124 server = talloc_strdup(frame, unc+2);
128 share = strchr_m(server,'\\');
130 fprintf(stderr, "Invalid argument: %s\n", share);
137 cli = connect_one(popt_get_cmdline_auth_info(), server, port, share);
142 ret = do_mount(cli, mountpoint);
144 fprintf(stderr, "mount failed\n");
148 popt_free_cmdline_auth_info();