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. */
23 #include <rpcsvc/nis.h>
24 #include <rpcsvc/nislib.h>
27 nis_local_group (void)
29 static char __nisgroup
[NIS_MAXNAMELEN
+ 1];
31 if (__nisgroup
[0] == '\0')
35 if ((cptr
= getenv ("NIS_GROUP")) == NULL
)
38 if (strlen (cptr
) >= NIS_MAXNAMELEN
)
41 strcpy (__nisgroup
, cptr
);
43 if (__nisgroup
[strlen (__nisgroup
) - 1] != '.')
45 cptr
= nis_local_directory ();
46 if (strlen (__nisgroup
) + strlen (cptr
) + 1 < NIS_MAXNAMELEN
)
48 strcat (__nisgroup
, ".");
49 strcat (__nisgroup
, cptr
);
64 nis_local_directory (void)
66 static char __nisdomainname
[NIS_MAXNAMELEN
+ 1];
69 if (__nisdomainname
[0] == '\0')
71 if (getdomainname (__nisdomainname
, NIS_MAXNAMELEN
) < 0)
72 strcpy (__nisdomainname
, "\0");
75 len
= strlen (__nisdomainname
);
77 /* Missing trailing dot? */
78 if (__nisdomainname
[len
- 1] != '.')
80 __nisdomainname
[len
] = '.';
81 __nisdomainname
[len
+ 1] = '\0';
86 return __nisdomainname
;
90 nis_local_principal (void)
92 static char __principal
[NIS_MAXNAMELEN
+ 1];
94 if (__principal
[0] == '\0')
96 char buf
[NIS_MAXNAMELEN
+ 1];
98 uid_t uid
= geteuid ();
102 snprintf (buf
, NIS_MAXNAMELEN
- 1,
103 "[auth_name=%d,auth_type=LOCAL],cred.org_dir.%s",
104 uid
, nis_local_directory ());
106 if (buf
[strlen (buf
) - 1] != '.')
109 res
= nis_list (buf
, USE_DGRAM
+ NO_AUTHINFO
+ FOLLOW_LINKS
+
110 FOLLOW_PATH
, NULL
, NULL
);
114 strcpy (__principal
, "nobody");
118 if (res
->status
== 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 strcpy (__principal
, "nobody");
142 strcpy (__principal
, nis_local_host ());
146 /* Should be never reached */
147 strcpy (__principal
, "nobody");
154 nis_local_host (void)
156 static char __nishostname
[NIS_MAXNAMELEN
+ 1];
159 if (__nishostname
[0] == '\0')
161 if (gethostname (__nishostname
, NIS_MAXNAMELEN
) < 0)
162 __nishostname
[0] = '\0';
166 len
= strlen(__nishostname
);
168 /* Hostname already fully qualified? */
169 if (__nishostname
[len
- 1] == '.')
170 return __nishostname
;
172 if ((strlen (__nishostname
) + strlen (nis_local_directory ()) + 1) >
175 __nishostname
[0] = '\0';
176 return __nishostname
;
179 cp
= &__nishostname
[len
];
181 strncpy (cp
, nis_local_directory (), NIS_MAXNAMELEN
- len
-1);
182 __nishostname
[NIS_MAXNAMELEN
] = '\0';
186 return __nishostname
;