1 /* Copyright (c) 1997, 1998, 2004 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24 #include <rpcsvc/nis.h>
27 nis_local_group (void)
29 static char __nisgroup
[NIS_MAXNAMELEN
+ 1];
32 if (__nisgroup
[0] == '\0'
33 && (cptr
= getenv ("NIS_GROUP")) != NULL
34 && strlen (cptr
) < NIS_MAXNAMELEN
)
36 char *cp
= stpcpy (__nisgroup
, cptr
);
40 cptr
= nis_local_directory ();
41 if ((cp
- __nisgroup
) + strlen (cptr
) + 1 < NIS_MAXNAMELEN
)
53 libnsl_hidden_def (nis_local_group
)
56 nis_local_directory (void)
58 static char __nisdomainname
[NIS_MAXNAMELEN
+ 1];
60 if (__nisdomainname
[0] == '\0')
62 if (getdomainname (__nisdomainname
, NIS_MAXNAMELEN
) < 0)
63 __nisdomainname
[0] = '\0';
66 char *cp
= strchr (__nisdomainname
, '\0');
68 /* Missing trailing dot? */
77 return __nisdomainname
;
79 libnsl_hidden_def (nis_local_directory
)
82 nis_local_principal (void)
84 static char __principal
[NIS_MAXNAMELEN
+ 1];
86 if (__principal
[0] == '\0')
88 char buf
[NIS_MAXNAMELEN
+ 1];
90 uid_t uid
= geteuid ();
94 int len
= snprintf (buf
, NIS_MAXNAMELEN
- 1,
95 "[auth_name=%d,auth_type=LOCAL],cred.org_dir.%s",
96 uid
, nis_local_directory ());
98 if (len
>= NIS_MAXNAMELEN
- 1)
100 /* XXX The buffer is too small. Can this happen??? */
101 return strcpy (__principal
, "nobody");
103 if (buf
[len
- 1] != '.')
109 res
= nis_list (buf
, USE_DGRAM
+ NO_AUTHINFO
+ FOLLOW_LINKS
+
110 FOLLOW_PATH
, NULL
, NULL
);
115 if (NIS_RES_STATUS (res
) == NIS_SUCCESS
)
117 if (res
->objects
.objects_len
> 1)
119 /* More than one principal with same uid? something
120 wrong with cred table. Should be unique. Warn user
123 LOCAL entry for UID %d in directory %s not unique\n"),
124 uid
, nis_local_directory ());
126 strcpy (__principal
, ENTRY_VAL (res
->objects
.objects_val
, 0));
127 nis_freeresult (res
);
132 nis_freeresult (res
);
137 return strcpy (__principal
, nis_local_host ());
139 /* Should be never reached */
144 libnsl_hidden_def (nis_local_principal
)
147 nis_local_host (void)
149 static char __nishostname
[NIS_MAXNAMELEN
+ 1];
151 if (__nishostname
[0] == '\0')
153 if (gethostname (__nishostname
, NIS_MAXNAMELEN
) < 0)
154 __nishostname
[0] = '\0';
157 char *cp
= strchr (__nishostname
, '\0');
158 int len
= cp
- __nishostname
;
160 /* Hostname already fully qualified? */
162 return __nishostname
;
164 if (len
+ strlen (nis_local_directory ()) + 1 > NIS_MAXNAMELEN
)
166 __nishostname
[0] = '\0';
167 return __nishostname
;
171 strncpy (cp
, nis_local_directory (), NIS_MAXNAMELEN
- len
-1);
172 __nishostname
[NIS_MAXNAMELEN
] = '\0';
176 return __nishostname
;
178 libnsl_hidden_def (nis_local_host
)