windows-follow-backup-path-20080105
[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     HKEY hkSubmounts;
21     HKEY hkParameters;
22     char mountRoot[64]="/afs";
23     char * mountstring;
24
25     if (argc < 2 || argc > 3) {
26         fprintf(stderr, "afsshare.exe <submount> [<afs mount path>]\n");
27         exit(1);
28     }
29
30     if (RegCreateKeyEx( HKEY_LOCAL_MACHINE,
31                         AFSREG_CLT_OPENAFS_SUBKEY "\\Submounts",
32                         0,
33                         NULL,
34                         REG_OPTION_NON_VOLATILE,
35                         KEY_READ|KEY_WRITE,
36                         NULL,
37                         &hkSubmounts,
38                         NULL) == ERROR_SUCCESS) 
39     {
40         if ( argc == 2 ) {
41             if (RegDeleteValue(hkSubmounts, argv[1])) {
42                 fprintf(stderr,"Submount Deletion failure for [%s]: %lX",
43                          argv[1], GetLastError());
44                 RegCloseKey(hkSubmounts);
45                 return 1;
46             }
47         } else {
48             if (RegCreateKeyEx( HKEY_LOCAL_MACHINE,
49                                 AFSREG_CLT_SVC_PARAM_SUBKEY,
50                                 0,
51                                 NULL,
52                                 REG_OPTION_NON_VOLATILE,
53                                 KEY_READ,
54                                 NULL,
55                                 &hkParameters,
56                                 NULL) == ERROR_SUCCESS) 
57             {
58                 DWORD dwSize = sizeof(mountRoot);
59                 RegQueryValueEx (hkParameters, "MountRoot", NULL, NULL, (PBYTE)mountRoot, &dwSize);
60                 RegCloseKey(hkParameters);
61             }
62
63
64             if ( !strncmp(mountRoot, argv[2], strlen(mountRoot)) )
65                 mountstring = argv[2] + strlen(mountRoot);
66             else
67                 mountstring = argv[2];
68
69             if (RegSetValueEx(hkSubmounts, argv[1], 0, REG_EXPAND_SZ, mountstring, (DWORD)strlen(mountstring)+1)) {
70                 fprintf(stderr,"Submount Set failure for [%s]: %lX",
71                          argv[1], GetLastError());
72                 RegCloseKey(hkSubmounts);
73                 return 2;
74             }
75         }
76         RegCloseKey(hkSubmounts);
77     } else {
78         fprintf(stderr,"Submount access denied: %lX", GetLastError());
79         return 3;
80     }
81     return 0;
82 }