]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libncp/ncpl_misc.c
This commit was generated by cvs2svn to compensate for changes in r98247,
[FreeBSD/FreeBSD.git] / lib / libncp / ncpl_misc.c
1 /*
2  * Copyright (c) 1999, Boris Popov
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *    This product includes software developed by Boris Popov.
16  * 4. Neither the name of the author nor the names of any co-contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  * calls that don't fit to any other category
33  */
34
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
37
38 #include <sys/types.h>
39 #include <sys/time.h>
40 #include <arpa/inet.h>
41 #include <errno.h>
42 #include <stdio.h>
43 #include <strings.h>
44
45 #include <netncp/ncp_lib.h>
46
47 static time_t
48 ncp_nw_to_ctime(struct nw_time_buffer *source) {
49         struct tm u_time;
50
51         bzero(&u_time,sizeof(struct tm));
52         /*
53          * XXX: NW 4.x tracks daylight automatically
54          */
55         u_time.tm_isdst = -1;
56         u_time.tm_sec = source->second;
57         u_time.tm_min = source->minute;
58         u_time.tm_hour = source->hour;
59         u_time.tm_mday = source->day;
60         u_time.tm_mon = source->month - 1;
61         u_time.tm_year = source->year;
62
63         if (u_time.tm_year < 80) {
64                 u_time.tm_year += 100;
65         }
66         return mktime(&u_time);
67 }
68
69 int
70 ncp_get_file_server_information(NWCONN_HANDLE connid,
71         struct ncp_file_server_info *target)
72 {
73         int error;
74         DECLARE_RQ;
75
76         ncp_init_request_s(conn, 17);
77         if ((error = ncp_request(connid, 23, conn)) != 0) 
78                 return error;
79         memcpy(target, ncp_reply_data(conn, 0), sizeof(*target));
80         target->MaximumServiceConnections
81             = htons(target->MaximumServiceConnections);
82         target->ConnectionsInUse
83             = htons(target->ConnectionsInUse);
84         target->MaxConnectionsEverUsed
85             = htons(target->MaxConnectionsEverUsed);
86         target->NumberMountedVolumes
87             = htons(target->NumberMountedVolumes);
88         return 0;
89 }
90
91 int
92 ncp_get_stations_logged_info(NWCONN_HANDLE connid, u_int32_t connection,
93         struct ncp_bindery_object *target, time_t *login_time)
94 {
95         int error;
96         DECLARE_RQ;
97
98         ncp_init_request_s(conn, 28);
99         ncp_add_dword_lh(conn, connection);
100
101         if ((error = ncp_request(connid, 23, conn)) != 0)
102                 return error;
103         bzero(target, sizeof(*target));
104         target->object_id = ncp_reply_dword_hl(conn, 0);
105         target->object_type = ncp_reply_word_hl(conn, 4);
106         memcpy(target->object_name, ncp_reply_data(conn, 6),
107                sizeof(target->object_name));
108         *login_time = ncp_nw_to_ctime((struct nw_time_buffer *)ncp_reply_data(conn, 54));
109         return 0;
110 }
111
112 int
113 ncp_get_internet_address(NWCONN_HANDLE connid, u_int32_t connection,
114         struct ipx_addr *target, u_int8_t * conn_type)
115 {
116         int error;
117         DECLARE_RQ;
118
119         ncp_init_request_s(conn, 26);
120         ncp_add_dword_lh(conn, connection);
121         error = ncp_request(connid, 23, conn);
122         if (error) return error;
123         bzero(target, sizeof(*target));
124         ipx_netlong(*target) = ncp_reply_dword_lh(conn, 0);
125         memcpy(&(target->x_host), ncp_reply_data(conn, 4), 6);
126         target->x_port = ncp_reply_word_lh(conn, 10);
127         *conn_type = ncp_reply_byte(conn, 12);
128         return 0;
129 }
130
131 NWCCODE
132 NWGetObjectConnectionNumbers(NWCONN_HANDLE connHandle,
133                 pnstr8 pObjName, nuint16 objType,
134                 pnuint16 pNumConns, pnuint16 pConnHandleList,
135                 nuint16 maxConns) 
136 {
137         int error, i, n;
138         nuint32 lastconn;
139         DECLARE_RQ;
140
141         lastconn = 0;
142         ncp_init_request_s(conn, 27);
143         ncp_add_dword_lh(conn, lastconn);
144         ncp_add_word_hl(conn, objType);
145         ncp_add_pstring(conn, pObjName);
146         if ((error = ncp_request(connHandle, 23, conn)) != 0) return error;
147         n = min(ncp_reply_byte(conn, 0), maxConns);
148         *pNumConns = n;
149         for (i = 0; i < n ; i++) {
150                 *pConnHandleList++ = ncp_reply_dword_lh(conn, i * 4 + 1);
151         }
152         return 0;
153 }
154
155 void
156 NWUnpackDateTime(nuint32 dateTime, NW_DATE *sDate, NW_TIME *sTime) {
157         NWUnpackDate(dateTime >> 16, sDate);
158         NWUnpackTime(dateTime & 0xffff, sTime);
159 }
160
161 void
162 NWUnpackDate(nuint16 date, NW_DATE *sDate) {
163         sDate->day = date & 0x1f;
164         sDate->month = (date >> 5) & 0xf;
165         sDate->year = ((date >> 9) & 0x7f) + 1980;
166 }
167
168 void
169 NWUnpackTime(nuint16 time, NW_TIME *sTime) {
170         sTime->seconds = time & 0x1f;
171         sTime->minutes = (time >> 5) & 0x3f;
172         sTime->hours = (time >> 11) & 0x1f;
173 }
174
175 nuint32
176 NWPackDateTime(NW_DATE *sDate, NW_TIME *sTime) {
177         return 0;
178 }
179
180 nuint16
181 NWPackDate(NW_DATE *sDate) {
182         return 0;
183 }
184
185 nuint16
186 NWPackTime(NW_TIME *sTime) {
187         return 0;
188 }
189
190 time_t
191 ncp_UnpackDateTime(nuint32 dateTime) {
192         struct tm u_time;
193         NW_DATE d;
194         NW_TIME t;
195
196         NWUnpackDateTime(dateTime, &d, &t);
197         bzero(&u_time,sizeof(struct tm));
198         u_time.tm_isdst = -1;
199         u_time.tm_sec = t.seconds;
200         u_time.tm_min = t.minutes;
201         u_time.tm_hour = t.hours;
202         u_time.tm_mday = d.day;
203         u_time.tm_mon = d.month - 1;
204         u_time.tm_year = d.year - 1900;
205
206         return mktime(&u_time);
207 }
208
209 int
210 ncp_GetFileServerDateAndTime(NWCONN_HANDLE cH, time_t *target) {
211         int error;
212         DECLARE_RQ;
213
214         ncp_init_request(conn);
215         if ((error = ncp_request(cH, 20, conn)) != 0)
216                 return error;
217         *target = ncp_nw_to_ctime((struct nw_time_buffer *) ncp_reply_data(conn, 0));
218         return 0;
219 }
220
221 int
222 ncp_SetFileServerDateAndTime(NWCONN_HANDLE cH, time_t * source) {
223         int year;
224         struct tm *utime = localtime(source);
225         DECLARE_RQ;
226
227         year = utime->tm_year;
228         if (year > 99) {
229                 year -= 100;
230         }
231         ncp_init_request_s(conn, 202);
232         ncp_add_byte(conn, year);
233         ncp_add_byte(conn, utime->tm_mon + 1);
234         ncp_add_byte(conn, utime->tm_mday);
235         ncp_add_byte(conn, utime->tm_hour);
236         ncp_add_byte(conn, utime->tm_min);
237         ncp_add_byte(conn, utime->tm_sec);
238         return ncp_request(cH, 23, conn);
239 }
240
241 NWCCODE
242 NWDownFileServer(NWCONN_HANDLE cH, int force) {
243         DECLARE_RQ;
244
245         ncp_init_request_s(conn, 211);
246         ncp_add_byte(conn, force ? 0 : 0xff);
247         return ncp_request(cH, 23, conn);
248 }
249
250 NWCCODE
251 NWCloseBindery(NWCONN_HANDLE cH) {
252         DECLARE_RQ;
253
254         ncp_init_request_s(conn, 68);
255         return ncp_request(cH, 23, conn);
256 }
257
258 NWCCODE
259 NWOpenBindery(NWCONN_HANDLE cH) {
260         DECLARE_RQ;
261
262         ncp_init_request_s(conn, 69);
263         return ncp_request(cH, 23, conn);
264 }
265
266 NWCCODE
267 NWDisableTTS(NWCONN_HANDLE cH) {
268         DECLARE_RQ;
269
270         ncp_init_request_s(conn, 207);
271         return ncp_request(cH, 23, conn);
272 }
273
274 NWCCODE
275 NWEnableTTS(NWCONN_HANDLE cH) {
276         DECLARE_RQ;
277
278         ncp_init_request_s(conn, 208);
279         return ncp_request(cH, 23, conn);
280 }
281
282 NWCCODE
283 NWDisableFileServerLogin(NWCONN_HANDLE cH) {
284         DECLARE_RQ;
285
286         ncp_init_request_s(conn, 203);
287         return ncp_request(cH, 23, conn);
288 }
289
290 NWCCODE
291 NWEnableFileServerLogin(NWCONN_HANDLE cH) {
292         DECLARE_RQ;
293
294         ncp_init_request_s(conn, 204);
295         return ncp_request(cH, 23, conn);
296 }