1
/* Editor Settings: expandtabs and use 4 spaces for indentation
2
* ex: set softtabstop=4 tabstop=8 expandtab shiftwidth=4: *
3
* -*- mode: c, c-basic-offset: 4 -*- */
6
* Copyright Likewise Software
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2 of the License, or (at
12
* your option) any later version.
14
* This program is distributed in the hope that it will be useful, but
15
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17
* for more details. You should have received a copy of the GNU General
18
* Public License along with this program. If not, see
19
* <http://www.gnu.org/licenses/>.
21
* LIKEWISE SOFTWARE MAKES THIS SOFTWARE AVAILABLE UNDER OTHER LICENSING
22
* TERMS AS WELL. IF YOU HAVE ENTERED INTO A SEPARATE LICENSE AGREEMENT
23
* WITH LIKEWISE SOFTWARE, THEN YOU MAY ELECT TO USE THE SOFTWARE UNDER THE
24
* TERMS OF THAT SOFTWARE LICENSE AGREEMENT INSTEAD OF THE TERMS OF THE GNU
25
* GENERAL PUBLIC LICENSE, NOTWITHSTANDING THE ABOVE NOTICE. IF YOU
26
* HAVE QUESTIONS, OR WISH TO REQUEST A COPY OF THE ALTERNATE LICENSING
27
* TERMS OFFERED BY LIKEWISE SOFTWARE, PLEASE CONTACT LIKEWISE SOFTWARE AT
28
* license@likewisesoftware.com
33
#define LWIO_OPT_KEY(t, p, v) { t, offsetof(IO_FUSE_CONTEXT, p), v }
41
static struct fuse_opt lwio_opts[] =
43
LWIO_OPT_KEY("--path %s", pszUncPath, 0),
44
LWIO_OPT_KEY("--user %s", pszUsername, 0),
45
LWIO_OPT_KEY("--domain %s", pszDomain, 0),
46
LWIO_OPT_KEY("--password %s", pszPassword, 0),
47
LWIO_OPT_KEY("-h", bHelp, 1),
48
LWIO_OPT_KEY("--help", bHelp, 1),
56
printf("lwio-fuse-mount: mount lwio path onto filesystem\n"
58
"Usage: lwio-fuse-mount --path unc_path mount_point\n"
62
" --path unc_path Specify UNC path\n"
63
" --user name User to log in as\n"
64
" --domain name Domain of user\n"
65
" --password password Password for user\n"
74
NTSTATUS status = STATUS_SUCCESS;
75
PIO_FUSE_CONTEXT pFuseContext = NULL;
76
struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
77
PWSTR pwszUncPath = NULL;
78
const static WCHAR wszCredPrefix[] = {'/', 'r', 'd', 'r', '/'};
79
struct termios oldFlags, newFlags;
81
FILE* ttyOut = stdout;
82
char szPassword[256] = {0};
84
status = RTL_ALLOCATE(&pFuseContext, IO_FUSE_CONTEXT, sizeof(*pFuseContext));
85
BAIL_ON_NT_STATUS(status);
87
if (fuse_opt_parse(&args, pFuseContext, lwio_opts, NULL) == -1)
92
if (pFuseContext->bHelp)
98
if (!pFuseContext->pszUncPath)
100
printf("Error: No UNC path specified\n");
104
status = LwRtlWC16StringAllocateFromCString(
106
pFuseContext->pszUncPath);
107
BAIL_ON_NT_STATUS(status);
109
status = LwIoUncPathToInternalPath(
111
&pFuseContext->pwszInternalPath);
112
BAIL_ON_NT_STATUS(status);
114
pFuseContext->ownerUid = geteuid();
115
pFuseContext->ownerGid = getegid();
117
if (pFuseContext->pszUsername)
119
if (!pFuseContext->pszPassword)
121
tcgetattr(fileno(ttyIn), &oldFlags);
122
memcpy(&newFlags, &oldFlags, sizeof(newFlags));
123
newFlags.c_lflag &= ~(ECHO);
124
tcsetattr(fileno(ttyIn), TCSANOW, &newFlags);
125
fprintf(ttyOut, "Password for %s: ", pFuseContext->pszUsername);
127
pFuseContext->pszPassword = fgets(szPassword, sizeof(szPassword), ttyIn);
128
if (szPassword[strlen(szPassword) - 1] == '\n')
130
szPassword[strlen(szPassword) - 1] = '\0';
132
fprintf(ttyOut, "\n");
133
tcsetattr(fileno(ttyIn), TCSANOW, &oldFlags);
136
status = LwIoCreatePlainCredsA(
137
pFuseContext->pszUsername,
138
pFuseContext->pszDomain,
139
pFuseContext->pszPassword,
140
&pFuseContext->pCreds);
141
BAIL_ON_NT_STATUS(status);
143
status = LwIoSetPathCreds(wszCredPrefix, pFuseContext->pCreds);
144
BAIL_ON_NT_STATUS(status);
147
return fuse_main(args.argc, args.argv, LwIoFuseGetOperationsTable(), pFuseContext);