1 /* Copyright (c) 1997, 1998 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. */
23 #include <rpcsvc/nis.h>
26 nis_local_group (void)
28 static char __nisgroup
[NIS_MAXNAMELEN
+ 1];
30 if (__nisgroup
[0] == '\0')
35 if ((cptr
= getenv ("NIS_GROUP")) == NULL
)
38 if (strlen (cptr
) >= NIS_MAXNAMELEN
)
41 cp
= stpcpy (__nisgroup
, cptr
);
45 cptr
= nis_local_directory ();
46 if ((cp
- __nisgroup
) + strlen (cptr
) + 1 < NIS_MAXNAMELEN
)
61 nis_local_directory (void)
63 static char __nisdomainname
[NIS_MAXNAMELEN
+ 1];
65 if (__nisdomainname
[0] == '\0')
67 if (getdomainname (__nisdomainname
, NIS_MAXNAMELEN
) < 0)
68 __nisdomainname
[0] = '\0';
71 char *cp
= strchr (__nisdomainname
, '\0');
73 /* Missing trailing dot? */
82 return __nisdomainname
;
86 nis_local_principal (void)
88 static char __principal
[NIS_MAXNAMELEN
+ 1];
90 if (__principal
[0] == '\0')
92 char buf
[NIS_MAXNAMELEN
+ 1];
94 uid_t uid
= geteuid ();
98 int len
= snprintf (buf
, NIS_MAXNAMELEN
- 1,
99 "[auth_name=%d,auth_type=LOCAL],cred.org_dir.%s",
100 uid
, nis_local_directory ());
102 if (len
>= NIS_MAXNAMELEN
- 1)
103 /* XXX The buffer is too small. Can this happen??? */
104 return strcpy (__principal
, "nobody");
106 if (buf
[len
- 1] != '.')
112 res
= nis_list (buf
, USE_DGRAM
+ NO_AUTHINFO
+ FOLLOW_LINKS
+
113 FOLLOW_PATH
, NULL
, NULL
);
116 return strcpy (__principal
, "nobody");
118 if (NIS_RES_STATUS (res
) == NIS_SUCCESS
)
120 if (res
->objects
.objects_len
> 1)
122 /* More than one principal with same uid? something
123 wrong with cred table. Should be unique. Warn user
126 LOCAL entry for UID %d in directory %s not unique\n"),
127 uid
, nis_local_directory ());
129 strcpy (__principal
, ENTRY_VAL (res
->objects
.objects_val
, 0));
130 nis_freeresult (res
);
135 nis_freeresult (res
);
136 return strcpy (__principal
, "nobody");
140 return strcpy (__principal
, nis_local_host ());
142 /* Should be never reached */
143 return strcpy (__principal
, "nobody");
149 nis_local_host (void)
151 static char __nishostname
[NIS_MAXNAMELEN
+ 1];
153 if (__nishostname
[0] == '\0')
155 if (gethostname (__nishostname
, NIS_MAXNAMELEN
) < 0)
156 __nishostname
[0] = '\0';
159 char *cp
= strchr (__nishostname
, '\0');
160 int len
= cp
- __nishostname
;
162 /* Hostname already fully qualified? */
164 return __nishostname
;
166 if (len
+ strlen (nis_local_directory ()) + 1 > NIS_MAXNAMELEN
)
168 __nishostname
[0] = '\0';
169 return __nishostname
;
173 strncpy (cp
, nis_local_directory (), NIS_MAXNAMELEN
- len
-1);
174 __nishostname
[NIS_MAXNAMELEN
] = '\0';
178 return __nishostname
;