1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
|
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#
include ../../Makefile.master
# Hammerhead: amd64-only
SUBDIRS = $(MACH64)
all : TARGET= all
clean : TARGET= clean
clobber : TARGET= clobber
delete : TARGET= delete
install : TARGET= install
_msg : TARGET= _msg
package : TARGET= package
LIBRARY= libnls.a
TEXT_DOMAIN= SUNW_OST_OSLIB
XGETFLAGS= -a
POFILE= $(LIBRARY:.a=.po)
POFILES= generic.po
.KEEP_STATE:
all clean clobber delete install package: $(SUBDIRS)
# install rule for install_h target
$(ROOTHDRDIR)/%: %
$(INS.file)
install_h: $(ROOTHDRS)
check: $(CHECKHDRS)
$(SUBDIRS): FRC
@cd $@; pwd; $(MAKE) $(TARGET)
_msg: $(MSGDOMAIN) $(POFILE)
$(RM) $(MSGDOMAIN)/$(POFILE)
$(CP) $(POFILE) $(MSGDOMAIN)
$(POFILE): $(POFILES)
$(RM) $@
$(CAT) $(POFILES) > $@
$(POFILES):
$(RM) messages.po
$(XGETTEXT) $(XGETFLAGS) *.[ch]* */*.[ch]*
$(SED) -e '/^# msg/d' -e '/^domain/d' messages.po > $@
$(RM) messages.po
FRC:
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
LIBRARY= libnls.a
VERS= .1
OBJECTS= nlsdata.o nlsenv.o nlsrequest.o
# include library definitions
include ../../Makefile.lib
SRCDIR = ../common
LIBS = $(DYNLIB)
CFLAGS += $(CCVERBOSE)
LDLIBS += -lnsl -lc
CERRWARN += -Wno-unused-variable
.KEEP_STATE:
# include library targets
include ../../Makefile.targ
pics/%.o: ../common/%.c
$(COMPILE.c) -o $@ $<
$(POST_PROCESS_O)
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
include ../Makefile.com
include ../../Makefile.lib.64
LIBS= $(DYNLIB)
.KEEP_STATE:
all: $(LIBS)
install: all $(ROOTLIBS64) $(ROOTLINKS64)
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
#
#
# MAPFILE HEADER START
#
# WARNING: STOP NOW. DO NOT MODIFY THIS FILE.
# Object versioning must comply with the rules detailed in
#
# usr/src/lib/README.mapfiles
#
# You should not be making modifications here until you've read the most current
# copy of that file. If you need help, contact a gatekeeper for guidance.
#
# MAPFILE HEADER END
#
$mapfile_version 2
SYMBOL_VERSION SUNW_1.1 {
global:
nlsgetcall;
nlsprovider;
nlsrequest;
};
SYMBOL_VERSION SUNWprivate_1.1 {
global:
nlsc2addr;
_nlscall { ASSERT = { TYPE = OBJECT; SIZE = addrsize; }; };
nlsenv;
_nlslog { ASSERT = { TYPE = OBJECT; SIZE = 4; }; };
_nlsrmsg { ASSERT = { TYPE = OBJECT; SIZE = addrsize; }; };
local:
*;
};
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.3 */
/*
* data used by network listener service library routines
*/
#include "sys/tiuser.h"
int _nlslog; /* non-zero allows use of stderr for messages */
struct t_call *_nlscall; /* call struct allocated by routines */
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* nlsenv.c:
*
* Utilities for servers to access environment set by listener.
*
* nlsgetcall: Returns pointer to t_call structure listener recieved during
* the t_listen. Gets data from environment and converts
* the data to internal address form.
*
* nlsprovider: Returns name of provider from environment.
*
*/
#include <ctype.h>
#include <strings.h>
#include <sys/tiuser.h>
#include "listen.h"
/*
* define DEBUGMODE for diagnostic printf's to stderr
*/
/* #define DEBUGMODE */
#ifdef DEBUGMODE
#include <stdio.h>
#endif
/*
* nlsenv: (static)
*
* Given an environment variable name, a receiving buffer and the length
* of the receiving buffer, getenv gets the environment variable, decodes
* it and places the decoded data in addr. The return value is the length
* of "addr" if succesful, or a negative value if unsuccessful.
*/
extern char *getenv();
int
nlsenv(struct netbuf *buf, char *envname)
{
char *charaddr;
extern char *calloc();
extern int nlsc2addr();
int length;
if (!(charaddr = getenv(envname)))
return(-11);
#ifdef DEBUGMODE
fprintf(stderr, "nlsenv: environ %s = %s len = %d\n",
envname, charaddr, strlen(charaddr));
#endif
if ((int)strlen(charaddr) & 1)
return(-12);
length = (strlen(charaddr) + 1) / 2;
if (!(buf->buf = calloc(1, length)))
return(-13);
else
buf->maxlen = length;
return(nlsc2addr(buf->buf, buf->maxlen, charaddr));
}
/*
* nlsgetcall: Get calling data provided by the client via the listener.
*
* nlsgetcall allows network server processes started by the
* network listener process to access the callers 't_call'
* structure provided in the client's t_connect primitive.
*
* This routine gets this data from the environment
* via putenv(3C), interprets the data and places the data
* in a t_call structure allocated via t_alloc.
*
* synopsis:
*
* struct t_call *nlsgetcall(fd);
* int fd; arg now ignored
*
*
* returns: Address of an allocated t_call structure
* or
* NULL for failure. (calloc failed)
* If calloc succeeds, non-existant
* env. variables or data is indicated
* by a negative 'len' field in the approp.
* netbuf structure. A length of zero in the
* netbuf structure is valid.
*
*/
struct t_call *
nlsgetcall(int fd)
{
struct t_call *call;
extern char *calloc();
if (!(call = (struct t_call *) calloc(1, sizeof(struct t_call))))
return((struct t_call *)0);
/*
* Note: space for buffers gets allocated by nlsenv on the fly
*/
call->addr.len = nlsenv(&call->addr, NLSADDR);
call->opt.len = nlsenv(&call->opt, NLSOPT);
call->udata.len = nlsenv(&call->udata, NLSUDATA);
return (call);
}
/*
* nlsprovider: Return the name of the transport provider
* as placed in the environment by the Network listener
* process. If the variable is not defined in the
* environment, a NULL pointer is returned.
*
* If the provider is "/dev/starlan", nlsprovider
* returns a pointer to the null terminated character string:
* "/dev/starlan" if this calling process is a child of the
* network listener process.
*/
char *
nlsprovider()
{
return(getenv(NLSPROVIDER));
}
/*
* nlsc2addr: Convert external address to internal form.
* (from nlsaddr.c)
*/
/*
* asctohex(X): convert char X to integer value
* assumes isxdigit(X). returns integer value.
* Note that 'a' > 'A'. See usage in code below.
*/
#define asctohex(X) \
((int)(isdigit(X) ? (int)(X-'0') : (X>='a') ? (X-'a')+10 : (X-'A')+10))
/*
* nlsc2addr: Given a buffer containing the hex/ascii representation
* of a logical address, the buffer's size and an address
* of a receiving buffer, char2addr converts the logical
* addr to internal format and returns the size of the logical
* address. A negative value is returned and the receiving
* buffers contents are undefined if:
*
* A. The receiving buffer is not large enough. (rc = -1)
* B. If 'charaddr' does not contain a series of octets
* (strlen(charaddr) must be even). (rc = -2)
* C. Any character in 'charaddr' is not an ASCII hex digit.
* (rc = -3)
*
* NOTE: that even if the internal representation of an address is
* an ASCII string, there is no guarantee that the output will be
* null terminated, thus the returned length must be used when
* accessing the internal address.
*/
int
nlsc2addr(char *addr, int maxlen, char *charaddr)
{
int len;
int i;
char c;
unsigned char val;
if (strlen(charaddr) & 1)
return(-1);
for (len = 0; ((maxlen--) && (*charaddr)); ++len) {
for (i = 2, val = 0; i--; ) {
c = *charaddr++;
if (!(isxdigit(c)))
return(-3);
val = (val << 4) | (unsigned char)asctohex(c);
}
*addr++ = (char)val;
}
#ifdef DEBUGMODE
fprintf(stderr, "nlsc2addr: returned length = %d\n", len);
#endif
return(*charaddr ? -2 : len);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
*
* nlsrequest(3):
*
* Send service request message to remote listener
* on previously established virtual circuit to remote
* listener process.
*
* If an error occurrs, t_errno will contain an error code.
*
* Setting the external integer "_nlslog" to any non-zero
* value before calling nlsrequest, will cause nlsrequest
* to print debug information on stderr.
*
* client/server process pairs should include their own
* initial handshake to insure connectivity.
*
* This version of nlsrequest includes the
* service request response message.
*/
#include <stdio.h>
#include <ctype.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <sys/tiuser.h>
#include "listen.h"
extern int _nlslog; /* non-zero allows use of stderr */
char *_nlsrmsg = (char *)0;
static char _nlsbuf[256];
int
nlsrequest(int fd, char *svc_code)
{
int len, err, flags;
char buf[256];
char *p;
int ret;
extern int t_errno;
t_errno = 0; /* indicates a 'name' problem */
buf[0] = 0;
/*
* Validate service code
*/
if (!svc_code || !strlen(svc_code) ||
(strlen(svc_code) >= (size_t)SVC_CODE_SZ)) {
if (_nlslog) {
fprintf(stderr,
"nlsrequest: invalid service code format\n");
}
return (-1);
}
/*
* send protocol message requesting the service
*/
len = sprintf(buf, nls_v2_msg, svc_code) + 1; /* inc trailing null */
if (t_snd(fd, buf, len, 0) < len) {
if (_nlslog)
t_error("t_snd of listener request message failed");
return (-1);
}
p = _nlsbuf;
len = 0;
do {
if (++len > sizeof (_nlsbuf)) {
if (_nlslog) {
fprintf(stderr,
"nlsrequest: _nlsbuf not large enough\n");
}
return (-1);
}
if (t_rcv(fd, p, sizeof (char), &flags) != sizeof (char)) {
if (_nlslog) {
t_error("t_rcv of listener response msg "
"failed");
}
return (-1);
}
} while (*p++ != '\0');
if ((p = strtok(_nlsbuf, ":")) == NULL)
goto parsefail;
/*
* We ignore the version number here as we do not have any use for it.
* Previous versions of the code looked at it by calling atoi() on it,
* which did not mutate the actual string and did not use it.
*/
if ((p = strtok(NULL, ":")) == NULL)
goto parsefail;
ret = atoi(p);
_nlsrmsg = p + strlen(p) + 1;
if (ret && _nlslog)
fprintf(stderr, "%s\n", _nlsrmsg); /* debug only */
return (ret);
parsefail:
if (_nlslog) {
fprintf(stderr,
"nlsrequest: failed parse of response message\n");
}
return (-1);
}
|