docs:smbdotconf: fix a typo in oldpasswordallowedperiod.xml
[Samba.git] / examples / fuse / smb2mount.c
blobc64be57346291718a8a797740045ed682bca915a
1 /*
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"
22 #include "popt.h"
23 #include "popt_common_cmdline.h"
24 #include "client.h"
25 #include "libsmb/proto.h"
26 #include "clifuse.h"
28 static struct cli_state *connect_one(const struct user_auth_info *auth_info,
29 const char *server, int port,
30 const char *share)
32 struct cli_state *c = NULL;
33 NTSTATUS nt_status;
34 uint32_t flags = 0;
36 nt_status = cli_full_connection_creds(&c, lp_netbios_name(), server,
37 NULL, port,
38 share, "?????",
39 get_cmdline_auth_info_creds(auth_info),
40 flags);
41 if (!NT_STATUS_IS_OK(nt_status)) {
42 DBG_ERR("cli_full_connection failed! (%s)\n",
43 nt_errstr(nt_status));
44 return NULL;
47 return c;
50 int main(int argc, char *argv[])
52 const char **argv_const = discard_const_p(const char *, argv);
53 TALLOC_CTX *frame = talloc_stackframe();
54 poptContext pc;
55 int opt, ret;
56 int port = 0;
57 char *unc, *mountpoint, *server, *share;
58 struct cli_state *cli;
60 struct poptOption long_options[] = {
61 POPT_AUTOHELP
62 POPT_COMMON_SAMBA
63 POPT_COMMON_CREDENTIALS
64 { "port", 'p', POPT_ARG_INT, &port, 'p', "Port to connect to",
65 "PORT" },
66 POPT_TABLEEND
69 smb_init_locale();
70 setup_logging(argv[0], DEBUG_STDERR);
71 lp_set_cmdline("client min protocol", "SMB2");
72 lp_set_cmdline("client max protocol", "SMB3_11");
74 lp_load_global(get_dyn_CONFIGFILE());
75 load_interfaces();
77 pc = poptGetContext("smb2mount", argc, argv_const, long_options, 0);
78 poptSetOtherOptionHelp(pc, "//server1/share1 mountpoint");
80 while ((opt = poptGetNextOpt(pc)) != -1) {
81 switch(opt) {
82 case 'p':
83 break;
84 default:
85 fprintf(stderr, "Unknown Option: %c\n", opt);
86 exit(1);
90 if (!poptPeekArg(pc)) {
91 poptPrintUsage(pc, stderr, 0);
92 return -1;
94 unc = talloc_strdup(frame, poptGetArg(pc));
95 if (unc == NULL) {
96 return -1;
98 string_replace(unc,'/','\\');
100 if (!poptPeekArg(pc)) {
101 poptPrintUsage(pc, stderr, 0);
102 return -1;
104 mountpoint = talloc_strdup(frame, poptGetArg(pc));
105 if (mountpoint == NULL) {
106 return -1;
109 poptFreeContext(pc);
110 popt_burn_cmdline_password(argc, argv);
112 server = talloc_strdup(frame, unc+2);
113 if (!server) {
114 return -1;
116 share = strchr_m(server,'\\');
117 if (!share) {
118 fprintf(stderr, "Invalid argument: %s\n", share);
119 return -1;
122 *share = 0;
123 share++;
125 cli = connect_one(popt_get_cmdline_auth_info(), server, port, share);
126 if (cli == NULL) {
127 return -1;
130 ret = do_mount(cli, mountpoint);
131 if (ret != 0) {
132 fprintf(stderr, "mount failed\n");
133 return -1;
136 popt_free_cmdline_auth_info();
137 TALLOC_FREE(frame);
138 return 0;