]>
git.saurik.com Git - apple/libinfo.git/blob - lookup.subproj/lu_netgroup.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
26 * Copyright (C) 1989 by NeXT, Inc.
29 #include <mach/mach.h>
33 #include <rpc/types.h>
36 #include "_lu_types.h"
39 #include "lu_overrides.h"
41 #define FIX(x) ((x == NULL) ? NULL : &(x))
43 static struct netgrent global_netgr
;
44 static int global_free
= 1;
45 static char *netgr_data
= NULL
;
46 static unsigned netgr_datalen
;
47 static int netgr_nentries
= 0;
48 static int netgr_start
= 1;
54 if (global_free
== 1) return;
56 free(global_netgr
.ng_host
);
57 free(global_netgr
.ng_user
);
58 free(global_netgr
.ng_domain
);
64 convert_netgr(_lu_netgrent
*lu_netgr
)
68 global_netgr
.ng_host
= strdup(lu_netgr
->ng_host
);
69 global_netgr
.ng_user
= strdup(lu_netgr
->ng_user
);
70 global_netgr
.ng_domain
= strdup(lu_netgr
->ng_domain
);
77 lu_innetgr(const char *group
, const char *host
, const char *user
,
82 char namebuf
[4*_LU_MAXLUSTRLEN
+ 3*BYTES_PER_XDR_UNIT
];
86 _lu_innetgr_args args
;
87 unit lookup_buf
[MAX_INLINE_UNITS
];
91 if (_lookup_link(_lu_port
, "innetgr", &proc
) != KERN_SUCCESS
)
97 args
.group
= (char *)group
;
98 args
.host
= FIX(host
);
99 args
.user
= FIX(user
);
100 args
.domain
= FIX(domain
);
102 xdrmem_create(&xdr
, namebuf
, sizeof(namebuf
), XDR_ENCODE
);
103 if (!xdr__lu_innetgr_args(&xdr
, &args
))
109 size
= xdr_getpos(&xdr
) / BYTES_PER_XDR_UNIT
;
112 datalen
= MAX_INLINE_UNITS
;
113 if (_lookup_one(_lu_port
, proc
, (unit
*)namebuf
, size
, lookup_buf
,
114 &datalen
) != KERN_SUCCESS
)
119 datalen
*= BYTES_PER_XDR_UNIT
;
120 xdrmem_create(&xdr
, lookup_buf
, datalen
, XDR_DECODE
);
121 if (!xdr_int(&xdr
, &res
))
135 if (netgr_data
!= NULL
)
138 vm_deallocate(mach_task_self(), (vm_address_t
)netgr_data
, netgr_datalen
);
144 * This is different than the other setXXXent routines
145 * since this is really more like getnetgrbyname() than
149 lu_setnetgrent(const char *group
)
152 char namebuf
[_LU_MAXLUSTRLEN
+ BYTES_PER_XDR_UNIT
];
154 static int proc
= -1;
160 if (_lookup_link(_lu_port
, "getnetgrent", &proc
) != KERN_SUCCESS
)
167 xdrmem_create(&outxdr
, namebuf
, sizeof(namebuf
), XDR_ENCODE
);
168 if (!xdr__lu_string(&outxdr
, &group
))
170 xdr_destroy(&outxdr
);
175 datalen
= MAX_INLINE_UNITS
;
176 if (_lookup_all(_lu_port
, proc
, (unit
*)namebuf
,
177 xdr_getpos(&outxdr
) / BYTES_PER_XDR_UNIT
,
178 &netgr_data
, &netgr_datalen
) != KERN_SUCCESS
)
180 xdr_destroy(&outxdr
);
185 xdr_destroy(&outxdr
);
188 /* NOTDEF because OOL buffers are counted in bytes with untyped IPC */
189 netgr_datalen
*= BYTES_PER_XDR_UNIT
;
192 xdrmem_create(&netgr_xdr
, netgr_data
,
193 netgr_datalen
, XDR_DECODE
);
194 if (!xdr_int(&netgr_xdr
, &netgr_nentries
))
196 xdr_destroy(&netgr_xdr
);
205 _lu_netgrent lu_netgr
;
207 if (netgr_nentries
== 0)
209 xdr_destroy(&netgr_xdr
);
214 bzero(&lu_netgr
, sizeof(lu_netgr
));
215 if (!xdr__lu_netgrent(&netgr_xdr
, &lu_netgr
))
217 xdr_destroy(&netgr_xdr
);
223 convert_netgr(&lu_netgr
);
224 xdr_free(xdr__lu_netgrent
, &lu_netgr
);
225 return (&global_netgr
);
229 innetgr(const char *group
, const char *host
, const char *user
,
232 if (_lu_running()) return (lu_innetgr(group
, host
, user
, domain
));
233 // return (_old_innetgr(group, host, user, domain));
240 if (_lu_running()) return (lu_getnetgrent());
241 // return (_old_getnetgrent());
246 setnetgrent(const char *group
)
248 if (_lu_running()) lu_setnetgrent(group
);
249 // else _old_setnetgrent(group);
255 if (_lu_running()) lu_endnetgrent();
256 // else _old_endnetgrent();