17c478bd9Sstevel@tonic-gate /*
2*9525b14bSRao Shoaib  * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
37c478bd9Sstevel@tonic-gate  * Copyright (c) 1999 by Internet Software Consortium.
47c478bd9Sstevel@tonic-gate  *
57c478bd9Sstevel@tonic-gate  * Permission to use, copy, modify, and distribute this software for any
67c478bd9Sstevel@tonic-gate  * purpose with or without fee is hereby granted, provided that the above
77c478bd9Sstevel@tonic-gate  * copyright notice and this permission notice appear in all copies.
87c478bd9Sstevel@tonic-gate  *
9*9525b14bSRao Shoaib  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
10*9525b14bSRao Shoaib  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11*9525b14bSRao Shoaib  * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
12*9525b14bSRao Shoaib  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13*9525b14bSRao Shoaib  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14*9525b14bSRao Shoaib  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
15*9525b14bSRao Shoaib  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
167c478bd9Sstevel@tonic-gate  */
177c478bd9Sstevel@tonic-gate 
187c478bd9Sstevel@tonic-gate /*
19*9525b14bSRao Shoaib  * $Id: irpmarshall.h,v 1.4 2005/04/27 04:56:17 sra Exp $
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate 
227c478bd9Sstevel@tonic-gate #ifndef _IRPMARSHALL_H_INCLUDED
237c478bd9Sstevel@tonic-gate #define _IRPMARSHALL_H_INCLUDED
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate /* Hide function names */
267c478bd9Sstevel@tonic-gate #define irp_marshall_gr __irp_marshall_gr
277c478bd9Sstevel@tonic-gate #define irp_marshall_ho __irp_marshall_ho
287c478bd9Sstevel@tonic-gate #define irp_marshall_ne __irp_marshall_ne
297c478bd9Sstevel@tonic-gate #define irp_marshall_ng __irp_marshall_ng
307c478bd9Sstevel@tonic-gate #define irp_marshall_nw __irp_marshall_nw
317c478bd9Sstevel@tonic-gate #define irp_marshall_pr __irp_marshall_pr
327c478bd9Sstevel@tonic-gate #define irp_marshall_pw __irp_marshall_pw
337c478bd9Sstevel@tonic-gate #define irp_marshall_sv __irp_marshall_sv
347c478bd9Sstevel@tonic-gate #define irp_unmarshall_gr __irp_unmarshall_gr
357c478bd9Sstevel@tonic-gate #define irp_unmarshall_ho __irp_unmarshall_ho
367c478bd9Sstevel@tonic-gate #define irp_unmarshall_ne __irp_unmarshall_ne
377c478bd9Sstevel@tonic-gate #define irp_unmarshall_ng __irp_unmarshall_ng
387c478bd9Sstevel@tonic-gate #define irp_unmarshall_nw __irp_unmarshall_nw
397c478bd9Sstevel@tonic-gate #define irp_unmarshall_pr __irp_unmarshall_pr
407c478bd9Sstevel@tonic-gate #define irp_unmarshall_pw __irp_unmarshall_pw
417c478bd9Sstevel@tonic-gate #define irp_unmarshall_sv __irp_unmarshall_sv
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #define MAXPADDRSIZE (sizeof "255.255.255.255" + 1)
447c478bd9Sstevel@tonic-gate #define ADDR_T_STR(x) (x == AF_INET ? "AF_INET" :\
457c478bd9Sstevel@tonic-gate 		       (x == AF_INET6 ? "AF_INET6" : "UNKNOWN"))
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /* See comment below on usage */
48*9525b14bSRao Shoaib int irp_marshall_pw(const struct passwd *, char **, size_t *);
49*9525b14bSRao Shoaib int irp_unmarshall_pw(struct passwd *, char *);
50*9525b14bSRao Shoaib int irp_marshall_gr(const struct group *, char **, size_t *);
51*9525b14bSRao Shoaib int irp_unmarshall_gr(struct group *, char *);
52*9525b14bSRao Shoaib int irp_marshall_sv(const struct servent *, char **, size_t *);
53*9525b14bSRao Shoaib int irp_unmarshall_sv(struct servent *, char *);
54*9525b14bSRao Shoaib int irp_marshall_pr(struct protoent *, char **, size_t *);
55*9525b14bSRao Shoaib int irp_unmarshall_pr(struct protoent *, char *);
56*9525b14bSRao Shoaib int irp_marshall_ho(struct hostent *, char **, size_t *);
57*9525b14bSRao Shoaib int irp_unmarshall_ho(struct hostent *, char *);
58*9525b14bSRao Shoaib int irp_marshall_ng(const char *, const char *, const char *,
59*9525b14bSRao Shoaib 		    char **, size_t *);
60*9525b14bSRao Shoaib int irp_unmarshall_ng(const char **, const char **, const char **, char *);
61*9525b14bSRao Shoaib int irp_marshall_nw(struct nwent *, char **, size_t *);
62*9525b14bSRao Shoaib int irp_unmarshall_nw(struct nwent *, char *);
63*9525b14bSRao Shoaib int irp_marshall_ne(struct netent *, char **, size_t *);
64*9525b14bSRao Shoaib int irp_unmarshall_ne(struct netent *, char *);
657c478bd9Sstevel@tonic-gate 
66*9525b14bSRao Shoaib /*! \file
67*9525b14bSRao Shoaib  * \brief
687c478bd9Sstevel@tonic-gate  * Functions to marshall and unmarshall various system data structures. We
697c478bd9Sstevel@tonic-gate  * use a printable ascii format that is as close to various system config
707c478bd9Sstevel@tonic-gate  * files as reasonable (e.g. /etc/passwd format).
717c478bd9Sstevel@tonic-gate  *
727c478bd9Sstevel@tonic-gate  * We are not forgiving with unmarhsalling misformatted buffers. In
737c478bd9Sstevel@tonic-gate  * particular whitespace in fields is not ignored. So a formatted password
747c478bd9Sstevel@tonic-gate  * entry "brister  :1364:100:...." will yield a username of "brister   "
757c478bd9Sstevel@tonic-gate  *
767c478bd9Sstevel@tonic-gate  * We potentially do a lot of mallocs to fill fields that are of type
777c478bd9Sstevel@tonic-gate  * (char **) like a hostent h_addr field. Building (for example) the
787c478bd9Sstevel@tonic-gate  * h_addr field and its associated addresses all in one buffer is
797c478bd9Sstevel@tonic-gate  * certainly possible, but not done here.
807c478bd9Sstevel@tonic-gate  *
817c478bd9Sstevel@tonic-gate  * The following description is true for all the marshalling functions:
827c478bd9Sstevel@tonic-gate  *
83*9525b14bSRao Shoaib  * int irp_marshall_XX(struct yyyy *XX, char **buffer, size_t *len);
847c478bd9Sstevel@tonic-gate  *
857c478bd9Sstevel@tonic-gate  * The argument XX (of type struct passwd for example) is marshalled in the
867c478bd9Sstevel@tonic-gate  * buffer pointed at by *BUFFER, which is of length *LEN. Returns 0
877c478bd9Sstevel@tonic-gate  * on success and -1 on failure. Failure will occur if *LEN is
887c478bd9Sstevel@tonic-gate  * smaller than needed.
897c478bd9Sstevel@tonic-gate  *
907c478bd9Sstevel@tonic-gate  * If BUFFER is NULL, then *LEN is set to the size of the buffer
917c478bd9Sstevel@tonic-gate  * needed to marshall the data and no marshalling is actually done.
927c478bd9Sstevel@tonic-gate  *
937c478bd9Sstevel@tonic-gate  * If *BUFFER is NULL, then a buffer large enough will be allocated
947c478bd9Sstevel@tonic-gate  * with memget() and the size allocated will be stored in *LEN. An extra 2
957c478bd9Sstevel@tonic-gate  * bytes will be allocated for the client to append CRLF if wanted. The
967c478bd9Sstevel@tonic-gate  * value of *LEN will include these two bytes.
977c478bd9Sstevel@tonic-gate  *
987c478bd9Sstevel@tonic-gate  * All the marshalling functions produce a buffer with the fields
997c478bd9Sstevel@tonic-gate  * separated by colons (except for the hostent marshalling, which uses '@'
1007c478bd9Sstevel@tonic-gate  * to separate fields). Fields that have multiple subfields (like the
1017c478bd9Sstevel@tonic-gate  * gr_mem field in struct group) have their subparts separated by
1027c478bd9Sstevel@tonic-gate  * commas.
103*9525b14bSRao Shoaib  *
1047c478bd9Sstevel@tonic-gate  * int irp_unmarshall_XX(struct YYYYY *XX, char *buffer);
1057c478bd9Sstevel@tonic-gate  *
1067c478bd9Sstevel@tonic-gate  * The unmashalling functions break apart the buffer and store the
1077c478bd9Sstevel@tonic-gate  * values in the struct pointed to by XX. All pointer values inside
1087c478bd9Sstevel@tonic-gate  * XX are allocated with malloc. All arrays of pointers have a NULL
1097c478bd9Sstevel@tonic-gate  * as the last element.
1107c478bd9Sstevel@tonic-gate  */
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate #endif
113