]>
Commit | Line | Data |
---|---|---|
d4a089cf | 1 | /* Get public or secret key from key server. |
384ca551 | 2 | Copyright (C) 1996-1999,2002,2007 Free Software Foundation, Inc. |
d4a089cf UD |
3 | This file is part of the GNU C Library. |
4 | Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. | |
5 | ||
6 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
7 | modify it under the terms of the GNU Lesser General Public |
8 | License as published by the Free Software Foundation; either | |
9 | version 2.1 of the License, or (at your option) any later version. | |
d4a089cf UD |
10 | |
11 | The GNU C Library is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 | 14 | Lesser General Public License for more details. |
d4a089cf | 15 | |
41bdb6e2 AJ |
16 | You should have received a copy of the GNU Lesser General Public |
17 | License along with the GNU C Library; if not, write to the Free | |
18 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |
19 | 02111-1307 USA. */ | |
d4a089cf | 20 | |
bd355af0 | 21 | #include <errno.h> |
d4a089cf | 22 | #include <rpc/netdb.h> |
6b083d46 | 23 | #include <rpc/auth_des.h> |
d4a089cf UD |
24 | |
25 | #include "nsswitch.h" | |
26 | ||
27 | ||
28 | /* Type of the lookup function for the public key. */ | |
bd355af0 | 29 | typedef int (*public_function) (const char *, char *, int *); |
d4a089cf UD |
30 | |
31 | /* Type of the lookup function for the secret key. */ | |
bd355af0 | 32 | typedef int (*secret_function) (const char *, char *, const char *, int *); |
d4a089cf UD |
33 | |
34 | /* The lookup function for the first entry of this service. */ | |
35 | extern int __nss_publickey_lookup (service_user **nip, const char *name, | |
f7ddf3d3 | 36 | void **fctp) internal_function; |
d4a089cf UD |
37 | |
38 | ||
39 | int | |
40 | getpublickey (const char *name, char *key) | |
41 | { | |
c4563d2d | 42 | static service_user *startp; |
d4a089cf UD |
43 | static public_function start_fct; |
44 | service_user *nip; | |
fb776f3e AJ |
45 | union |
46 | { | |
47 | public_function f; | |
48 | void *ptr; | |
49 | } fct; | |
d4a089cf UD |
50 | enum nss_status status = NSS_STATUS_UNAVAIL; |
51 | int no_more; | |
52 | ||
53 | if (startp == NULL) | |
54 | { | |
fb776f3e | 55 | no_more = __nss_publickey_lookup (&nip, "getpublickey", &fct.ptr); |
d4a089cf UD |
56 | if (no_more) |
57 | startp = (service_user *) -1; | |
58 | else | |
59 | { | |
60 | startp = nip; | |
fb776f3e | 61 | start_fct = fct.f; |
d4a089cf UD |
62 | } |
63 | } | |
64 | else | |
65 | { | |
fb776f3e | 66 | fct.f = start_fct; |
d4a089cf UD |
67 | no_more = (nip = startp) == (service_user *) -1; |
68 | } | |
69 | ||
70 | while (! no_more) | |
71 | { | |
fb776f3e | 72 | status = (*fct.f) (name, key, &errno); |
d4a089cf | 73 | |
384ca551 | 74 | no_more = __nss_next2 (&nip, "getpublickey", NULL, &fct.ptr, status, 0); |
d4a089cf UD |
75 | } |
76 | ||
77 | return status == NSS_STATUS_SUCCESS; | |
78 | } | |
7b57bfe5 | 79 | libc_hidden_nolink (getpublickey, GLIBC_2_0) |
d4a089cf UD |
80 | |
81 | ||
82 | int | |
83 | getsecretkey (const char *name, char *key, const char *passwd) | |
84 | { | |
c4563d2d | 85 | static service_user *startp; |
d4a089cf UD |
86 | static secret_function start_fct; |
87 | service_user *nip; | |
fb776f3e AJ |
88 | union |
89 | { | |
90 | secret_function f; | |
91 | void *ptr; | |
92 | } fct; | |
d4a089cf UD |
93 | enum nss_status status = NSS_STATUS_UNAVAIL; |
94 | int no_more; | |
95 | ||
96 | if (startp == NULL) | |
97 | { | |
fb776f3e | 98 | no_more = __nss_publickey_lookup (&nip, "getsecretkey", &fct.ptr); |
d4a089cf UD |
99 | if (no_more) |
100 | startp = (service_user *) -1; | |
101 | else | |
102 | { | |
103 | startp = nip; | |
fb776f3e | 104 | start_fct = fct.f; |
d4a089cf UD |
105 | } |
106 | } | |
107 | else | |
108 | { | |
fb776f3e | 109 | fct.f = start_fct; |
d4a089cf UD |
110 | no_more = (nip = startp) == (service_user *) -1; |
111 | } | |
112 | ||
113 | while (! no_more) | |
114 | { | |
fb776f3e | 115 | status = (*fct.f) (name, key, passwd, &errno); |
d4a089cf | 116 | |
384ca551 | 117 | no_more = __nss_next2 (&nip, "getsecretkey", NULL, &fct.ptr, status, 0); |
d4a089cf UD |
118 | } |
119 | ||
120 | return status == NSS_STATUS_SUCCESS; | |
121 | } | |
7b57bfe5 | 122 | libc_hidden_nolink (getsecretkey, GLIBC_2_0) |