xref: /onnv-gate/usr/src/lib/libresolv2/include/isc/irpmarshall.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * Copyright 2000-2002 Sun Microsystems, Inc.  All rights reserved.
3*0Sstevel@tonic-gate  * Use is subject to license terms.
4*0Sstevel@tonic-gate  */
5*0Sstevel@tonic-gate 
6*0Sstevel@tonic-gate /*
7*0Sstevel@tonic-gate  * Copyright (c) 1999 by Internet Software Consortium.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * Permission to use, copy, modify, and distribute this software for any
10*0Sstevel@tonic-gate  * purpose with or without fee is hereby granted, provided that the above
11*0Sstevel@tonic-gate  * copyright notice and this permission notice appear in all copies.
12*0Sstevel@tonic-gate  *
13*0Sstevel@tonic-gate  * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
14*0Sstevel@tonic-gate  * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
15*0Sstevel@tonic-gate  * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
16*0Sstevel@tonic-gate  * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
17*0Sstevel@tonic-gate  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
18*0Sstevel@tonic-gate  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
19*0Sstevel@tonic-gate  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
20*0Sstevel@tonic-gate  * SOFTWARE.
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate 
23*0Sstevel@tonic-gate /*
24*0Sstevel@tonic-gate  * $Id: irpmarshall.h,v 8.2 2001/05/29 05:47:10 marka Exp $
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #ifndef _IRPMARSHALL_H_INCLUDED
28*0Sstevel@tonic-gate #define _IRPMARSHALL_H_INCLUDED
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate /* Hide function names */
33*0Sstevel@tonic-gate #define irp_marshall_gr __irp_marshall_gr
34*0Sstevel@tonic-gate #define irp_marshall_ho __irp_marshall_ho
35*0Sstevel@tonic-gate #define irp_marshall_ne __irp_marshall_ne
36*0Sstevel@tonic-gate #define irp_marshall_ng __irp_marshall_ng
37*0Sstevel@tonic-gate #define irp_marshall_nw __irp_marshall_nw
38*0Sstevel@tonic-gate #define irp_marshall_pr __irp_marshall_pr
39*0Sstevel@tonic-gate #define irp_marshall_pw __irp_marshall_pw
40*0Sstevel@tonic-gate #define irp_marshall_sv __irp_marshall_sv
41*0Sstevel@tonic-gate #define irp_unmarshall_gr __irp_unmarshall_gr
42*0Sstevel@tonic-gate #define irp_unmarshall_ho __irp_unmarshall_ho
43*0Sstevel@tonic-gate #define irp_unmarshall_ne __irp_unmarshall_ne
44*0Sstevel@tonic-gate #define irp_unmarshall_ng __irp_unmarshall_ng
45*0Sstevel@tonic-gate #define irp_unmarshall_nw __irp_unmarshall_nw
46*0Sstevel@tonic-gate #define irp_unmarshall_pr __irp_unmarshall_pr
47*0Sstevel@tonic-gate #define irp_unmarshall_pw __irp_unmarshall_pw
48*0Sstevel@tonic-gate #define irp_unmarshall_sv __irp_unmarshall_sv
49*0Sstevel@tonic-gate 
50*0Sstevel@tonic-gate #define MAXPADDRSIZE (sizeof "255.255.255.255" + 1)
51*0Sstevel@tonic-gate #define ADDR_T_STR(x) (x == AF_INET ? "AF_INET" :\
52*0Sstevel@tonic-gate 		       (x == AF_INET6 ? "AF_INET6" : "UNKNOWN"))
53*0Sstevel@tonic-gate 
54*0Sstevel@tonic-gate /* See comment below on usage */
55*0Sstevel@tonic-gate int irp_marshall_pw(const struct passwd *pw, char **buffer, size_t *len);
56*0Sstevel@tonic-gate int irp_unmarshall_pw(struct passwd *pw, char *buffer);
57*0Sstevel@tonic-gate int irp_marshall_gr(const struct group *gr, char **buffer, size_t *len);
58*0Sstevel@tonic-gate int irp_unmarshall_gr(struct group *gr, char *buffer);
59*0Sstevel@tonic-gate int irp_marshall_sv(const struct servent *sv, char **buffer, size_t *len);
60*0Sstevel@tonic-gate int irp_unmarshall_sv(struct servent *sv, char *buffer);
61*0Sstevel@tonic-gate int irp_marshall_pr(struct protoent *pr, char **buffer, size_t *len);
62*0Sstevel@tonic-gate int irp_unmarshall_pr(struct protoent *pr, char *buffer);
63*0Sstevel@tonic-gate int irp_marshall_ho(struct hostent *ho, char **buffer, size_t *len);
64*0Sstevel@tonic-gate int irp_unmarshall_ho(struct hostent *ho, char *buffer);
65*0Sstevel@tonic-gate int irp_marshall_ng(const char *host, const char *user, const char *domain,
66*0Sstevel@tonic-gate 		    char **buffer, size_t *len);
67*0Sstevel@tonic-gate int irp_unmarshall_ng(const char **host, const char **user,
68*0Sstevel@tonic-gate 		      const char **domain, char *buffer);
69*0Sstevel@tonic-gate int irp_marshall_nw(struct nwent *ne, char **buffer, size_t *len);
70*0Sstevel@tonic-gate int irp_unmarshall_nw(struct nwent *ne, char *buffer);
71*0Sstevel@tonic-gate int irp_marshall_ne(struct netent *ne, char **buffer, size_t *len);
72*0Sstevel@tonic-gate int irp_unmarshall_ne(struct netent *ne, char *buffer);
73*0Sstevel@tonic-gate 
74*0Sstevel@tonic-gate /*
75*0Sstevel@tonic-gate  * Functions to marshall and unmarshall various system data structures. We
76*0Sstevel@tonic-gate  * use a printable ascii format that is as close to various system config
77*0Sstevel@tonic-gate  * files as reasonable (e.g. /etc/passwd format).
78*0Sstevel@tonic-gate  *
79*0Sstevel@tonic-gate  * We are not forgiving with unmarhsalling misformatted buffers. In
80*0Sstevel@tonic-gate  * particular whitespace in fields is not ignored. So a formatted password
81*0Sstevel@tonic-gate  * entry "brister  :1364:100:...." will yield a username of "brister   "
82*0Sstevel@tonic-gate  *
83*0Sstevel@tonic-gate  * We potentially do a lot of mallocs to fill fields that are of type
84*0Sstevel@tonic-gate  * (char **) like a hostent h_addr field. Building (for example) the
85*0Sstevel@tonic-gate  * h_addr field and its associated addresses all in one buffer is
86*0Sstevel@tonic-gate  * certainly possible, but not done here.
87*0Sstevel@tonic-gate  *
88*0Sstevel@tonic-gate  * The following description is true for all the marshalling functions:
89*0Sstevel@tonic-gate  *
90*0Sstevel@tonic-gate  */
91*0Sstevel@tonic-gate 
92*0Sstevel@tonic-gate /* int irp_marshall_XX(struct yyyy *XX, char **buffer, size_t *len);
93*0Sstevel@tonic-gate  *
94*0Sstevel@tonic-gate  * The argument XX (of type struct passwd for example) is marshalled in the
95*0Sstevel@tonic-gate  * buffer pointed at by *BUFFER, which is of length *LEN. Returns 0
96*0Sstevel@tonic-gate  * on success and -1 on failure. Failure will occur if *LEN is
97*0Sstevel@tonic-gate  * smaller than needed.
98*0Sstevel@tonic-gate  *
99*0Sstevel@tonic-gate  * If BUFFER is NULL, then *LEN is set to the size of the buffer
100*0Sstevel@tonic-gate  * needed to marshall the data and no marshalling is actually done.
101*0Sstevel@tonic-gate  *
102*0Sstevel@tonic-gate  * If *BUFFER is NULL, then a buffer large enough will be allocated
103*0Sstevel@tonic-gate  * with memget() and the size allocated will be stored in *LEN. An extra 2
104*0Sstevel@tonic-gate  * bytes will be allocated for the client to append CRLF if wanted. The
105*0Sstevel@tonic-gate  * value of *LEN will include these two bytes.
106*0Sstevel@tonic-gate  *
107*0Sstevel@tonic-gate  * All the marshalling functions produce a buffer with the fields
108*0Sstevel@tonic-gate  * separated by colons (except for the hostent marshalling, which uses '@'
109*0Sstevel@tonic-gate  * to separate fields). Fields that have multiple subfields (like the
110*0Sstevel@tonic-gate  * gr_mem field in struct group) have their subparts separated by
111*0Sstevel@tonic-gate  * commas.
112*0Sstevel@tonic-gate  */
113*0Sstevel@tonic-gate 
114*0Sstevel@tonic-gate /*
115*0Sstevel@tonic-gate  * int irp_unmarshall_XX(struct YYYYY *XX, char *buffer);
116*0Sstevel@tonic-gate  *
117*0Sstevel@tonic-gate  * The unmashalling functions break apart the buffer and store the
118*0Sstevel@tonic-gate  * values in the struct pointed to by XX. All pointer values inside
119*0Sstevel@tonic-gate  * XX are allocated with malloc. All arrays of pointers have a NULL
120*0Sstevel@tonic-gate  * as the last element.
121*0Sstevel@tonic-gate  */
122*0Sstevel@tonic-gate 
123*0Sstevel@tonic-gate #endif
124