Print this page
remove support for non-ANSI compilation


   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*


  22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  *
  25  * Database-specific definitions for the getXXXbyYYY routines
  26  * (e.g getpwuid_r(), ether_ntohost()) that use the name-service switch.
  27  * Database-independent definitions are in <nss_common.h>
  28  *
  29  * Ideally, this is the only switch header file one would add things
  30  * to in order to support a new database.
  31  *
  32  * NOTE:  The interfaces documented in this file may change in a minor
  33  *        release.  It is intended that in the future a stronger committment
  34  *        will be made to these interface definitions which will guarantee
  35  *        them across minor releases.
  36  */
  37 
  38 #ifndef _NSS_DBDEFS_H
  39 #define _NSS_DBDEFS_H
  40 
  41 #include <sys/types.h>


 217  * Default cache door buffer size (2x largest buffer)
 218  */
 219 
 220 #define NSS_BUFLEN_DOOR         ((NSS_BUFSIZ) * 16)
 221 
 222 /*
 223  * Arguments and results, passed between the frontends and backends for
 224  * the well-known databases.  The getXbyY_r() and getXent_r() routines
 225  * use a common format that is further described below;  other routines
 226  * use their own formats.
 227  */
 228 
 229 /*
 230  * The nss_str2ent_t routine is the data marshaller for the nsswitch.
 231  * it converts 'native files' format into 'entry' format as part of the
 232  * return processing for a getXbyY interface.
 233  *
 234  * The nss_groupstr_t routine does the real work for any backend
 235  * that can supply a netgroup entry as a string in /etc/group format
 236  */
 237 #if defined(__STDC__)
 238 typedef int             (*nss_str2ent_t)(const char *in, int inlen,
 239                                 void *ent, char *buf, int buflen);
 240 
 241 struct nss_groupsbymem;         /* forward definition */
 242 typedef nss_status_t    (*nss_groupstr_t)(const char *instr, int inlen,
 243                                 struct nss_groupsbymem *);
 244 #else
 245 typedef int             (*nss_str2ent_t)();
 246 typedef nss_status_t    (*nss_groupstr_t)();
 247 #endif
 248 
 249 /*
 250  * The initgroups() function [see initgroups(3c)] needs to find all the
 251  *   groups to which a given user belongs.  To do this it calls
 252  *   _getgroupsbymember(), which is part of the frontend for the "group"
 253  *   database.
 254  * We want the same effect as if we used getgrent_r() to enumerate the
 255  *   entire groups database (possibly from multiple sources), but getgrent_r()
 256  *   is too inefficient.  Most backends can do better if they know they're
 257  *   meant to scan all groups;  hence there's a separate backend operation,
 258  *   NSS_DBOP_GROUP_BYMEMBER, which uses the nss_groupsbymem struct.
 259  * Note that the normal return-value from such a backend, even when it
 260  *   successfully finds matching group entries, is NSS_NOTFOUND, because
 261  *   this tells the switch engine to keep searching in any more sources.
 262  *   In fact, the backends only return NSS_SUCCESS if they find enough
 263  *   matching entries that the gid_array is completely filled, in which
 264  *   case the switch engine should stop searching.
 265  * If the force_slow_way field is set, the backend should eschew any cached
 266  *   information (e.g. the YP netid.byname map or the NIS+ cred.org_dir table)
 267  *   and should instead grind its way through the group map/table/whatever.


 359         struct nss_innetgr_1arg groups;
 360 /* out: */
 361         enum nss_netgr_status   status;
 362 };
 363 
 364 /*
 365  * nss_XbyY_buf_t -- structure containing the generic arguments passwd to
 366  *   getXXXbyYYY_r() and getXXXent_r() routines.  The (void *) value points to
 367  *   a struct of the appropriate type, e.g. struct passwd or struct hostent.
 368  *
 369  * The functions that allocate and free these structures do no locking at
 370  * all, since the routines that use them are inherently MT-unsafe anyway.
 371  */
 372 
 373 typedef struct {
 374         void            *result;        /* "result" parameter to getXbyY_r() */
 375         char            *buffer;        /* "buffer"     "             "      */
 376         int             buflen;         /* "buflen"     "             "      */
 377 } nss_XbyY_buf_t;
 378 
 379 #if defined(__STDC__)
 380 extern nss_XbyY_buf_t   *_nss_XbyY_buf_alloc(int struct_size, int buffer_size);
 381 extern void              _nss_XbyY_buf_free(nss_XbyY_buf_t *);
 382 #else
 383 extern nss_XbyY_buf_t   *_nss_XbyY_buf_alloc();
 384 extern void              _nss_XbyY_buf_free();
 385 #endif
 386 
 387 #define NSS_XbyY_ALLOC(bufpp, str_size, buf_size)               (\
 388         (*bufpp) == 0                                           \
 389         ? (*bufpp) = _nss_XbyY_buf_alloc(str_size, buf_size)    \
 390         : (*bufpp))
 391 
 392 #define NSS_XbyY_FREE(bufpp)    (_nss_XbyY_buf_free(*bufpp), (*bufpp) = 0)
 393 
 394 /*
 395  * The nss_XbyY_args_t struct contains all the information passed between
 396  * frontends and backends for the getXbyY_r() and getXent() routines,
 397  * including an nss_XbyY_buf_t and the lookup key (unused for getXXXent_r).
 398  *
 399  * The (*str2ent)() member converts a single XXXent from ASCII text to the
 400  * appropriate struct, storing any pointer data (strings, in_addrs, arrays
 401  * of these) in the buffer.  The ASCII text is a counted string (*not* a
 402  * zero-terminated string) whose length is specified by the instr_len
 403  * parameter.  The text is found at the address specified by instr and
 404  * the string is treated as readonly. buffer and instr must be non-
 405  * intersecting memory areas.


 436                 union {
 437                         const char      *name;
 438                         int             port;
 439                 }               serv;
 440                 const char      *proto;
 441         }       serv;
 442         void *ether;
 443         struct {
 444                 const char      *name;
 445                 const char      *keytype;
 446         } pkey;
 447         struct {
 448                 const char      *name;
 449                 int             af_family;
 450                 int             flags;
 451         }       ipnode;
 452         void *attrp;    /* for the new attr databases */
 453 } nss_XbyY_key_t;
 454 
 455 
 456 #if defined(__STDC__)
 457 typedef int             (*nss_key2str_t)(void *buffer, size_t buflen,
 458                                 nss_XbyY_key_t *key, size_t *len);
 459 #else
 460 typedef int             (*nss_key2str_t)();
 461 #endif
 462 
 463 
 464 typedef struct nss_XbyY_args {
 465 
 466 /* IN */
 467         nss_XbyY_buf_t  buf;
 468         int             stayopen;
 469                         /*
 470                          * Support for setXXXent(stayopen)
 471                          * Used only in hosts, protocols,
 472                          * networks, rpc, and services.
 473                          */
 474         nss_str2ent_t   str2ent;
 475         union nss_XbyY_key key;
 476 
 477 /* OUT */
 478         void            *returnval;
 479         int             erange;
 480         int             h_errno;        /* For gethost*_r() */
 481         nss_status_t    status;         /* from the backend last called */


 672 #define NSS_XbyY_INIT_EXT(str, res, bufp, len, func, kfunc)     (\
 673         (str)->buf.result = (res),                   \
 674         (str)->buf.buffer = (bufp),                  \
 675         (str)->buf.buflen = (len),                   \
 676         (str)->stayopen  = 0,                                \
 677         (str)->str2ent  = (func),                    \
 678         (str)->key2str  = (kfunc),                   \
 679         (str)->returnval = 0,                                \
 680         (str)->returnlen = 0,                                \
 681         (str)->h_errno    = 0,                               \
 682         (str)->erange    = 0)
 683 
 684 #define NSS_XbyY_FINI(str)                              (\
 685         (str)->returnval == 0 && (str)->erange && (errno = ERANGE), \
 686         (str)->returnval)
 687 
 688 #define NSS_PACKED_CRED_CHECK(buf, ruid, euid)          (\
 689         ((nss_pheader_t *)(buf))->p_ruid == (ruid) && \
 690         ((nss_pheader_t *)(buf))->p_euid == (euid))
 691 
 692 #if defined(__STDC__)
 693 extern char             **_nss_netdb_aliases(const char *, int, char *, int);
 694 extern nss_status_t     nss_default_key2str(void *, size_t, nss_XbyY_args_t *,
 695                                         const char *, int, size_t *);
 696 extern nss_status_t     nss_packed_arg_init(void *, size_t, nss_db_root_t *,
 697                                         nss_db_initf_t *, int *,
 698                                         nss_XbyY_args_t *);
 699 extern nss_status_t     nss_packed_context_init(void *, size_t, nss_db_root_t *,
 700                                         nss_db_initf_t *, nss_getent_t **,
 701                                         nss_XbyY_args_t *);
 702 extern void             nss_packed_set_status(void *, size_t, nss_status_t,
 703                                         nss_XbyY_args_t *);
 704 extern nss_status_t     nss_packed_getkey(void *, size_t, char **, int *,
 705                                         nss_XbyY_args_t *);
 706 #else
 707 extern char             **_nss_netdb_aliases();
 708 extern int              nss_default_key2str();
 709 extern nss_status_t     nss_packed_arg_init();
 710 extern nss_status_t     nss_packed_context_init();
 711 extern void             nss_packed_set_status();
 712 extern nss_status_t     nss_packed_getkey();
 713 #endif
 714 
 715 /*
 716  * nss_dbop_t values for searches with various keys;  values for
 717  * destructor/endent/setent/getent are defined in <nss_common.h>
 718  */
 719 
 720 /*
 721  * These are part of the "Over the wire" IE app->nscd getXbyY
 722  * op for well known getXbyY's.  Cannot use NSS_DBOP_X_Y directly
 723  * because NSS_DBOP_next_iter is NOT an incrementing counter value
 724  * it's a starting offset into an array value.
 725  */
 726 
 727 #define NSS_DBOP_X(x)                   ((x)<<16)
 728 #define NSS_DBOP_XY(x, y)               ((x)|(y))
 729 
 730 #define NSS_DBOP_ALIASES        NSS_DBOP_X(1)
 731 #define NSS_DBOP_AUTOMOUNT      NSS_DBOP_X(2)
 732 #define NSS_DBOP_BOOTPARAMS     NSS_DBOP_X(3)
 733 #define NSS_DBOP_ETHERS         NSS_DBOP_X(4)




   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
  23  *
  24  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  25  * Use is subject to license terms.
  26  *
  27  * Database-specific definitions for the getXXXbyYYY routines
  28  * (e.g getpwuid_r(), ether_ntohost()) that use the name-service switch.
  29  * Database-independent definitions are in <nss_common.h>
  30  *
  31  * Ideally, this is the only switch header file one would add things
  32  * to in order to support a new database.
  33  *
  34  * NOTE:  The interfaces documented in this file may change in a minor
  35  *        release.  It is intended that in the future a stronger committment
  36  *        will be made to these interface definitions which will guarantee
  37  *        them across minor releases.
  38  */
  39 
  40 #ifndef _NSS_DBDEFS_H
  41 #define _NSS_DBDEFS_H
  42 
  43 #include <sys/types.h>


 219  * Default cache door buffer size (2x largest buffer)
 220  */
 221 
 222 #define NSS_BUFLEN_DOOR         ((NSS_BUFSIZ) * 16)
 223 
 224 /*
 225  * Arguments and results, passed between the frontends and backends for
 226  * the well-known databases.  The getXbyY_r() and getXent_r() routines
 227  * use a common format that is further described below;  other routines
 228  * use their own formats.
 229  */
 230 
 231 /*
 232  * The nss_str2ent_t routine is the data marshaller for the nsswitch.
 233  * it converts 'native files' format into 'entry' format as part of the
 234  * return processing for a getXbyY interface.
 235  *
 236  * The nss_groupstr_t routine does the real work for any backend
 237  * that can supply a netgroup entry as a string in /etc/group format
 238  */

 239 typedef int             (*nss_str2ent_t)(const char *in, int inlen,
 240                                 void *ent, char *buf, int buflen);
 241 
 242 struct nss_groupsbymem;         /* forward definition */
 243 typedef nss_status_t    (*nss_groupstr_t)(const char *instr, int inlen,
 244                                 struct nss_groupsbymem *);




 245 
 246 /*
 247  * The initgroups() function [see initgroups(3c)] needs to find all the
 248  *   groups to which a given user belongs.  To do this it calls
 249  *   _getgroupsbymember(), which is part of the frontend for the "group"
 250  *   database.
 251  * We want the same effect as if we used getgrent_r() to enumerate the
 252  *   entire groups database (possibly from multiple sources), but getgrent_r()
 253  *   is too inefficient.  Most backends can do better if they know they're
 254  *   meant to scan all groups;  hence there's a separate backend operation,
 255  *   NSS_DBOP_GROUP_BYMEMBER, which uses the nss_groupsbymem struct.
 256  * Note that the normal return-value from such a backend, even when it
 257  *   successfully finds matching group entries, is NSS_NOTFOUND, because
 258  *   this tells the switch engine to keep searching in any more sources.
 259  *   In fact, the backends only return NSS_SUCCESS if they find enough
 260  *   matching entries that the gid_array is completely filled, in which
 261  *   case the switch engine should stop searching.
 262  * If the force_slow_way field is set, the backend should eschew any cached
 263  *   information (e.g. the YP netid.byname map or the NIS+ cred.org_dir table)
 264  *   and should instead grind its way through the group map/table/whatever.


 356         struct nss_innetgr_1arg groups;
 357 /* out: */
 358         enum nss_netgr_status   status;
 359 };
 360 
 361 /*
 362  * nss_XbyY_buf_t -- structure containing the generic arguments passwd to
 363  *   getXXXbyYYY_r() and getXXXent_r() routines.  The (void *) value points to
 364  *   a struct of the appropriate type, e.g. struct passwd or struct hostent.
 365  *
 366  * The functions that allocate and free these structures do no locking at
 367  * all, since the routines that use them are inherently MT-unsafe anyway.
 368  */
 369 
 370 typedef struct {
 371         void            *result;        /* "result" parameter to getXbyY_r() */
 372         char            *buffer;        /* "buffer"     "             "      */
 373         int             buflen;         /* "buflen"     "             "      */
 374 } nss_XbyY_buf_t;
 375 

 376 extern nss_XbyY_buf_t   *_nss_XbyY_buf_alloc(int struct_size, int buffer_size);
 377 extern void              _nss_XbyY_buf_free(nss_XbyY_buf_t *);




 378 
 379 #define NSS_XbyY_ALLOC(bufpp, str_size, buf_size)               (\
 380         (*bufpp) == 0                                           \
 381         ? (*bufpp) = _nss_XbyY_buf_alloc(str_size, buf_size)    \
 382         : (*bufpp))
 383 
 384 #define NSS_XbyY_FREE(bufpp)    (_nss_XbyY_buf_free(*bufpp), (*bufpp) = 0)
 385 
 386 /*
 387  * The nss_XbyY_args_t struct contains all the information passed between
 388  * frontends and backends for the getXbyY_r() and getXent() routines,
 389  * including an nss_XbyY_buf_t and the lookup key (unused for getXXXent_r).
 390  *
 391  * The (*str2ent)() member converts a single XXXent from ASCII text to the
 392  * appropriate struct, storing any pointer data (strings, in_addrs, arrays
 393  * of these) in the buffer.  The ASCII text is a counted string (*not* a
 394  * zero-terminated string) whose length is specified by the instr_len
 395  * parameter.  The text is found at the address specified by instr and
 396  * the string is treated as readonly. buffer and instr must be non-
 397  * intersecting memory areas.


 428                 union {
 429                         const char      *name;
 430                         int             port;
 431                 }               serv;
 432                 const char      *proto;
 433         }       serv;
 434         void *ether;
 435         struct {
 436                 const char      *name;
 437                 const char      *keytype;
 438         } pkey;
 439         struct {
 440                 const char      *name;
 441                 int             af_family;
 442                 int             flags;
 443         }       ipnode;
 444         void *attrp;    /* for the new attr databases */
 445 } nss_XbyY_key_t;
 446 
 447 

 448 typedef int             (*nss_key2str_t)(void *buffer, size_t buflen,
 449                                 nss_XbyY_key_t *key, size_t *len);



 450 
 451 
 452 typedef struct nss_XbyY_args {
 453 
 454 /* IN */
 455         nss_XbyY_buf_t  buf;
 456         int             stayopen;
 457                         /*
 458                          * Support for setXXXent(stayopen)
 459                          * Used only in hosts, protocols,
 460                          * networks, rpc, and services.
 461                          */
 462         nss_str2ent_t   str2ent;
 463         union nss_XbyY_key key;
 464 
 465 /* OUT */
 466         void            *returnval;
 467         int             erange;
 468         int             h_errno;        /* For gethost*_r() */
 469         nss_status_t    status;         /* from the backend last called */


 660 #define NSS_XbyY_INIT_EXT(str, res, bufp, len, func, kfunc)     (\
 661         (str)->buf.result = (res),                   \
 662         (str)->buf.buffer = (bufp),                  \
 663         (str)->buf.buflen = (len),                   \
 664         (str)->stayopen  = 0,                                \
 665         (str)->str2ent  = (func),                    \
 666         (str)->key2str  = (kfunc),                   \
 667         (str)->returnval = 0,                                \
 668         (str)->returnlen = 0,                                \
 669         (str)->h_errno    = 0,                               \
 670         (str)->erange    = 0)
 671 
 672 #define NSS_XbyY_FINI(str)                              (\
 673         (str)->returnval == 0 && (str)->erange && (errno = ERANGE), \
 674         (str)->returnval)
 675 
 676 #define NSS_PACKED_CRED_CHECK(buf, ruid, euid)          (\
 677         ((nss_pheader_t *)(buf))->p_ruid == (ruid) && \
 678         ((nss_pheader_t *)(buf))->p_euid == (euid))
 679 

 680 extern char             **_nss_netdb_aliases(const char *, int, char *, int);
 681 extern nss_status_t     nss_default_key2str(void *, size_t, nss_XbyY_args_t *,
 682                                         const char *, int, size_t *);
 683 extern nss_status_t     nss_packed_arg_init(void *, size_t, nss_db_root_t *,
 684                                         nss_db_initf_t *, int *,
 685                                         nss_XbyY_args_t *);
 686 extern nss_status_t     nss_packed_context_init(void *, size_t, nss_db_root_t *,
 687                                         nss_db_initf_t *, nss_getent_t **,
 688                                         nss_XbyY_args_t *);
 689 extern void             nss_packed_set_status(void *, size_t, nss_status_t,
 690                                         nss_XbyY_args_t *);
 691 extern nss_status_t     nss_packed_getkey(void *, size_t, char **, int *,
 692                                         nss_XbyY_args_t *);








 693 
 694 /*
 695  * nss_dbop_t values for searches with various keys;  values for
 696  * destructor/endent/setent/getent are defined in <nss_common.h>
 697  */
 698 
 699 /*
 700  * These are part of the "Over the wire" IE app->nscd getXbyY
 701  * op for well known getXbyY's.  Cannot use NSS_DBOP_X_Y directly
 702  * because NSS_DBOP_next_iter is NOT an incrementing counter value
 703  * it's a starting offset into an array value.
 704  */
 705 
 706 #define NSS_DBOP_X(x)                   ((x)<<16)
 707 #define NSS_DBOP_XY(x, y)               ((x)|(y))
 708 
 709 #define NSS_DBOP_ALIASES        NSS_DBOP_X(1)
 710 #define NSS_DBOP_AUTOMOUNT      NSS_DBOP_X(2)
 711 #define NSS_DBOP_BOOTPARAMS     NSS_DBOP_X(3)
 712 #define NSS_DBOP_ETHERS         NSS_DBOP_X(4)