]>
Commit | Line | Data |
---|---|---|
d4a089cf | 1 | /* Get public or secret key from key server. |
2b778ceb | 2 | Copyright (C) 1996-2021 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 | 17 | License along with the GNU C Library; if not, see |
5a82c748 | 18 | <https://www.gnu.org/licenses/>. */ |
d4a089cf | 19 | |
bd355af0 | 20 | #include <errno.h> |
d4a089cf | 21 | #include <rpc/netdb.h> |
6b083d46 | 22 | #include <rpc/auth_des.h> |
82f43dd2 | 23 | #include <shlib-compat.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 | 33 | |
d4a089cf UD |
34 | int |
35 | getpublickey (const char *name, char *key) | |
36 | { | |
f4f3b091 | 37 | nss_action_list nip; |
fb776f3e AJ |
38 | union |
39 | { | |
40 | public_function f; | |
41 | void *ptr; | |
42 | } fct; | |
d4a089cf UD |
43 | enum nss_status status = NSS_STATUS_UNAVAIL; |
44 | int no_more; | |
45 | ||
f4f3b091 | 46 | no_more = __nss_publickey_lookup2 (&nip, "getpublickey", NULL, &fct.ptr); |
d4a089cf UD |
47 | |
48 | while (! no_more) | |
49 | { | |
fb776f3e | 50 | status = (*fct.f) (name, key, &errno); |
d4a089cf | 51 | |
384ca551 | 52 | no_more = __nss_next2 (&nip, "getpublickey", NULL, &fct.ptr, status, 0); |
d4a089cf UD |
53 | } |
54 | ||
55 | return status == NSS_STATUS_SUCCESS; | |
56 | } | |
021db4be | 57 | libc_hidden_nolink_sunrpc (getpublickey, GLIBC_2_0) |
d4a089cf UD |
58 | |
59 | ||
60 | int | |
61 | getsecretkey (const char *name, char *key, const char *passwd) | |
62 | { | |
f4f3b091 | 63 | nss_action_list nip; |
fb776f3e AJ |
64 | union |
65 | { | |
66 | secret_function f; | |
67 | void *ptr; | |
68 | } fct; | |
d4a089cf UD |
69 | enum nss_status status = NSS_STATUS_UNAVAIL; |
70 | int no_more; | |
71 | ||
f4f3b091 | 72 | no_more = __nss_publickey_lookup2 (&nip, "getsecretkey", NULL, &fct.ptr); |
d4a089cf UD |
73 | |
74 | while (! no_more) | |
75 | { | |
fb776f3e | 76 | status = (*fct.f) (name, key, passwd, &errno); |
d4a089cf | 77 | |
384ca551 | 78 | no_more = __nss_next2 (&nip, "getsecretkey", NULL, &fct.ptr, status, 0); |
d4a089cf UD |
79 | } |
80 | ||
81 | return status == NSS_STATUS_SUCCESS; | |
82 | } | |
021db4be | 83 | libc_hidden_nolink_sunrpc (getsecretkey, GLIBC_2_0) |