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"
25 #include "libsmb/proto.h"
28 static struct cli_state
*connect_one(struct cli_credentials
*creds
,
29 const char *server
, int port
,
32 struct cli_state
*c
= NULL
;
36 nt_status
= cli_full_connection_creds(&c
, lp_netbios_name(), server
,
41 if (!NT_STATUS_IS_OK(nt_status
)) {
42 DBG_ERR("cli_full_connection failed! (%s)\n",
43 nt_errstr(nt_status
));
50 int main(int argc
, char *argv
[])
52 const char **argv_const
= discard_const_p(const char *, argv
);
53 TALLOC_CTX
*frame
= talloc_stackframe();
57 char *unc
, *mountpoint
, *server
, *share
;
58 struct cli_state
*cli
;
59 struct cli_credentials
*creds
= NULL
;
62 struct poptOption long_options
[] = {
65 POPT_COMMON_CREDENTIALS
66 { "port", 'p', POPT_ARG_INT
, &port
, 'p', "Port to connect to",
73 ok
= samba_cmdline_init(frame
,
74 SAMBA_CMDLINE_CONFIG_CLIENT
,
75 false /* require_smbconf */);
77 DBG_ERR("Failed to init cmdline parser!\n");
81 lp_set_cmdline("client min protocol", "SMB2");
82 lp_set_cmdline("client max protocol", "SMB3_11");
84 pc
= samba_popt_get_context(getprogname(),
90 DBG_ERR("Failed to setup popt context!\n");
95 poptSetOtherOptionHelp(pc
, "//server1/share1 mountpoint");
97 while ((opt
= poptGetNextOpt(pc
)) != -1) {
102 fprintf(stderr
, "Unknown Option: %c\n", opt
);
107 if (!poptPeekArg(pc
)) {
108 poptPrintUsage(pc
, stderr
, 0);
111 unc
= talloc_strdup(frame
, poptGetArg(pc
));
115 string_replace(unc
,'/','\\');
117 if (!poptPeekArg(pc
)) {
118 poptPrintUsage(pc
, stderr
, 0);
121 mountpoint
= talloc_strdup(frame
, poptGetArg(pc
));
122 if (mountpoint
== NULL
) {
127 samba_cmdline_burn(argc
, argv
);
129 server
= talloc_strdup(frame
, unc
+2);
133 share
= strchr_m(server
,'\\');
135 fprintf(stderr
, "Invalid argument: %s\n", server
);
142 creds
= samba_cmdline_get_creds();
144 cli
= connect_one(creds
, server
, port
, share
);
149 ret
= do_mount(cli
, mountpoint
);
151 fprintf(stderr
, "mount failed\n");