1 /* Copyright (c) 1997-2021 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 Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the 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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
23 #include <rpcsvc/nis.h>
24 #include <shlib-compat.h>
27 nis_local_group (void)
29 static char __nisgroup
[NIS_MAXNAMELEN
+ 1];
32 if (__nisgroup
[0] == '\0'
33 && (cptr
= getenv ("NIS_GROUP")) != NULL
35 && strlen (cptr
) < NIS_MAXNAMELEN
)
37 char *cp
= stpcpy (__nisgroup
, cptr
);
41 cptr
= nis_local_directory ();
42 if ((cp
- __nisgroup
) + strlen (cptr
) + 1 < NIS_MAXNAMELEN
)
54 libnsl_hidden_nolink_def (nis_local_group
, GLIBC_2_1
)
57 nis_local_directory (void)
59 static char __nisdomainname
[NIS_MAXNAMELEN
+ 1];
61 if (__nisdomainname
[0] == '\0')
63 if (getdomainname (__nisdomainname
, NIS_MAXNAMELEN
) < 0)
64 __nisdomainname
[0] = '\0';
67 char *cp
= rawmemchr (__nisdomainname
, '\0');
69 /* Missing trailing dot? */
78 return __nisdomainname
;
80 libnsl_hidden_nolink_def (nis_local_directory
, GLIBC_2_1
)
83 nis_local_principal (void)
85 static char __principal
[NIS_MAXNAMELEN
+ 1];
87 if (__principal
[0] == '\0')
89 char buf
[NIS_MAXNAMELEN
+ 1];
91 uid_t uid
= geteuid ();
95 int len
= snprintf (buf
, NIS_MAXNAMELEN
- 1,
96 "[auth_name=%d,auth_type=LOCAL],cred.org_dir.%s",
97 uid
, nis_local_directory ());
99 if (len
>= NIS_MAXNAMELEN
- 1)
101 /* XXX The buffer is too small. Can this happen??? */
102 return strcpy (__principal
, "nobody");
104 if (buf
[len
- 1] != '.')
110 res
= nis_list (buf
, USE_DGRAM
+ NO_AUTHINFO
+ FOLLOW_LINKS
111 + FOLLOW_PATH
, NULL
, NULL
);
116 if (NIS_RES_STATUS (res
) == NIS_SUCCESS
)
118 if (res
->objects
.objects_len
> 1)
120 /* More than one principal with same uid? something
121 wrong with cred table. Should be unique. Warn user
124 LOCAL entry for UID %d in directory %s not unique\n"),
125 uid
, nis_local_directory ());
127 strcpy (__principal
, ENTRY_VAL (res
->objects
.objects_val
, 0));
128 nis_freeresult (res
);
133 nis_freeresult (res
);
138 return strcpy (__principal
, nis_local_host ());
140 /* Should be never reached */
145 libnsl_hidden_nolink_def (nis_local_principal
, GLIBC_2_1
)
148 nis_local_host (void)
150 static char __nishostname
[NIS_MAXNAMELEN
+ 1];
152 if (__nishostname
[0] == '\0')
154 if (gethostname (__nishostname
, NIS_MAXNAMELEN
) < 0)
155 __nishostname
[0] = '\0';
158 char *cp
= rawmemchr (__nishostname
, '\0');
159 int len
= cp
- __nishostname
;
161 /* Hostname already fully qualified? */
163 return __nishostname
;
165 if (len
+ strlen (nis_local_directory ()) + 1 > NIS_MAXNAMELEN
)
167 __nishostname
[0] = '\0';
168 return __nishostname
;
172 strncpy (cp
, nis_local_directory (), NIS_MAXNAMELEN
- len
-1);
173 __nishostname
[NIS_MAXNAMELEN
] = '\0';
177 return __nishostname
;
179 libnsl_hidden_nolink_def (nis_local_host
, GLIBC_2_1
)