windows-torture-test-20060625
[openafs.git] / src / WINNT / tests / torture / Source / ResolveLocker.c
1 /* 
2  * MODULE: locker.c.
3  *
4  * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology.
5  * For copying and distribution information, please see the file
6  * <mit-copyright.h>.
7  *
8  * Description: functions used by add, attach, detach, and shell extensions
9  */
10 #ifdef HAVE_HESOID
11
12 #ifdef _WIN32_WINNT
13     #undef _WIN32_WINNT
14 #endif
15
16 #define _WIN32_WINNT 0x0500
17
18 #include <windows.h>
19 #include <stdio.h>
20 #include <hesiod.h>
21 #include <locker.h>
22
23
24 char **ResolveHesName(char *locker);
25 void GetLockerInfo(char *Locker, char *Path);
26
27 int  ResolveLocker(USER_OPTIONS *attachOption)
28 {
29     char    HostName[128];
30     char    path[2048];
31     char    MountDir[2048];
32     char    ReparseDir[MAX_PATH];
33     char    AccessMode[16];
34     char    temp[4096];
35     char    FileSystem[16];
36     int     i;
37
38     memset(path, '\0', sizeof(path));
39     if (!stricmp(attachOption->type, "locker"))
40     {
41         GetLockerInfo(attachOption->Locker, path);
42         if (strlen(path) == 0)
43         {
44             return(FALSE);
45         }
46         memset(MountDir, 0, sizeof(MountDir));
47         memset(AccessMode, 0, sizeof(AccessMode));
48         memset(ReparseDir, 0, sizeof(ReparseDir));
49         memset(temp, 0, sizeof(temp));
50         sscanf(path, "%s %s", FileSystem, temp);
51
52         if (!strcmp(FileSystem, "AFS"))
53         {
54             sprintf(attachOption->SubMount, "\\\\afs\\%s", attachOption->Locker);
55             for (i = 0; i < (int)strlen(attachOption->SubMount); i++)
56             {
57                 if (attachOption->SubMount[i] == '/')
58                     attachOption->SubMount[i] = '\\';
59             }
60             strcpy(attachOption->type, "AFS");
61             return(TRUE);
62         }
63         else if (!strcmp(FileSystem, "NFS"))
64         {
65             if (strlen(attachOption->SubMount) != 0)
66             {
67                 return(FALSE);
68             }
69             if (sscanf(path, "%s %s %s %s %s", FileSystem, temp, HostName,
70                        AccessMode, ReparseDir) != 5)
71             {
72                 return(FALSE);
73             }
74             sprintf(attachOption->SubMount, "\\\\%s%s", HostName, temp);
75             for (i = 0; i < (int)strlen(attachOption->SubMount); i++)
76             {
77                 if (attachOption->SubMount[i] == '/')
78                     attachOption->SubMount[i] = '\\';
79             }
80             strcpy(attachOption->FileType, "NFS");
81             return(TRUE);
82         }
83         else
84         {
85             return(FALSE);
86         }
87     }
88     else
89     {
90         return(FALSE);
91     }
92
93 //    rc = resource_mount(attachOption, addtoPath, addtoFront, appName,
94 //                        MountDir, HostName, FileSystem);
95     return(TRUE);
96 }
97
98 void GetLockerInfo(char *Locker, char *Path)
99 {
100     char**  cpp;
101     char    cWeight[3];
102     char    cPath[256];
103     int     i;
104     int     last_weight;
105
106     cpp = NULL;
107     cpp = ResolveHesName(Locker);
108
109     if (cpp != NULL)
110     {
111         memset(cWeight, 0, sizeof(cWeight));
112         memset(cPath, 0, sizeof(cPath));
113         last_weight = 1000;
114         i = 0;
115         while (cpp[i] != NULL)
116         {
117             memset(cPath, '\0', sizeof(cPath));
118             if (sscanf(cpp[i], "%*s %s", cPath))
119             {
120                 if (strnicmp(cpp[i], "AFS", strlen("AFS")) == 0)
121                 {
122                     memset(cWeight, '\0', sizeof(cWeight));
123                     if (sscanf(cpp[i], "%*s %*s %*s %*s %s", cWeight))
124                     {
125                         if (atoi(cWeight) < last_weight)
126                         {
127                             strcpy(Path, cpp[i]);
128                             last_weight = (int)atoi(cWeight);
129                         }
130                     }
131                     else
132                         strcpy(Path, cpp[i]);
133                     }
134                 if (strnicmp(cpp[i], "NFS", strlen("NFS")) == 0)
135                     strcpy(Path, cpp[i]);
136             }
137             ++i;
138         }
139     }
140     return;
141 }
142
143 char **ResolveHesName(char *locker)
144 {
145     char   type[16];
146     char** cpp;
147     strcpy(type, "filsys");
148
149     cpp = NULL;
150     cpp = hes_resolve(locker, type);
151
152     return cpp;
153 }
154 #endif /*HAVE_HESOID */