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 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];
31 if (__nisgroup
[0] == '\0')
36 if ((cptr
= getenv ("NIS_GROUP")) == NULL
)
39 if (strlen (cptr
) >= NIS_MAXNAMELEN
)
42 cp
= stpcpy (__nisgroup
, cptr
);
46 cptr
= nis_local_directory ();
47 if ((cp
- __nisgroup
) + strlen (cptr
) + 1 < NIS_MAXNAMELEN
)
62 nis_local_directory (void)
64 static char __nisdomainname
[NIS_MAXNAMELEN
+ 1];
66 if (__nisdomainname
[0] == '\0')
68 if (getdomainname (__nisdomainname
, NIS_MAXNAMELEN
) < 0)
69 __nisdomainname
[0] = '\0';
72 char *cp
= strchr (__nisdomainname
, '\0');
74 /* Missing trailing dot? */
83 return __nisdomainname
;
87 nis_local_principal (void)
89 static char __principal
[NIS_MAXNAMELEN
+ 1];
91 if (__principal
[0] == '\0')
93 char buf
[NIS_MAXNAMELEN
+ 1];
95 uid_t uid
= geteuid ();
99 int len
= snprintf (buf
, NIS_MAXNAMELEN
- 1,
100 "[auth_name=%d,auth_type=LOCAL],cred.org_dir.%s",
101 uid
, nis_local_directory ());
103 if (len
>= NIS_MAXNAMELEN
- 1)
104 /* XXX The buffer is too small. Can this happen??? */
105 return strcpy (__principal
, "nobody");
107 if (buf
[len
- 1] != '.')
113 res
= nis_list (buf
, USE_DGRAM
+ NO_AUTHINFO
+ FOLLOW_LINKS
+
114 FOLLOW_PATH
, NULL
, NULL
);
117 return strcpy (__principal
, "nobody");
119 if (NIS_RES_STATUS (res
) == NIS_SUCCESS
)
121 if (res
->objects
.objects_len
> 1)
123 /* More than one principal with same uid? something
124 wrong with cred table. Should be unique. Warn user
127 LOCAL entry for UID %d in directory %s not unique\n"),
128 uid
, nis_local_directory ());
130 strcpy (__principal
, ENTRY_VAL (res
->objects
.objects_val
, 0));
131 nis_freeresult (res
);
136 nis_freeresult (res
);
137 return strcpy (__principal
, "nobody");
141 return strcpy (__principal
, nis_local_host ());
143 /* Should be never reached */
144 return strcpy (__principal
, "nobody");
150 nis_local_host (void)
152 static char __nishostname
[NIS_MAXNAMELEN
+ 1];
154 if (__nishostname
[0] == '\0')
156 if (gethostname (__nishostname
, NIS_MAXNAMELEN
) < 0)
157 __nishostname
[0] = '\0';
160 char *cp
= strchr (__nishostname
, '\0');
161 int len
= cp
- __nishostname
;
163 /* Hostname already fully qualified? */
165 return __nishostname
;
167 if (len
+ strlen (nis_local_directory ()) + 1 > NIS_MAXNAMELEN
)
169 __nishostname
[0] = '\0';
170 return __nishostname
;
174 strncpy (cp
, nis_local_directory (), NIS_MAXNAMELEN
- len
-1);
175 __nishostname
[NIS_MAXNAMELEN
] = '\0';
179 return __nishostname
;