1 /* Copyright (C) 1997-2013 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 <http://www.gnu.org/licenses/>. */
27 #define MAXIPRINT (11) /* max length of printed integer */
28 static const char OPSYS[] = "unix";
31 user2netname (char netname[MAXNETNAMELEN + 1], const uid_t uid,
34 char dfltdom[MAXNETNAMELEN + 1];
39 if (getdomainname (dfltdom, sizeof (dfltdom)) < 0)
44 strncpy (dfltdom, domain, MAXNETNAMELEN);
45 dfltdom[MAXNETNAMELEN] = '\0';
48 if ((strlen (dfltdom) + OPSYS_LEN + 3 + MAXIPRINT) > (size_t) MAXNETNAMELEN)
51 sprintf (netname, "%s.%d@%s", OPSYS, uid, dfltdom);
53 if (netname[i - 1] == '.')
54 netname[i - 1] = '\0';
57 libc_hidden_nolink_sunrpc (user2netname, GLIBC_2_1)
60 host2netname (char netname[MAXNETNAMELEN + 1], const char *host,
64 char hostname[MAXHOSTNAMELEN + 1];
65 char domainname[MAXHOSTNAMELEN + 1];
69 netname[0] = '\0'; /* make null first (no need for memset) */
72 __gethostname (hostname, MAXHOSTNAMELEN);
75 strncpy (hostname, host, MAXHOSTNAMELEN);
76 hostname[MAXHOSTNAMELEN] = '\0';
79 dot_in_host = strchr (hostname, '.');
86 strncpy (domainname, p, MAXHOSTNAMELEN);
87 domainname[MAXHOSTNAMELEN] = '\0';
92 getdomainname (domainname, MAXHOSTNAMELEN);
97 strncpy (domainname, domain, MAXHOSTNAMELEN);
98 domainname[MAXHOSTNAMELEN] = '\0';
101 i = strlen (domainname);
105 if (domainname[i - 1] == '.')
106 domainname[i - 1] = 0;
108 if (dot_in_host) /* strip off rest of name */
111 if ((strlen (domainname) + strlen (hostname) + OPSYS_LEN + 3)
115 sprintf (netname, "%s.%s@%s", OPSYS, hostname, domainname);
118 #ifdef EXPORT_RPC_SYMBOLS
119 libc_hidden_def (host2netname)
121 libc_hidden_nolink_sunrpc (host2netname, GLIBC_2_1)
125 getnetname (char name[MAXNETNAMELEN + 1])
132 dummy = host2netname (name, NULL, NULL);
134 dummy = user2netname (name, uid, NULL);
137 libc_hidden_nolink_sunrpc (getnetname, GLIBC_2_1)
139 /* Type of the lookup function for netname2user. */
140 typedef int (*netname2user_function) (const char netname[MAXNETNAMELEN + 1],
141 uid_t *, gid_t *, int *, gid_t *);
142 /* The lookup function for the first entry of this service. */
143 extern int __nss_publickey_lookup (service_user ** nip, const char *name,
144 void **fctp) internal_function;
147 netname2user (const char netname[MAXNETNAMELEN + 1], uid_t * uidp, gid_t * gidp,
148 int *gidlenp, gid_t * gidlist)
150 static service_user *startp;
151 static netname2user_function start_fct;
155 netname2user_function f;
158 enum nss_status status = NSS_STATUS_UNAVAIL;
163 no_more = __nss_publickey_lookup (&nip, "netname2user", &fct.ptr);
165 startp = (service_user *) - 1;
175 no_more = (nip = startp) == (service_user *) - 1;
180 status = (*fct.f) (netname, uidp, gidp, gidlenp, gidlist);
182 no_more = __nss_next2 (&nip, "netname2user", NULL, &fct.ptr, status, 0);
185 return status == NSS_STATUS_SUCCESS;
187 #ifdef EXPORT_RPC_SYMBOLS
188 libc_hidden_def (netname2user)
190 libc_hidden_nolink_sunrpc (netname2user, GLIBC_2_1)
194 netname2host (const char netname[MAXNETNAMELEN + 1], char *hostname,
199 p1 = strchr (netname, '.');
204 p2 = strchr (p1, '@');
209 if (hostlen > MAXNETNAMELEN)
212 strncpy (hostname, p1, hostlen);
213 hostname[hostlen] = '\0';
217 libc_hidden_nolink_sunrpc (netname2host, GLIBC_2_1)