windows-byte-range-locks-20050816
[openafs.git] / src / WINNT / afsd / afsshare.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include <afs/param.h>
11 #include <afs/stds.h>
12
13 #include <windows.h>
14 #include <stdio.h>
15
16 #include <WINNT\afsreg.h>
17
18 int
19 main(int argc, char **argv) {
20     BOOL res;
21     HKEY hkSubmounts;
22     HKEY hkParameters;
23     char mountRoot[64]="/afs";
24     char * mountstring;
25
26     if (argc < 2 || argc > 3) {
27         fprintf(stderr, "afsshare.exe <submount> [<afs mount path>]\n");
28         exit(1);
29     }
30
31     if (RegCreateKeyEx( HKEY_LOCAL_MACHINE,
32                         AFSREG_CLT_OPENAFS_SUBKEY "\\Submounts",
33                         0,
34                         NULL,
35                         REG_OPTION_NON_VOLATILE,
36                         KEY_READ|KEY_WRITE,
37                         NULL,
38                         &hkSubmounts,
39                         NULL) == ERROR_SUCCESS) 
40     {
41         if ( argc == 2 ) {
42             if (RegDeleteValue(hkSubmounts, argv[1])) {
43                 fprintf(stderr,"Submount Deletion failure for [%s]: %lX",
44                          argv[1], GetLastError());
45                 RegCloseKey(hkSubmounts);
46                 return 1;
47             }
48         } else {
49             if (RegCreateKeyEx( HKEY_LOCAL_MACHINE,
50                                 AFSREG_CLT_SVC_PARAM_SUBKEY,
51                                 0,
52                                 NULL,
53                                 REG_OPTION_NON_VOLATILE,
54                                 KEY_READ,
55                                 NULL,
56                                 &hkParameters,
57                                 NULL) == ERROR_SUCCESS) 
58             {
59                 DWORD dwSize = sizeof(mountRoot);
60                 RegQueryValueEx (hkParameters, "MountRoot", NULL, NULL, (PBYTE)mountRoot, &dwSize);
61                 RegCloseKey(hkParameters);
62             }
63
64
65             if ( !strncmp(mountRoot, argv[2], strlen(mountRoot)) )
66                 mountstring = argv[2] + strlen(mountRoot);
67             else
68                 mountstring = argv[2];
69
70             if (RegSetValueEx(hkSubmounts, argv[1], 0, REG_EXPAND_SZ, mountstring, strlen(mountstring)+1)) {
71                 fprintf(stderr,"Submount Set failure for [%s]: %lX",
72                          argv[1], GetLastError());
73                 RegCloseKey(hkSubmounts);
74                 return 2;
75             }
76         }
77         RegCloseKey(hkSubmounts);
78     } else {
79         fprintf(stderr,"Submount access denied: %lX", GetLastError());
80         return 3;
81     }
82     return 0;
83 }