1/* Get public or secret key from key server.
2 Copyright (C) 1996-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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 <https://www.gnu.org/licenses/>. */
18
19#include <errno.h>
20#include <rpc/netdb.h>
21#include <rpc/auth_des.h>
22#include <shlib-compat.h>
23
24#include "nsswitch.h"
25
26
27/* Type of the lookup function for the public key. */
28typedef int (*public_function) (const char *, char *, int *);
29
30/* Type of the lookup function for the secret key. */
31typedef int (*secret_function) (const char *, char *, const char *, int *);
32
33int
34getpublickey (const char *name, char *key)
35{
36 nss_action_list nip;
37 union
38 {
39 public_function f;
40 void *ptr;
41 } fct;
42 enum nss_status status = NSS_STATUS_UNAVAIL;
43 int no_more;
44
45 no_more = __nss_publickey_lookup2 (&nip, "getpublickey", NULL, &fct.ptr);
46
47 while (! no_more)
48 {
49 status = (*fct.f) (name, key, &errno);
50
51 no_more = __nss_next2 (&nip, "getpublickey", NULL, &fct.ptr, status, 0);
52 }
53
54 return status == NSS_STATUS_SUCCESS;
55}
56libc_hidden_nolink_sunrpc (getpublickey, GLIBC_2_0)
57
58
59int
60getsecretkey (const char *name, char *key, const char *passwd)
61{
62 nss_action_list nip;
63 union
64 {
65 secret_function f;
66 void *ptr;
67 } fct;
68 enum nss_status status = NSS_STATUS_UNAVAIL;
69 int no_more;
70
71 no_more = __nss_publickey_lookup2 (&nip, "getsecretkey", NULL, &fct.ptr);
72
73 while (! no_more)
74 {
75 status = (*fct.f) (name, key, passwd, &errno);
76
77 no_more = __nss_next2 (&nip, "getsecretkey", NULL, &fct.ptr, status, 0);
78 }
79
80 return status == NSS_STATUS_SUCCESS;
81}
82libc_hidden_nolink_sunrpc (getsecretkey, GLIBC_2_0)
83

source code of glibc/sunrpc/publickey.c