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.
30 #include <mach/mach.h>
33 #include <rpc/types.h>
38 #include "_lu_types.h"
40 #include "lu_overrides.h"
42 static lookup_state alias_state
= LOOKUP_CACHE
;
43 static struct aliasent global_aliasent
;
44 static int global_free
= 1;
45 static char *alias_data
= NULL
;
46 static unsigned alias_datalen
;
47 static int alias_nentries
= 0;
48 static int alias_start
= 1;
56 if (global_free
== 1) return;
58 free(global_aliasent
.alias_name
);
60 len
= global_aliasent
.alias_members_len
;
61 for (i
= 0; i
< len
; i
++)
62 free(global_aliasent
.alias_members
[i
]);
64 free(global_aliasent
.alias_members
);
70 convert_aliasent(_lu_aliasent
*lu_aliasent
)
76 global_aliasent
.alias_name
= strdup(lu_aliasent
->alias_name
);
78 len
= lu_aliasent
->alias_members
.alias_members_len
;
79 global_aliasent
.alias_members_len
= len
;
80 global_aliasent
.alias_members
= (char **)malloc(len
* sizeof(char *));
82 for (i
= 0; i
< len
; i
++)
84 global_aliasent
.alias_members
[i
] =
85 strdup(lu_aliasent
->alias_members
.alias_members_val
[i
]);
88 global_aliasent
.alias_local
= lu_aliasent
->alias_local
;
93 static struct aliasent
*
94 lu_alias_getbyname(const char *name
)
97 char namebuf
[_LU_MAXLUSTRLEN
+ BYTES_PER_XDR_UNIT
];
98 unit lookup_buf
[MAX_INLINE_UNITS
];
101 _lu_aliasent_ptr lu_aliasent
;
102 static int proc
= -1;
106 if (_lookup_link(_lu_port
, "alias_getbyname", &proc
) != KERN_SUCCESS
)
112 xdrmem_create(&outxdr
, namebuf
, sizeof(namebuf
), XDR_ENCODE
);
113 if (!xdr__lu_string(&outxdr
, &name
))
115 xdr_destroy(&outxdr
);
119 datalen
= MAX_INLINE_UNITS
;
120 if (_lookup_one(_lu_port
, proc
, (unit
*)namebuf
,
121 xdr_getpos(&outxdr
) / BYTES_PER_XDR_UNIT
, lookup_buf
, &datalen
)
124 xdr_destroy(&outxdr
);
128 xdr_destroy(&outxdr
);
130 datalen
*= BYTES_PER_XDR_UNIT
;
131 xdrmem_create(&inxdr
, lookup_buf
, datalen
,
134 if (!xdr__lu_aliasent_ptr(&inxdr
, &lu_aliasent
) || (lu_aliasent
== NULL
))
142 convert_aliasent(lu_aliasent
);
143 xdr_free(xdr__lu_aliasent_ptr
, &lu_aliasent
);
144 return (&global_aliasent
);
148 lu_alias_endent(void)
151 if (alias_data
!= NULL
)
154 vm_deallocate(mach_task_self(), (vm_address_t
)alias_data
, alias_datalen
);
160 lu_alias_setent(void)
166 static struct aliasent
*
167 lu_alias_getent(void)
169 static int proc
= -1;
170 _lu_aliasent lu_aliasent
;
172 if (alias_start
== 1)
178 if (_lookup_link(_lu_port
, "alias_getent", &proc
) != KERN_SUCCESS
)
185 if (_lookup_all(_lu_port
, proc
, NULL
, 0, &alias_data
, &alias_datalen
)
193 /* NOTDEF because OOL buffers are counted in bytes with untyped IPC */
194 alias_datalen
*= BYTES_PER_XDR_UNIT
;
196 xdrmem_create(&alias_xdr
, alias_data
,
197 alias_datalen
, XDR_DECODE
);
198 if (!xdr_int(&alias_xdr
, &alias_nentries
))
200 xdr_destroy(&alias_xdr
);
206 if (alias_nentries
== 0)
208 xdr_destroy(&alias_xdr
);
213 bzero(&lu_aliasent
, sizeof(lu_aliasent
));
214 if (!xdr__lu_aliasent(&alias_xdr
, &lu_aliasent
))
216 xdr_destroy(&alias_xdr
);
222 convert_aliasent(&lu_aliasent
);
223 xdr_free(xdr__lu_aliasent
, &lu_aliasent
);
224 return (&global_aliasent
);
228 alias_getbyname(const char *name
)
230 LOOKUP1(lu_alias_getbyname
, _old_alias_getbyname
, name
, struct aliasent
);
236 GETENT(lu_alias_getent
, _old_alias_getent
, &alias_state
, struct aliasent
);
242 SETSTATEVOID(lu_alias_setent
, _old_alias_setent
, &alias_state
);
248 UNSETSTATE(lu_alias_endent
, _old_alias_endent
, &alias_state
);