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