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 "lib/cmdline/cmdline.h"
24 #include "lib/param/param.h"
26 #include "libsmb/proto.h"
29 static struct cli_state
*connect_one(struct cli_credentials
*creds
,
30 const char *server
, int port
,
33 struct cli_state
*c
= NULL
;
37 nt_status
= cli_full_connection_creds(&c
, lp_netbios_name(), server
,
42 if (!NT_STATUS_IS_OK(nt_status
)) {
43 DBG_ERR("cli_full_connection failed! (%s)\n",
44 nt_errstr(nt_status
));
51 int main(int argc
, char *argv
[])
53 const char **argv_const
= discard_const_p(const char *, argv
);
54 TALLOC_CTX
*frame
= talloc_stackframe();
55 struct loadparm_context
*lp_ctx
= NULL
;
59 char *unc
, *mountpoint
, *server
, *share
;
60 struct cli_state
*cli
;
61 struct cli_credentials
*creds
= NULL
;
64 struct poptOption long_options
[] = {
67 POPT_COMMON_CREDENTIALS
68 { "port", 'p', POPT_ARG_INT
, &port
, 'p', "Port to connect to",
75 ok
= samba_cmdline_init(frame
,
76 SAMBA_CMDLINE_CONFIG_CLIENT
,
77 false /* require_smbconf */);
79 DBG_ERR("Failed to init cmdline parser!\n");
83 lp_ctx
= samba_cmdline_get_lp_ctx();
84 lpcfg_set_cmdline(lp_ctx
, "client min protocol", "SMB2");
85 lpcfg_set_cmdline(lp_ctx
, "client max protocol", "SMB3_11");
87 pc
= samba_popt_get_context(getprogname(),
93 DBG_ERR("Failed to setup popt context!\n");
98 poptSetOtherOptionHelp(pc
, "//server1/share1 mountpoint");
100 while ((opt
= poptGetNextOpt(pc
)) != -1) {
105 fprintf(stderr
, "Unknown Option: %c\n", opt
);
110 if (!poptPeekArg(pc
)) {
111 poptPrintUsage(pc
, stderr
, 0);
114 unc
= talloc_strdup(frame
, poptGetArg(pc
));
118 string_replace(unc
,'/','\\');
120 if (!poptPeekArg(pc
)) {
121 poptPrintUsage(pc
, stderr
, 0);
124 mountpoint
= talloc_strdup(frame
, poptGetArg(pc
));
125 if (mountpoint
== NULL
) {
130 samba_cmdline_burn(argc
, argv
);
132 server
= talloc_strdup(frame
, unc
+2);
136 share
= strchr_m(server
,'\\');
138 fprintf(stderr
, "Invalid argument: %s\n", server
);
145 creds
= samba_cmdline_get_creds();
147 cli
= connect_one(creds
, server
, port
, share
);
152 ret
= do_mount(cli
, mountpoint
);
154 fprintf(stderr
, "mount failed\n");