]>
Commit | Line | Data |
---|---|---|
d4a089cf | 1 | /* Get public or secret key from key server. |
f7a9f785 | 2 | Copyright (C) 1996-2016 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 | 16 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
17 | License along with the GNU C Library; if not, see |
18 | <http://www.gnu.org/licenses/>. */ | |
d4a089cf | 19 | |
bd355af0 | 20 | #include <errno.h> |
d4a089cf | 21 | #include <rpc/netdb.h> |
6b083d46 | 22 | #include <rpc/auth_des.h> |
d4a089cf UD |
23 | |
24 | #include "nsswitch.h" | |
25 | ||
26 | ||
27 | /* Type of the lookup function for the public key. */ | |
bd355af0 | 28 | typedef int (*public_function) (const char *, char *, int *); |
d4a089cf UD |
29 | |
30 | /* Type of the lookup function for the secret key. */ | |
bd355af0 | 31 | typedef int (*secret_function) (const char *, char *, const char *, int *); |
d4a089cf UD |
32 | |
33 | /* The lookup function for the first entry of this service. */ | |
34 | extern int __nss_publickey_lookup (service_user **nip, const char *name, | |
f7ddf3d3 | 35 | void **fctp) internal_function; |
d4a089cf UD |
36 | |
37 | ||
38 | int | |
39 | getpublickey (const char *name, char *key) | |
40 | { | |
c4563d2d | 41 | static service_user *startp; |
d4a089cf UD |
42 | static public_function start_fct; |
43 | service_user *nip; | |
fb776f3e AJ |
44 | union |
45 | { | |
46 | public_function f; | |
47 | void *ptr; | |
48 | } fct; | |
d4a089cf UD |
49 | enum nss_status status = NSS_STATUS_UNAVAIL; |
50 | int no_more; | |
51 | ||
52 | if (startp == NULL) | |
53 | { | |
fb776f3e | 54 | no_more = __nss_publickey_lookup (&nip, "getpublickey", &fct.ptr); |
d4a089cf UD |
55 | if (no_more) |
56 | startp = (service_user *) -1; | |
57 | else | |
58 | { | |
59 | startp = nip; | |
fb776f3e | 60 | start_fct = fct.f; |
d4a089cf UD |
61 | } |
62 | } | |
63 | else | |
64 | { | |
fb776f3e | 65 | fct.f = start_fct; |
d4a089cf UD |
66 | no_more = (nip = startp) == (service_user *) -1; |
67 | } | |
68 | ||
69 | while (! no_more) | |
70 | { | |
fb776f3e | 71 | status = (*fct.f) (name, key, &errno); |
d4a089cf | 72 | |
384ca551 | 73 | no_more = __nss_next2 (&nip, "getpublickey", NULL, &fct.ptr, status, 0); |
d4a089cf UD |
74 | } |
75 | ||
76 | return status == NSS_STATUS_SUCCESS; | |
77 | } | |
021db4be | 78 | libc_hidden_nolink_sunrpc (getpublickey, GLIBC_2_0) |
d4a089cf UD |
79 | |
80 | ||
81 | int | |
82 | getsecretkey (const char *name, char *key, const char *passwd) | |
83 | { | |
c4563d2d | 84 | static service_user *startp; |
d4a089cf UD |
85 | static secret_function start_fct; |
86 | service_user *nip; | |
fb776f3e AJ |
87 | union |
88 | { | |
89 | secret_function f; | |
90 | void *ptr; | |
91 | } fct; | |
d4a089cf UD |
92 | enum nss_status status = NSS_STATUS_UNAVAIL; |
93 | int no_more; | |
94 | ||
95 | if (startp == NULL) | |
96 | { | |
fb776f3e | 97 | no_more = __nss_publickey_lookup (&nip, "getsecretkey", &fct.ptr); |
d4a089cf UD |
98 | if (no_more) |
99 | startp = (service_user *) -1; | |
100 | else | |
101 | { | |
102 | startp = nip; | |
fb776f3e | 103 | start_fct = fct.f; |
d4a089cf UD |
104 | } |
105 | } | |
106 | else | |
107 | { | |
fb776f3e | 108 | fct.f = start_fct; |
d4a089cf UD |
109 | no_more = (nip = startp) == (service_user *) -1; |
110 | } | |
111 | ||
112 | while (! no_more) | |
113 | { | |
fb776f3e | 114 | status = (*fct.f) (name, key, passwd, &errno); |
d4a089cf | 115 | |
384ca551 | 116 | no_more = __nss_next2 (&nip, "getsecretkey", NULL, &fct.ptr, status, 0); |
d4a089cf UD |
117 | } |
118 | ||
119 | return status == NSS_STATUS_SUCCESS; | |
120 | } | |
021db4be | 121 | libc_hidden_nolink_sunrpc (getsecretkey, GLIBC_2_0) |