1 /* Copyright (C) 1997-2018 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/>. */
23 #include <shlib-compat.h>
28 #define MAXIPRINT (11) /* max length of printed integer */
29 static const char OPSYS
[] = "unix";
32 user2netname (char netname
[MAXNETNAMELEN
+ 1], const uid_t uid
,
35 char dfltdom
[MAXNETNAMELEN
+ 1];
40 if (getdomainname (dfltdom
, sizeof (dfltdom
)) < 0)
45 strncpy (dfltdom
, domain
, MAXNETNAMELEN
);
46 dfltdom
[MAXNETNAMELEN
] = '\0';
49 if ((strlen (dfltdom
) + OPSYS_LEN
+ 3 + MAXIPRINT
) > (size_t) MAXNETNAMELEN
)
52 sprintf (netname
, "%s.%d@%s", OPSYS
, uid
, dfltdom
);
54 if (netname
[i
- 1] == '.')
55 netname
[i
- 1] = '\0';
58 libc_hidden_nolink_sunrpc (user2netname
, GLIBC_2_1
)
61 host2netname (char netname
[MAXNETNAMELEN
+ 1], const char *host
,
65 char hostname
[MAXHOSTNAMELEN
+ 1];
66 char domainname
[MAXHOSTNAMELEN
+ 1];
70 netname
[0] = '\0'; /* make null first (no need for memset) */
73 __gethostname (hostname
, MAXHOSTNAMELEN
);
76 strncpy (hostname
, host
, MAXHOSTNAMELEN
);
77 hostname
[MAXHOSTNAMELEN
] = '\0';
80 dot_in_host
= strchr (hostname
, '.');
87 strncpy (domainname
, p
, MAXHOSTNAMELEN
);
88 domainname
[MAXHOSTNAMELEN
] = '\0';
93 getdomainname (domainname
, MAXHOSTNAMELEN
);
98 strncpy (domainname
, domain
, MAXHOSTNAMELEN
);
99 domainname
[MAXHOSTNAMELEN
] = '\0';
102 i
= strlen (domainname
);
106 if (domainname
[i
- 1] == '.')
107 domainname
[i
- 1] = 0;
109 if (dot_in_host
) /* strip off rest of name */
112 if ((strlen (domainname
) + strlen (hostname
) + OPSYS_LEN
+ 3)
116 sprintf (netname
, "%s.%s@%s", OPSYS
, hostname
, domainname
);
119 #ifdef EXPORT_RPC_SYMBOLS
120 libc_hidden_def (host2netname
)
122 libc_hidden_nolink_sunrpc (host2netname
, GLIBC_2_1
)
126 getnetname (char name
[MAXNETNAMELEN
+ 1])
133 dummy
= host2netname (name
, NULL
, NULL
);
135 dummy
= user2netname (name
, uid
, NULL
);
138 libc_hidden_nolink_sunrpc (getnetname
, GLIBC_2_1
)
140 /* Type of the lookup function for netname2user. */
141 typedef int (*netname2user_function
) (const char netname
[MAXNETNAMELEN
+ 1],
142 uid_t
*, gid_t
*, int *, gid_t
*);
145 netname2user (const char netname
[MAXNETNAMELEN
+ 1], uid_t
* uidp
, gid_t
* gidp
,
146 int *gidlenp
, gid_t
* gidlist
)
148 static service_user
*startp
;
149 static netname2user_function start_fct
;
153 netname2user_function f
;
156 enum nss_status status
= NSS_STATUS_UNAVAIL
;
161 no_more
= __nss_publickey_lookup2 (&nip
, "netname2user", NULL
, &fct
.ptr
);
163 startp
= (service_user
*) - 1;
173 no_more
= (nip
= startp
) == (service_user
*) - 1;
178 status
= (*fct
.f
) (netname
, uidp
, gidp
, gidlenp
, gidlist
);
180 no_more
= __nss_next2 (&nip
, "netname2user", NULL
, &fct
.ptr
, status
, 0);
183 return status
== NSS_STATUS_SUCCESS
;
185 #ifdef EXPORT_RPC_SYMBOLS
186 libc_hidden_def (netname2user
)
188 libc_hidden_nolink_sunrpc (netname2user
, GLIBC_2_1
)
192 netname2host (const char netname
[MAXNETNAMELEN
+ 1], char *hostname
,
197 p1
= strchr (netname
, '.');
202 p2
= strchr (p1
, '@');
207 if (hostlen
> MAXNETNAMELEN
)
210 strncpy (hostname
, p1
, hostlen
);
211 hostname
[hostlen
] = '\0';
215 libc_hidden_nolink_sunrpc (netname2host
, GLIBC_2_1
)