1 /* os2acl.c - access to OS/2 (LAN Server) ACLs
3 * Author: Kai Uwe Rommel <rommel@ars.de>
4 * Created: Mon Aug 08 1994
6 * This code is in the public domain.
10 * supported 32-bit compilers:
12 * - IBM C Set++ 2.1 or newer
13 * - Watcom C/C++ 10.0 or newer
15 * supported 16-bit compilers:
17 * - Watcom C/C++ 10.0 or newer
19 * supported OS/2 LAN environments:
20 * - IBM LAN Server/Requester 3.0, 4.0 and 5.0 (Warp Server)
21 * - IBM Peer 1.0 (Warp Connect)
27 static char *rcsrev
= "$Revision$";
32 * Revision 1.2 2000/07/15 19:50:45 cvsuser
35 * Revision 1.1.2.1 2000/04/11 12:38:06 BS
36 * Added wxInstall a self extracting installation program using wxWindows.
38 * Revision 1.3 1996/04/03 19:18:27 rommel
41 * Revision 1.2 1996/03/30 22:03:52 rommel
42 * avoid frequent dynamic allocation for every call
45 * Revision 1.1 1996/03/30 09:35:00 rommel
58 #define INCL_DOSERRORS
61 #include "os2/os2acl.h"
65 #if defined(__WATCOMC__) && defined(__386__) && !defined(__32BIT__)
72 #define PSTR16 _far16ptr
73 #define PTR16(x) _emx_32to16(x)
74 #else /* other 32-bit */
75 #define PSTR16 PCHAR16
76 #define PTR16(x) ((PCHAR16)(x))
84 typedef struct access_list
86 char acl_ugname
[UNLEN
+1];
92 typedef struct access_info
94 PSTR16 acc_resource_name
;
101 static char *path
, *data
;
107 static USHORT (APIENTRY
*_NetAccessGetInfo
)(PSZ pszServer
, PSZ pszResource
,
108 USHORT sLevel
, PVOID pbBuffer
, USHORT cbBuffer
, PUSHORT pcbTotalAvail
);
109 static USHORT (APIENTRY
*_NetAccessSetInfo
)(PSZ pszServer
, PSZ pszResource
,
110 USHORT sLevel
, PVOID pbBuffer
, USHORT cbBuffer
, USHORT sParmNum
);
111 static USHORT (APIENTRY
*_NetAccessAdd
)(PSZ pszServer
,
112 USHORT sLevel
, PVOID pbBuffer
, USHORT cbBuffer
);
114 USHORT
NetAccessGetInfo(PSZ pszServer
, PSZ pszResource
, USHORT sLevel
,
115 PVOID pbBuffer
, USHORT cbBuffer
, PUSHORT pcbTotalAvail
)
118 (_THUNK_PROLOG (4+4+2+4+2+4);
119 _THUNK_FLAT (pszServer
);
120 _THUNK_FLAT (pszResource
);
121 _THUNK_SHORT (sLevel
);
122 _THUNK_FLAT (pbBuffer
);
123 _THUNK_SHORT (cbBuffer
);
124 _THUNK_FLAT (pcbTotalAvail
);
125 _THUNK_CALLI (_emx_32to16(_NetAccessGetInfo
)));
128 USHORT
NetAccessSetInfo(PSZ pszServer
, PSZ pszResource
, USHORT sLevel
,
129 PVOID pbBuffer
, USHORT cbBuffer
, USHORT sParmNum
)
132 (_THUNK_PROLOG (4+4+2+4+2+2);
133 _THUNK_FLAT (pszServer
);
134 _THUNK_FLAT (pszResource
);
135 _THUNK_SHORT (sLevel
);
136 _THUNK_FLAT (pbBuffer
);
137 _THUNK_SHORT (cbBuffer
);
138 _THUNK_SHORT (sParmNum
);
139 _THUNK_CALLI (_emx_32to16(_NetAccessSetInfo
)));
142 USHORT
NetAccessAdd(PSZ pszServer
, USHORT sLevel
,
143 PVOID pbBuffer
, USHORT cbBuffer
)
146 (_THUNK_PROLOG (4+2+4+2);
147 _THUNK_FLAT (pszServer
);
148 _THUNK_SHORT (sLevel
);
149 _THUNK_FLAT (pbBuffer
);
150 _THUNK_SHORT (cbBuffer
);
151 _THUNK_CALLI (_emx_32to16(_NetAccessAdd
)));
154 #else /* other 32-bit */
156 APIRET16 (* APIENTRY16 NetAccessGetInfo
)(PCHAR16 pszServer
, PCHAR16 pszResource
,
157 USHORT sLevel
, PVOID16 pbBuffer
, USHORT cbBuffer
, PVOID16 pcbTotalAvail
);
158 APIRET16 (* APIENTRY16 NetAccessSetInfo
)(PCHAR16 pszServer
, PCHAR16 pszResource
,
159 USHORT sLevel
, PVOID16 pbBuffer
, USHORT cbBuffer
, USHORT sParmNum
);
160 APIRET16 (* APIENTRY16 NetAccessAdd
)(PCHAR16 pszServer
,
161 USHORT sLevel
, PVOID16 pbBuffer
, USHORT cbBuffer
);
163 #define _NetAccessGetInfo NetAccessGetInfo
164 #define _NetAccessSetInfo NetAccessSetInfo
165 #define _NetAccessAdd NetAccessAdd
167 #if !defined(__IBMC__) || !defined(__TILED__)
168 #define _tmalloc malloc
175 USHORT (APIENTRY
*NetAccessGetInfo
)(PSZ pszServer
, PSZ pszResource
,
176 USHORT sLevel
, PVOID pbBuffer
, USHORT cbBuffer
, PUSHORT pcbTotalAvail
);
177 USHORT (APIENTRY
*NetAccessSetInfo
)(PSZ pszServer
, PSZ pszResource
,
178 USHORT sLevel
, PVOID pbBuffer
, USHORT cbBuffer
, USHORT sParmNum
);
179 USHORT (APIENTRY
*NetAccessAdd
)(PSZ pszServer
,
180 USHORT sLevel
, PVOID pbBuffer
, USHORT cbBuffer
);
182 #define _NetAccessGetInfo NetAccessGetInfo
183 #define _NetAccessSetInfo NetAccessSetInfo
184 #define _NetAccessAdd NetAccessAdd
186 #define _tmalloc malloc
189 #define DosQueryProcAddr(handle, ord, name, funcptr) \
190 DosGetProcAddr(handle, name, funcptr)
191 #define DosQueryCurrentDir DosQCurDir
192 #define DosQueryCurrentDisk DosQCurDisk
197 static BOOL
acl_init(void)
199 static BOOL initialized
, netapi_avail
;
208 if (DosLoadModule(buf
, sizeof(buf
), "NETAPI", &netapi
))
211 if (DosQueryProcAddr(netapi
, 0, "NETACCESSGETINFO", (PFN
*) &_NetAccessGetInfo
) ||
212 DosQueryProcAddr(netapi
, 0, "NETACCESSSETINFO", (PFN
*) &_NetAccessSetInfo
) ||
213 DosQueryProcAddr(netapi
, 0, "NETACCESSADD", (PFN
*) &_NetAccessAdd
))
216 #if defined(__WATCOMC__) && defined(__386__)
217 NetAccessGetInfo
= (PVOID
) (ULONG
) (PVOID16
) NetAccessGetInfo
;
218 NetAccessSetInfo
= (PVOID
) (ULONG
) (PVOID16
) NetAccessSetInfo
;
219 NetAccessAdd
= (PVOID
) (ULONG
) (PVOID16
) NetAccessAdd
;
222 if ((path
= _tmalloc(CCHMAXPATH
)) == NULL
)
224 if ((data
= _tmalloc(ACL_BUFFERSIZE
)) == NULL
)
226 if ((ai
= _tmalloc(sizeof(ACCINFO
))) == NULL
)
234 static void acl_mkpath(char *buffer
, const char *source
)
237 static char cwd
[CCHMAXPATH
];
242 if (isalpha(source
[0]) && source
[1] == ':')
243 buffer
[0] = 0; /* fully qualified names */
248 DosQueryCurrentDisk(&cdrive
, &drivemap
);
249 cwd
[0] = (char)(cdrive
+ '@');
252 cwdlen
= sizeof(cwd
) - 3;
253 DosQueryCurrentDir(0, cwd
+ 3, &cwdlen
);
254 cwdlen
= strlen(cwd
);
257 if (source
[0] == '/' || source
[0] == '\\')
259 if (source
[1] == '/' || source
[1] == '\\')
260 buffer
[0] = 0; /* UNC names */
263 strncpy(buffer
, cwd
, 2);
270 if (cwd
[cwdlen
- 1] != '\\' && cwd
[cwdlen
- 1] != '/')
275 strcat(buffer
, source
);
277 for (ptr
= buffer
; *ptr
; ptr
++)
287 static int acl_bin2text(char *data
, char *text
)
293 ai
= (ACCINFO
*) data
;
294 al
= (ACCLIST
*) (data
+ sizeof(ACCINFO
));
296 offs
= sprintf(text
, "ACL1:%X,%d\n",
297 ai
-> acc_attr
, ai
-> acc_count
);
299 for (cnt
= 0; cnt
< ai
-> acc_count
; cnt
++)
300 offs
+= sprintf(text
+ offs
, "%s,%X\n",
301 al
[cnt
].acl_ugname
, al
[cnt
].acl_access
);
306 int acl_get(char *server
, const char *resource
, char *buffer
)
318 acl_mkpath(path
, resource
);
321 rc
= NetAccessGetInfo(srv
, path
, 1, data
, ACL_BUFFERSIZE
, &datalen
);
324 acl_bin2text(data
, buffer
);
329 static int acl_text2bin(char *data
, char *text
, char *path
)
336 ai
= (ACCINFO
*) data
;
337 ai
-> acc_resource_name
= PTR16(path
);
339 if (sscanf(text
, "ACL1:%hX,%hd",
340 &ai
-> acc_attr
, &ai
-> acc_count
) != 2)
341 return ERROR_INVALID_PARAMETER
;
343 al
= (ACCLIST
*) (data
+ sizeof(ACCINFO
));
344 ptr
= strchr(text
, '\n') + 1;
346 for (cnt
= 0; cnt
< ai
-> acc_count
; cnt
++)
348 ptr2
= strchr(ptr
, ',');
349 strncpy(al
[cnt
].acl_ugname
, ptr
, ptr2
- ptr
);
350 al
[cnt
].acl_ugname
[ptr2
- ptr
] = 0;
351 sscanf(ptr2
+ 1, "%hx", &al
[cnt
].acl_access
);
352 ptr
= strchr(ptr
, '\n') + 1;
355 return sizeof(ACCINFO
) + ai
-> acc_count
* sizeof(ACCLIST
);
358 int acl_set(char *server
, const char *resource
, char *buffer
)
369 acl_mkpath(path
, resource
);
371 ai
-> acc_resource_name
= PTR16(path
);
375 NetAccessAdd(srv
, 1, ai
, sizeof(ACCINFO
));
376 /* Ignore any errors, most probably because ACL already exists. */
377 /* In any such case, try updating the existing ACL. */
379 datalen
= acl_text2bin(data
, buffer
, path
);
381 return NetAccessSetInfo(srv
, path
, 1, data
, datalen
, 0);
384 /* end of os2acl.c */