~ubuntu-branches/ubuntu/oneiric/likewise-open/oneiric

« back to all changes in this revision

Viewing changes to lwio-fuse/src/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott Salley
  • Date: 2010-11-22 12:06:00 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20101122120600-8lba1fpceot71wlb
Tags: 6.0.0.53010-1
Likewise Open 6.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 -*- */
4
 
 
5
 
/*
6
 
 * Copyright Likewise Software
7
 
 * All rights reserved.
8
 
 *
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.
13
 
 *
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/>.
20
 
 *
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
29
 
 */
30
 
 
31
 
#include "includes.h"
32
 
 
33
 
#define LWIO_OPT_KEY(t, p, v) { t, offsetof(IO_FUSE_CONTEXT, p), v }
34
 
 
35
 
enum
36
 
{
37
 
    KEY_VERSION,
38
 
    KEY_HELP
39
 
};
40
 
 
41
 
static struct fuse_opt lwio_opts[] =
42
 
{
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),
49
 
    FUSE_OPT_END
50
 
};
51
 
 
52
 
static
53
 
void
54
 
show_help()
55
 
{
56
 
    printf("lwio-fuse-mount: mount lwio path onto filesystem\n"
57
 
           "\n"
58
 
           "Usage: lwio-fuse-mount --path unc_path mount_point\n"
59
 
           "\n"
60
 
           "Options:\n"
61
 
           "\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"
66
 
           "\n");
67
 
}
68
 
 
69
 
int
70
 
main(int argc,
71
 
     char** argv
72
 
    )
73
 
{
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;
80
 
    FILE* ttyIn = stdin;
81
 
    FILE* ttyOut = stdout;
82
 
    char szPassword[256] = {0};
83
 
 
84
 
    status = RTL_ALLOCATE(&pFuseContext, IO_FUSE_CONTEXT, sizeof(*pFuseContext));
85
 
    BAIL_ON_NT_STATUS(status);
86
 
 
87
 
    if (fuse_opt_parse(&args, pFuseContext, lwio_opts, NULL) == -1)
88
 
    {
89
 
        goto error;
90
 
    }
91
 
 
92
 
    if (pFuseContext->bHelp)
93
 
    {
94
 
        show_help();
95
 
        return 0;
96
 
    }
97
 
 
98
 
    if (!pFuseContext->pszUncPath)
99
 
    {
100
 
        printf("Error: No UNC path specified\n");
101
 
        goto error;
102
 
    }
103
 
 
104
 
    status = LwRtlWC16StringAllocateFromCString(
105
 
        &pwszUncPath,
106
 
        pFuseContext->pszUncPath);
107
 
    BAIL_ON_NT_STATUS(status);
108
 
 
109
 
    status = LwIoUncPathToInternalPath(
110
 
        pwszUncPath,
111
 
        &pFuseContext->pwszInternalPath);
112
 
    BAIL_ON_NT_STATUS(status);
113
 
 
114
 
    pFuseContext->ownerUid = geteuid();
115
 
    pFuseContext->ownerGid = getegid();
116
 
 
117
 
    if (pFuseContext->pszUsername)
118
 
    {
119
 
        if (!pFuseContext->pszPassword)
120
 
        {
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);
126
 
            fflush(ttyOut);
127
 
            pFuseContext->pszPassword = fgets(szPassword, sizeof(szPassword), ttyIn);
128
 
            if (szPassword[strlen(szPassword) - 1] == '\n')
129
 
            {
130
 
                szPassword[strlen(szPassword) - 1] = '\0';
131
 
            }
132
 
            fprintf(ttyOut, "\n");
133
 
            tcsetattr(fileno(ttyIn), TCSANOW, &oldFlags);
134
 
        }
135
 
 
136
 
        status = LwIoCreatePlainCredsA(
137
 
            pFuseContext->pszUsername,
138
 
            pFuseContext->pszDomain,
139
 
            pFuseContext->pszPassword,
140
 
            &pFuseContext->pCreds);
141
 
        BAIL_ON_NT_STATUS(status);
142
 
 
143
 
        status = LwIoSetPathCreds(wszCredPrefix, pFuseContext->pCreds);
144
 
        BAIL_ON_NT_STATUS(status);
145
 
    }
146
 
  
147
 
    return fuse_main(args.argc, args.argv, LwIoFuseGetOperationsTable(), pFuseContext);
148
 
 
149
 
error:
150
 
 
151
 
    return 1;
152
 
}
153