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(talloc_tos(),
47 if (!NT_STATUS_IS_OK(nt_status
)) {
48 DBG_ERR("cli_full_connection failed! (%s)\n",
49 nt_errstr(nt_status
));
56 int main(int argc
, char *argv
[])
58 const char **argv_const
= discard_const_p(const char *, argv
);
59 TALLOC_CTX
*frame
= talloc_stackframe();
60 struct loadparm_context
*lp_ctx
= NULL
;
64 char *unc
, *mountpoint
, *server
, *share
;
65 struct cli_state
*cli
;
66 struct cli_credentials
*creds
= NULL
;
69 struct poptOption long_options
[] = {
72 POPT_COMMON_CREDENTIALS
73 { "port", 'p', POPT_ARG_INT
, &port
, 'p', "Port to connect to",
80 ok
= samba_cmdline_init(frame
,
81 SAMBA_CMDLINE_CONFIG_CLIENT
,
82 false /* require_smbconf */);
84 DBG_ERR("Failed to init cmdline parser!\n");
88 lp_ctx
= samba_cmdline_get_lp_ctx();
89 lpcfg_set_cmdline(lp_ctx
, "client min protocol", "SMB2");
90 lpcfg_set_cmdline(lp_ctx
, "client max protocol", "SMB3_11");
92 pc
= samba_popt_get_context(getprogname(),
98 DBG_ERR("Failed to setup popt context!\n");
103 poptSetOtherOptionHelp(pc
, "//server1/share1 mountpoint");
105 while ((opt
= poptGetNextOpt(pc
)) != -1) {
110 fprintf(stderr
, "Unknown Option: %c\n", opt
);
115 if (!poptPeekArg(pc
)) {
116 poptPrintUsage(pc
, stderr
, 0);
119 unc
= talloc_strdup(frame
, poptGetArg(pc
));
123 string_replace(unc
,'/','\\');
125 if (!poptPeekArg(pc
)) {
126 poptPrintUsage(pc
, stderr
, 0);
129 mountpoint
= talloc_strdup(frame
, poptGetArg(pc
));
130 if (mountpoint
== NULL
) {
135 samba_cmdline_burn(argc
, argv
);
137 server
= talloc_strdup(frame
, unc
+2);
141 share
= strchr_m(server
,'\\');
143 fprintf(stderr
, "Invalid argument: %s\n", server
);
150 creds
= samba_cmdline_get_creds();
152 cli
= connect_one(creds
, server
, port
, share
);
157 ret
= do_mount(cli
, mountpoint
);
159 fprintf(stderr
, "mount failed\n");