xref: /onnv-gate/usr/src/lib/libresolv2/include/isc/irpmarshall.h (revision 11038:74b12212b8a2)
10Sstevel@tonic-gate /*
2*11038SRao.Shoaib@Sun.COM  * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
30Sstevel@tonic-gate  * Copyright (c) 1999 by Internet Software Consortium.
40Sstevel@tonic-gate  *
50Sstevel@tonic-gate  * Permission to use, copy, modify, and distribute this software for any
60Sstevel@tonic-gate  * purpose with or without fee is hereby granted, provided that the above
70Sstevel@tonic-gate  * copyright notice and this permission notice appear in all copies.
80Sstevel@tonic-gate  *
9*11038SRao.Shoaib@Sun.COM  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
10*11038SRao.Shoaib@Sun.COM  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11*11038SRao.Shoaib@Sun.COM  * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
12*11038SRao.Shoaib@Sun.COM  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13*11038SRao.Shoaib@Sun.COM  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14*11038SRao.Shoaib@Sun.COM  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
15*11038SRao.Shoaib@Sun.COM  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
160Sstevel@tonic-gate  */
170Sstevel@tonic-gate 
180Sstevel@tonic-gate /*
19*11038SRao.Shoaib@Sun.COM  * $Id: irpmarshall.h,v 1.4 2005/04/27 04:56:17 sra Exp $
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate 
220Sstevel@tonic-gate #ifndef _IRPMARSHALL_H_INCLUDED
230Sstevel@tonic-gate #define _IRPMARSHALL_H_INCLUDED
240Sstevel@tonic-gate 
250Sstevel@tonic-gate /* Hide function names */
260Sstevel@tonic-gate #define irp_marshall_gr __irp_marshall_gr
270Sstevel@tonic-gate #define irp_marshall_ho __irp_marshall_ho
280Sstevel@tonic-gate #define irp_marshall_ne __irp_marshall_ne
290Sstevel@tonic-gate #define irp_marshall_ng __irp_marshall_ng
300Sstevel@tonic-gate #define irp_marshall_nw __irp_marshall_nw
310Sstevel@tonic-gate #define irp_marshall_pr __irp_marshall_pr
320Sstevel@tonic-gate #define irp_marshall_pw __irp_marshall_pw
330Sstevel@tonic-gate #define irp_marshall_sv __irp_marshall_sv
340Sstevel@tonic-gate #define irp_unmarshall_gr __irp_unmarshall_gr
350Sstevel@tonic-gate #define irp_unmarshall_ho __irp_unmarshall_ho
360Sstevel@tonic-gate #define irp_unmarshall_ne __irp_unmarshall_ne
370Sstevel@tonic-gate #define irp_unmarshall_ng __irp_unmarshall_ng
380Sstevel@tonic-gate #define irp_unmarshall_nw __irp_unmarshall_nw
390Sstevel@tonic-gate #define irp_unmarshall_pr __irp_unmarshall_pr
400Sstevel@tonic-gate #define irp_unmarshall_pw __irp_unmarshall_pw
410Sstevel@tonic-gate #define irp_unmarshall_sv __irp_unmarshall_sv
420Sstevel@tonic-gate 
430Sstevel@tonic-gate #define MAXPADDRSIZE (sizeof "255.255.255.255" + 1)
440Sstevel@tonic-gate #define ADDR_T_STR(x) (x == AF_INET ? "AF_INET" :\
450Sstevel@tonic-gate 		       (x == AF_INET6 ? "AF_INET6" : "UNKNOWN"))
460Sstevel@tonic-gate 
470Sstevel@tonic-gate /* See comment below on usage */
48*11038SRao.Shoaib@Sun.COM int irp_marshall_pw(const struct passwd *, char **, size_t *);
49*11038SRao.Shoaib@Sun.COM int irp_unmarshall_pw(struct passwd *, char *);
50*11038SRao.Shoaib@Sun.COM int irp_marshall_gr(const struct group *, char **, size_t *);
51*11038SRao.Shoaib@Sun.COM int irp_unmarshall_gr(struct group *, char *);
52*11038SRao.Shoaib@Sun.COM int irp_marshall_sv(const struct servent *, char **, size_t *);
53*11038SRao.Shoaib@Sun.COM int irp_unmarshall_sv(struct servent *, char *);
54*11038SRao.Shoaib@Sun.COM int irp_marshall_pr(struct protoent *, char **, size_t *);
55*11038SRao.Shoaib@Sun.COM int irp_unmarshall_pr(struct protoent *, char *);
56*11038SRao.Shoaib@Sun.COM int irp_marshall_ho(struct hostent *, char **, size_t *);
57*11038SRao.Shoaib@Sun.COM int irp_unmarshall_ho(struct hostent *, char *);
58*11038SRao.Shoaib@Sun.COM int irp_marshall_ng(const char *, const char *, const char *,
59*11038SRao.Shoaib@Sun.COM 		    char **, size_t *);
60*11038SRao.Shoaib@Sun.COM int irp_unmarshall_ng(const char **, const char **, const char **, char *);
61*11038SRao.Shoaib@Sun.COM int irp_marshall_nw(struct nwent *, char **, size_t *);
62*11038SRao.Shoaib@Sun.COM int irp_unmarshall_nw(struct nwent *, char *);
63*11038SRao.Shoaib@Sun.COM int irp_marshall_ne(struct netent *, char **, size_t *);
64*11038SRao.Shoaib@Sun.COM int irp_unmarshall_ne(struct netent *, char *);
650Sstevel@tonic-gate 
66*11038SRao.Shoaib@Sun.COM /*! \file
67*11038SRao.Shoaib@Sun.COM  * \brief
680Sstevel@tonic-gate  * Functions to marshall and unmarshall various system data structures. We
690Sstevel@tonic-gate  * use a printable ascii format that is as close to various system config
700Sstevel@tonic-gate  * files as reasonable (e.g. /etc/passwd format).
710Sstevel@tonic-gate  *
720Sstevel@tonic-gate  * We are not forgiving with unmarhsalling misformatted buffers. In
730Sstevel@tonic-gate  * particular whitespace in fields is not ignored. So a formatted password
740Sstevel@tonic-gate  * entry "brister  :1364:100:...." will yield a username of "brister   "
750Sstevel@tonic-gate  *
760Sstevel@tonic-gate  * We potentially do a lot of mallocs to fill fields that are of type
770Sstevel@tonic-gate  * (char **) like a hostent h_addr field. Building (for example) the
780Sstevel@tonic-gate  * h_addr field and its associated addresses all in one buffer is
790Sstevel@tonic-gate  * certainly possible, but not done here.
800Sstevel@tonic-gate  *
810Sstevel@tonic-gate  * The following description is true for all the marshalling functions:
820Sstevel@tonic-gate  *
83*11038SRao.Shoaib@Sun.COM  * int irp_marshall_XX(struct yyyy *XX, char **buffer, size_t *len);
840Sstevel@tonic-gate  *
850Sstevel@tonic-gate  * The argument XX (of type struct passwd for example) is marshalled in the
860Sstevel@tonic-gate  * buffer pointed at by *BUFFER, which is of length *LEN. Returns 0
870Sstevel@tonic-gate  * on success and -1 on failure. Failure will occur if *LEN is
880Sstevel@tonic-gate  * smaller than needed.
890Sstevel@tonic-gate  *
900Sstevel@tonic-gate  * If BUFFER is NULL, then *LEN is set to the size of the buffer
910Sstevel@tonic-gate  * needed to marshall the data and no marshalling is actually done.
920Sstevel@tonic-gate  *
930Sstevel@tonic-gate  * If *BUFFER is NULL, then a buffer large enough will be allocated
940Sstevel@tonic-gate  * with memget() and the size allocated will be stored in *LEN. An extra 2
950Sstevel@tonic-gate  * bytes will be allocated for the client to append CRLF if wanted. The
960Sstevel@tonic-gate  * value of *LEN will include these two bytes.
970Sstevel@tonic-gate  *
980Sstevel@tonic-gate  * All the marshalling functions produce a buffer with the fields
990Sstevel@tonic-gate  * separated by colons (except for the hostent marshalling, which uses '@'
1000Sstevel@tonic-gate  * to separate fields). Fields that have multiple subfields (like the
1010Sstevel@tonic-gate  * gr_mem field in struct group) have their subparts separated by
1020Sstevel@tonic-gate  * commas.
103*11038SRao.Shoaib@Sun.COM  *
1040Sstevel@tonic-gate  * int irp_unmarshall_XX(struct YYYYY *XX, char *buffer);
1050Sstevel@tonic-gate  *
1060Sstevel@tonic-gate  * The unmashalling functions break apart the buffer and store the
1070Sstevel@tonic-gate  * values in the struct pointed to by XX. All pointer values inside
1080Sstevel@tonic-gate  * XX are allocated with malloc. All arrays of pointers have a NULL
1090Sstevel@tonic-gate  * as the last element.
1100Sstevel@tonic-gate  */
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate #endif
113