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. */
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';
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
, '.');
85 strncpy (domainname
, p
, MAXHOSTNAMELEN
);
86 domainname
[MAXHOSTNAMELEN
] = '\0';
91 getdomainname (domainname
, MAXHOSTNAMELEN
);
96 strncpy (domainname
, domain
, MAXHOSTNAMELEN
);
97 domainname
[MAXHOSTNAMELEN
] = '\0';
100 i
= strlen (domainname
);
104 if (domainname
[i
- 1] == '.')
105 domainname
[i
- 1] = 0;
107 if (dot_in_host
) /* strip off rest of name */
110 if ((strlen (domainname
) + strlen (hostname
) + OPSYS_LEN
+ 3)
114 sprintf (netname
, "%s.%s@%s", OPSYS
, hostname
, domainname
);
119 getnetname (char name
[MAXNETNAMELEN
+ 1])
126 dummy
= host2netname (name
, NULL
, NULL
);
128 dummy
= user2netname (name
, uid
, NULL
);
132 /* Type of the lookup function for netname2user. */
133 typedef int (*netname2user_function
) (const char netname
[MAXNETNAMELEN
+ 1],
134 uid_t
*, gid_t
*, int *, gid_t
*);
135 /* The lookup function for the first entry of this service. */
136 extern int __nss_publickey_lookup (service_user
** nip
, const char *name
,
140 netname2user (const char netname
[MAXNETNAMELEN
+ 1], uid_t
* uidp
, gid_t
* gidp
,
141 int *gidlenp
, gid_t
* gidlist
)
143 static service_user
*startp
= NULL
;
144 static netname2user_function start_fct
;
146 netname2user_function fct
;
147 enum nss_status status
= NSS_STATUS_UNAVAIL
;
152 no_more
= __nss_publickey_lookup (&nip
, "netname2user", (void **) &fct
);
154 startp
= (service_user
*) - 1;
164 no_more
= (nip
= startp
) == (service_user
*) - 1;
169 status
= (*fct
) (netname
, uidp
, gidp
, gidlenp
, gidlist
);
171 no_more
= __nss_next (&nip
, "netname2user", (void **) &fct
, status
, 0);
174 return status
== NSS_STATUS_SUCCESS
;
178 netname2host (const char netname
[MAXNETNAMELEN
+ 1], char *hostname
,
182 char buffer
[MAXNETNAMELEN
+ 1];
184 p1
= strchr (buffer
, '.');
189 p2
= strchr (p1
, '@');
194 if (hostlen
> MAXNETNAMELEN
)
197 strncpy (hostname
, p1
, hostlen
);
198 hostname
[hostlen
] = '\0';