]>
sourceware.org Git - glibc.git/blob - nis/nss_nisplus/nisplus-grp.c
1 /* Copyright (C) 1997 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
25 #include <bits/libc-lock.h>
26 #include <rpcsvc/nis.h>
27 #include <rpcsvc/nislib.h>
29 #include "nss-nisplus.h"
30 #include "nisplus-parser.h"
32 __libc_lock_define_initialized (static, lock
);
34 static nis_result
*result
= NULL
;
35 static unsigned long next_entry
= 0;
36 static nis_name tablename_val
= NULL
;
37 static u_long tablename_len
= 0;
39 static enum nss_status
40 _nss_create_tablename (void)
42 if (tablename_val
== NULL
)
44 char buf
[40 + strlen (nis_local_directory ())];
47 p
= stpcpy (buf
, "group.org_dir.");
48 p
= stpcpy (p
, nis_local_directory ());
49 tablename_val
= strdup (buf
);
50 if (tablename_val
== NULL
)
51 return NSS_STATUS_TRYAGAIN
;
52 tablename_len
= strlen (tablename_val
);
54 return NSS_STATUS_SUCCESS
;
57 static enum nss_status
58 internal_setgrent (void)
61 nis_freeresult (result
);
65 if (tablename_val
== NULL
)
66 if (_nss_create_tablename () != NSS_STATUS_SUCCESS
)
67 return NSS_STATUS_UNAVAIL
;
69 result
= nis_list (tablename_val
, FOLLOW_LINKS
| FOLLOW_PATH
, NULL
, NULL
);
70 if (niserr2nss (result
->status
) != NSS_STATUS_SUCCESS
)
72 nis_freeresult (result
);
75 return niserr2nss (result
->status
);
79 _nss_nisplus_setgrent (void)
81 enum nss_status status
;
83 __libc_lock_lock (lock
);
85 status
= internal_setgrent ();
87 __libc_lock_unlock (lock
);
93 _nss_nisplus_endgrent (void)
95 __libc_lock_lock (lock
);
98 nis_freeresult (result
);
101 __libc_lock_unlock (lock
);
103 return NSS_STATUS_SUCCESS
;
106 static enum nss_status
107 internal_nisplus_getgrent_r (struct group
*gr
, char *buffer
, size_t buflen
)
112 internal_setgrent ();
114 /* Get the next entry until we found a correct one. */
117 if (next_entry
>= result
->objects
.objects_len
)
118 return NSS_STATUS_NOTFOUND
;
120 if ((parse_res
= _nss_nisplus_parse_grent (result
, next_entry
, gr
,
121 buffer
, buflen
)) == -1)
122 return NSS_STATUS_TRYAGAIN
;
128 return NSS_STATUS_SUCCESS
;
132 _nss_nisplus_getgrent_r (struct group
*result
, char *buffer
, size_t buflen
)
136 __libc_lock_lock (lock
);
138 status
= internal_nisplus_getgrent_r (result
, buffer
, buflen
);
140 __libc_lock_unlock (lock
);
146 _nss_nisplus_getgrnam_r (const char *name
, struct group
*gr
,
147 char *buffer
, size_t buflen
)
151 if (tablename_val
== NULL
)
152 if (_nss_create_tablename() != NSS_STATUS_SUCCESS
)
153 return NSS_STATUS_UNAVAIL
;
155 if (name
== NULL
|| strlen (name
) > 8)
156 return NSS_STATUS_NOTFOUND
;
160 char buf
[strlen (name
) + 24 + tablename_len
];
162 sprintf (buf
, "[name=%s],%s", name
, tablename_val
);
164 result
= nis_list (buf
, FOLLOW_LINKS
| FOLLOW_PATH
, NULL
, NULL
);
166 if (niserr2nss (result
->status
) != NSS_STATUS_SUCCESS
)
168 enum nss_status status
= niserr2nss (result
->status
);
170 nis_freeresult (result
);
174 parse_res
= _nss_nisplus_parse_grent (result
, 0, gr
, buffer
, buflen
);
175 nis_freeresult (result
);
178 return NSS_STATUS_TRYAGAIN
;
180 return NSS_STATUS_SUCCESS
;
182 return NSS_STATUS_NOTFOUND
;
187 _nss_nisplus_getgrgid_r (const gid_t gid
, struct group
*gr
,
188 char *buffer
, size_t buflen
)
190 if (tablename_val
== NULL
)
191 if (_nss_create_tablename() != NSS_STATUS_SUCCESS
)
192 return NSS_STATUS_UNAVAIL
;
197 char buf
[36 + tablename_len
];
199 sprintf (buf
, "[gid=%d],%s", gid
, tablename_val
);
201 result
= nis_list (buf
, FOLLOW_PATH
| FOLLOW_LINKS
, NULL
, NULL
);
203 if (niserr2nss (result
->status
) != NSS_STATUS_SUCCESS
)
205 enum nss_status status
= niserr2nss (result
->status
);
207 nis_freeresult (result
);
211 parse_res
= _nss_nisplus_parse_grent (result
, 0, gr
, buffer
, buflen
);
213 nis_freeresult (result
);
216 return NSS_STATUS_TRYAGAIN
;
219 return NSS_STATUS_SUCCESS
;
221 return NSS_STATUS_NOTFOUND
;
This page took 0.045876 seconds and 5 git commands to generate.