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
|
'\" te
.\" Copyright 1989 AT&T
.\" Copyright (C) 2004, Sun Microsystems, Inc. All Rights Reserved
.\" 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]
.TH YPCLNT 3NSL "Feb 25, 2017"
.SH NAME
ypclnt, yp_get_default_domain, yp_bind, yp_unbind, yp_match, yp_first, yp_next,
yp_all, yp_order, yp_master, yperr_string, ypprot_err \- NIS Version 2 client
interface
.SH SYNOPSIS
.LP
.nf
\fBcc\fR [ \fB-flag\fR... ] \fIfile\fR\&.\|.\|. \fB-lnsl\fR [ \fIlibrary\fR...]
#include <rpcsvc/ypclnt.h>
#include <rpcsvc/yp_prot.h>
\fBint\fR \fByp_bind\fR(\fBchar *\fR\fIindomain\fR);
.fi
.LP
.nf
\fBvoid\fR \fByp_unbind\fR (\fBchar *\fR\fIindomain\fR);
.fi
.LP
.nf
\fBint\fR \fByp_get_default_domain\fR(\fBchar **\fR\fIoutdomain\fR);
.fi
.LP
.nf
\fBint\fR \fByp_match\fR(\fBchar *\fR\fIindomain\fR, \fBchar *\fR\fIinmap\fR, \fBchar *\fR\fIinkey\fR, \fBint\fR \fIinkeylen\fR,
\fBchar *\fR\fBchar **\fR\fIoutval\fR, \fBint *\fR\fIoutvallen\fR);
.fi
.LP
.nf
\fBint\fR \fByp_first\fR(\fBchar *\fR\fIindomain\fR, \fBchar *\fR\fIinmap\fR, \fBchar **\fR\fIoutkey\fR, \fBint *\fR\fIoutkeylen\fR,
\fBchar **\fR\fIoutval\fR, \fBint *\fR\fIoutvallen\fR);
.fi
.LP
.nf
\fBint\fR \fByp_next\fR(\fBchar *\fR\fIindomain\fR, \fBchar *\fR\fIinmap\fR, \fBchar *\fR\fIinkey\fR, \fBint *\fR\fIinkeylen\fR,
\fBchar **\fR\fIoutkey\fR, \fBint *\fR\fIoutkeylen\fR, \fBchar **\fR\fIoutval\fR,
\fBint *\fR\fIoutvallen\fR);
.fi
.LP
.nf
\fBint\fR \fByp_all\fR(\fBchar *\fR\fIindomain\fR, \fBchar *\fR\fIinmap\fR, \fBstruct ypall_callback *\fR\fIincallback\fR);
.fi
.LP
.nf
\fBint\fR \fByp_order\fR(\fBchar *\fR\fIindomain\fR, \fBchar *\fR\fIinmap\fR, \fBunsigned long *\fR\fIoutorder\fR);
.fi
.LP
.nf
\fBint\fR \fByp_master\fR(\fBchar *\fR\fIindomain\fR, \fBchar *\fR\fIinmap\fR, \fBchar **\fR\fIoutname\fR);
.fi
.LP
.nf
\fBchar *\fR\fByperr_string\fR(\fBint\fR \fIincode\fR);
.fi
.LP
.nf
\fBint\fR \fBypprot_err\fR(\fBchar *\fR\fIdomain\fR);
.fi
.SH DESCRIPTION
.LP
This package of functions provides an interface to \fBNIS\fR, Network
Information Service Version 2, formerly referred to as \fBYP\fR.
For commands used to access \fBNIS\fR from a
client machine, see \fBypbind\fR(1M), \fBypwhich\fR(1), \fBypmatch\fR(1), and
\fBypcat\fR(1). The package can be loaded from the standard library,
\fB/usr/lib/libnsl.so.1\fR.
.sp
.LP
All input parameter names begin with \fIin\fR. Output parameters begin with
\fIout\fR. Output parameters of type \fBchar **\fR should be addresses of
uninitialized character pointers. Memory is allocated by the NIS client package
using \fBmalloc\fR(3C) and can be freed by the user code if it has no
continuing need for it. For each \fIoutkey\fR and \fIoutval\fR, two extra bytes
of memory are allocated at the end that contain NEWLINE and \fInull\fR,
respectively, but these two bytes are not reflected in \fIoutkeylen\fR or
\fIoutvallen\fR. The \fIindomain\fR and \fIinmap\fR strings must be non-null
and null-terminated. String parameters that are accompanied by a count
parameter may not be \fInull\fR, but they may point to null strings, with the
count parameter indicating this. Counted strings need not be null-terminated.
.sp
.LP
All functions in this package of type \fIint\fR return \fB0\fR if they succeed.
Otherwise, they return a failure code (\fBYPERR_\fR\fIxxxx\fR). Failure codes
are described in the \fBERRORS\fR section.
.SS "Routines"
.ne 2
.na
\fB\fByp_bind()\fR\fR
.ad
.RS 27n
To use the NIS name services, the client process must be "bound" to an NIS
server that serves the appropriate domain using \fByp_bind()\fR. Binding need
not be done explicitly by user code. Binding is done automatically whenever an
NIS lookup function is called. The \fByp_bind()\fR function can be called
directly for processes that make use of a backup strategy , for example, a
local file in cases when NIS services are not available. A process should call
\fByp_unbind()\fR when it is finished using \fBNIS\fR in order to free up
resources.
.RE
.sp
.ne 2
.na
\fB\fByp_unbind()\fR\fR
.ad
.RS 27n
Each binding allocates or uses up one client process socket descriptor. Each
bound domain costs one socket descriptor. However, multiple requests to the
same domain use that same descriptor. The \fByp_unbind()\fR function is
available at the client interface for processes that explicitly manage their
socket descriptors while accessing multiple domains. The call to
\fByp_unbind()\fR makes the domain \fIunbound\fR, and frees all per-process and
per-node resources used to bind it.
.sp
If an RPC failure results upon use of a binding, that domain will be unbound
automatically. At that point, the \fBypclnt()\fR layer will retry a few more
times or until the operation succeeds, provided that \fBrpcbind\fR(1M) and
\fBypbind\fR(1M) are running, and either:
.RS +4
.TP
.ie t \(bu
.el o
The client process cannot bind a server for the proper domain; or
.RE
.RS +4
.TP
.ie t \(bu
.el o
RPC requests to the server fail.
.RE
.sp
.LP
Under the following circumstances, the \fBypclnt\fR layer will return control
to the user code, with either an error or success code and the results:
.RS +4
.TP
.ie t \(bu
.el o
If an error is not RPC-related.
.RE
.RS +4
.TP
.ie t \(bu
.el o
If \fBrpcbind\fR is not running.
.RE
.RS +4
.TP
.ie t \(bu
.el o
If \fBypbind\fR is not running.
.RE
.RS +4
.TP
.ie t \(bu
.el o
If a bound \fBypserv\fR process returns any answer (success or failure).
.RE
.RE
.sp
.ne 2
.na
\fB\fByp_get_default_domain()\fR\fR
.ad
.RS 27n
\fBNIS\fR lookup calls require a map name and a domain name, at minimum. The
client process should know the name of the map of interest. Client processes
fetch the node's default domain by calling \fByp_get_default_domain()\fR and
use the returned \fIoutdomain\fR as the \fIindomain\fR parameter to successive
\fBNIS\fR name service calls. The domain returned is the same as that returned
using the \fBSI_SRPC_DOMAIN\fR command to the \fBsysinfo\fR(2) system call. The
value returned in \fIoutdomain\fR should not be freed.
.RE
.sp
.ne 2
.na
\fB\fByp_match()\fR\fR
.ad
.RS 27n
The \fByp_match()\fR function returns the value associated with a passed key.
This key must be exact because no pattern matching is available.
\fByp_match()\fR requires a full YP map name, such as \fBhosts.byname\fR,
instead of the nickname \fBhosts\fR.
.RE
.sp
.ne 2
.na
\fB\fByp_first()\fR\fR
.ad
.RS 27n
The \fByp_first()\fR function returns the first key-value pair from the named
map in the named domain.
.RE
.sp
.ne 2
.na
\fB\fByp_next()\fR\fR
.ad
.RS 27n
The \fByp_next()\fR function returns the next key-value pair in a named map.
The \fIinkey\fR parameter must be the \fIoutkey\fR returned from an initial
call to \fByp_first()\fR (to get the second key-value pair) or the one returned
from the \fIn\fRth call to \fByp_next()\fR (to get the \fIn\fRth + second
key-value pair). Similarly, the \fIinkeylen\fR parameter must be the
\fIoutkeylen\fR returned from the earlier \fByp_first()\fR or \fByp_next()\fR
call.
.sp
The concept of first and next is particular to the structure of the NIS map
being processed. Retrieval order is not related to either the lexical order
within any original (non-NIS name service) data base, or to any obvious
numerical sorting order on the keys, values, or key-value pairs. The only
ordering guarantee is that if the \fByp_first()\fR function is called on a
particular map, and then the \fByp_next()\fR function is repeatedly called on
the same map at the same server until the call fails with a reason of
\fBYPERR_NOMORE\fR, every entry in the data base is seen exactly once. Further,
if the same sequence of operations is performed on the same map at the same
server, the entries are seen in the same order.
.sp
Under conditions of heavy server load or server failure, the domain can become
unbound, then bound once again (perhaps to a different server) while a client
is running. This binding can cause a break in one of the enumeration rules.
Specific entries may be seen twice by the client, or not at all. This approach
protects the client from error messages that would otherwise be returned in the
midst of the enumeration. For a better solution to enumerating all entries in a
map, see \fByp_all()\fR.
.RE
.sp
.ne 2
.na
\fB\fByp_all()\fR\fR
.ad
.RS 27n
The \fByp_all()\fR function provides a way to transfer an entire map from
server to client in a single request using TCP (rather than UDP as with other
functions in this package). The entire transaction takes place as a single RPC
request and response. The \fByp_all()\fR function can be used just like any
other NIS name service procedure to identify the map in the normal manner and
to supply the name of a function that will be called to process each key-value
pair within the map. The call to \fByp_all()\fR returns only when the
transaction is completed (successfully or unsuccessfully), or the
\fBforeach()\fR function decides that it does not want to see any more
key-value pairs.
.sp
The third parameter to \fByp_all()\fR is:
.sp
.in +2
.nf
struct ypall_callback *incallback {
int (*foreach)(\|);
char *data;
};
.fi
.in -2
The function \fBforeach()\fR is called:
.sp
.in +2
.nf
foreach(int \fIinstatus\fR, char *\fIinkey\fR,
int \fIinkeylen\fR, char *\fIinval\fR,
int \fIinvallen\fR, char *\fIindata\fR);
.fi
.in -2
The \fIinstatus\fR parameter holds one of the return status values defined in
<\fBrpcsvc/yp_prot.h\fR>, either \fBYP_TRUE\fR or an error code. See
\fBypprot_err()\fR, for a function that converts an NIS name service protocol
error code to a \fBypclnt\fR layer error code.
.sp
The key and value parameters are somewhat different than defined in the
synopsis section above. First, the memory pointed to by the \fIinkey\fR and
\fIinval\fR parameters is private to the \fByp_all()\fR function, and is
overwritten with the arrival of each new key-value pair. The \fBforeach()\fR
function must do something useful with the contents of that memory, but it does
not own the memory itself. Key and value objects presented to the
\fBforeach()\fR function look exactly as they do in the server's map. If they
were not NEWLINE-terminated or null-terminated in the map, they would not be
here either.
.sp
The \fIindata\fR parameter is the contents of the \fIincallback\fR->\fIdata\fR
element passed to \fByp_all()\fR. The \fBdata\fR element of the callback
structure can be used to share state information between the \fBforeach()\fR
function and the mainline code. Its use is optional, and no part of the NIS
client package inspects its contents; cast it to something useful, or ignore
it. The \fBforeach()\fR function is Boolean. It should return \fB0\fR to
indicate that it wants to be called again for further received key-value pairs,
or non-zero to stop the flow of key-value pairs. If \fBforeach()\fR returns a
non-zero value, it is not called again. The functional value of \fByp_all()\fR
is then \fB0\fR.
.RE
.sp
.ne 2
.na
\fB\fByp_order()\fR\fR
.ad
.RS 27n
The \fByp_order()\fR function returns the order number for a map.
.RE
.sp
.ne 2
.na
\fB\fByp_master()\fR\fR
.ad
.RS 27n
The \fByp_master()\fR function returns the machine name of the master NIS
server for a map.
.RE
.sp
.ne 2
.na
\fB\fByperr_string()\fR\fR
.ad
.RS 27n
The \fByperr_string()\fR function returns a pointer to an error message string
that is null-terminated but contains no period or NEWLINE.
.RE
.sp
.ne 2
.na
\fB\fBypprot_err()\fR\fR
.ad
.RS 27n
The \fBypprot_err()\fR function takes an NIS name service protocol error code
as input, and returns a \fBypclnt()\fR layer error code, which can be used as
an input to \fByperr_string()\fR.
.RE
.SH RETURN VALUES
.LP
All integer functions return \fB0\fR if the requested operation is successful,
or one of the following errors if the operation fails:
.sp
.ne 2
.na
\fB\fBYPERR_ACCESS\fR\fR
.ad
.RS 17n
Access violation.
.RE
.sp
.ne 2
.na
\fB\fBYPERR_BADARGS\fR\fR
.ad
.RS 17n
The arguments to the function are bad.
.RE
.sp
.ne 2
.na
\fB\fBYPERR_BADDB\fR\fR
.ad
.RS 17n
The \fBYP\fR database is bad.
.RE
.sp
.ne 2
.na
\fB\fBYPERR_BUSY\fR\fR
.ad
.RS 17n
The database is busy.
.RE
.sp
.ne 2
.na
\fB\fBYPERR_DOMAIN\fR\fR
.ad
.RS 17n
Cannot bind to server on this domain.
.RE
.sp
.ne 2
.na
\fB\fBYPERR_KEY\fR\fR
.ad
.RS 17n
No such key in map.
.RE
.sp
.ne 2
.na
\fB\fBYPERR_MAP\fR\fR
.ad
.RS 17n
No such map in server's domain.
.RE
.sp
.ne 2
.na
\fB\fBYPERR_NODOM\fR\fR
.ad
.RS 17n
Local domain name not set.
.RE
.sp
.ne 2
.na
\fB\fBYPERR_NOMORE\fR\fR
.ad
.RS 17n
No more records in map database.
.RE
.sp
.ne 2
.na
\fB\fBYPERR_PMAP\fR\fR
.ad
.RS 17n
Cannot communicate with \fBrpcbind\fR.
.RE
.sp
.ne 2
.na
\fB\fBYPERR_RESRC\fR\fR
.ad
.RS 17n
Resource allocation failure.
.RE
.sp
.ne 2
.na
\fB\fBYPERR_RPC\fR\fR
.ad
.RS 17n
\fBRPC\fR failure; domain has been unbound.
.RE
.sp
.ne 2
.na
\fB\fBYPERR_YPBIND\fR\fR
.ad
.RS 17n
Cannot communicate with \fBypbind\fR.
.RE
.sp
.ne 2
.na
\fB\fBYPERR_YPERR\fR\fR
.ad
.RS 17n
Internal \fBYP\fR server or client error.
.RE
.sp
.ne 2
.na
\fB\fBYPERR_YPSERV\fR\fR
.ad
.RS 17n
Cannot communicate with \fBypserv\fR.
.RE
.sp
.ne 2
.na
\fB\fBYPERR_VERS\fR\fR
.ad
.RS 17n
\fBYP\fR version mismatch.
.RE
.SH FILES
.LP
\fB/usr/lib/libnsl.so.1\fR
.SH ATTRIBUTES
.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp
.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE ATTRIBUTE VALUE
_
MT-Level Safe
.TE
.SH SEE ALSO
.LP
\fBypcat\fR(1), \fBypmatch\fR(1), \fBypwhich\fR(1),
\fBrpcbind\fR(1M), \fBypbind\fR(1M), \fBypserv\fR(1M),
\fBsysinfo\fR(2), \fBmalloc\fR(3C), \fBypfiles\fR(4), \fBattributes\fR(5)
|