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