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