2 * Copyright 2004. Secure Endpoints Inc.
4 * This software has been released under the terms of the IBM Public
5 * License. For details, see the LICENSE file in the top-level source
6 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afs/param.h>
13 #include <afs/fs_utils.h>
23 void usage(char * program)
25 fprintf(stderr, "Usage: %s <drive> <afs-path> [ <submount> ] [ /persistent ]\n", program);
26 fprintf(stderr, " %s <drive> <unc-path> [ /persistent ]\n", program);
27 fprintf(stderr, " %s <drive> /delete\n", program);
28 fprintf(stderr, " %s /list\n", program);
29 fprintf(stderr, " %s /help\n", program);
33 int main(int argc, char * argv)
38 DWORD mountRootLen = 0;
46 char submount[32] = "";
48 if ( argc < 2 || argc > 5 )
51 if ( stricmp("/list", argv[1]) ) {
52 /* print list of afs drive mappings */
57 if ( stricmp("/help", argv[1]) ) {
61 if ( strlen(argv[1]) == 2 && argv[1][1] == ':' ) {
62 drive = toupper(argv[1][0]);
63 if ( drive < 'A' || drive > 'Z' )
67 if ( stricmp("/delete", argv[2]) ) {
68 if ( !DriveIsGlobalAfsDrive(drive) ) {
69 fprintf(stderr, "%s: Drive %c is not mapped to AFS\n", argv[0], drive);
73 /* remove drive map */
74 WriteActiveMap( drive, FALSE );
75 code = DisMountDOSDrive( drive, TRUE );
77 fprintf(stderr, "%s: Unable to delete drive %c:, error = %lX\n", argv[0], code);
83 /* need to determine if argv[3] contains a /mountroot or \\netbiosname path.
84 * do not use hard code constants; instead use the registry strings
86 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSConfigKeyName,
87 0, KEY_QUERY_VALUE, &parmKey);
88 dummyLen = sizeof(cm_mountRoot);
89 code = RegQueryValueEx(parmKey, "MountRoot", NULL, NULL,
90 mountRoot, &mountRootLen);
91 if (code == ERROR_SUCCESS) {
92 cm_mountRootLen = strlen(cm_mountRoot);
94 strncpy(mountRoot, sizeof(cm_mountRoot), "/afs");
98 code = lana_GetNetbiosName(netbiosName, LANA_NETBIOS_NAME_FULL);
100 fprintf(stderr, "%s: Unable to determine AFS SMB server name\n",argv[0]);
103 netbiosNameLen = strlen(netbiosName);
105 if ( argv[3][0] == '\\' && argv[3][1] == '\\' &&
106 _strnicmp(netbiosName, &argv[3][2], netbiosNameLen) == 0 &&
107 argv[3][netbiosNameLen+3] == '\\') {
108 /* we have a UNC style path */
112 } else if (argc > 5) {
115 if ( stricmp("/persistent", argv[4]) )
120 code = MountDOSDrive(drive, &argv[3][netbiosNameLen+4], persistent, NULL);
122 fprintf(stderr, "%s: Unable to map %c: to %s, error = %lX\n", argv[0], drive, argv[3], code);
125 WriteActiveMap( drive, persistent );
129 if ( argv[3][0] == '/' &&
130 _strnicmp(mountRoot, &argv[1], mountRootLen) &&
131 argv[3][mountRootLen+2] == '/') {
132 /* we have an afs path */
133 /* check to see if we have a submount, if not generate a random one */
134 /* check to see if we are persistent or not */
137 /* we have neither persistence nor a submount name */
139 } else if ( argc > 6 ) {
141 } else if ( argc == 5 ) {
142 /* we have either persistence or a submount */
143 if ( _stricmp("/persistent", argv[4]) == 0 ) {
146 /* we have a submount name */
147 if ( !IsValidSubmountName(argv[4]) ) {
148 fprintf(stderr, "%s: invalid submount name: %s\n", argv[4]);
151 strcpy(submount, argv[4]);
155 /* we have both persistent and a submount */
156 if ( _stricmp("/persistent", argv[5]) == 0 ) {
162 if ( !IsValidSubmountName(argv[4]) ) {
163 fprintf(stderr, "%s: invalid submount name: %s\n", argv[4]);
166 strcpy(submount, argv[4]);
169 WriteActiveMap( drive, persistent );