Add MAP_SHARED_VALIDATE from Linux 4.15.
[glibc.git] / sunrpc / publickey.c
blob9c44760e04d57940f4e1dd533d54d5ffc03c6076
1 /* Get public or secret key from key server.
2 Copyright (C) 1996-2018 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
6 The GNU C Library is free software; you can redistribute it and/or
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.
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
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
20 #include <errno.h>
21 #include <rpc/netdb.h>
22 #include <rpc/auth_des.h>
23 #include <shlib-compat.h>
25 #include "nsswitch.h"
28 /* Type of the lookup function for the public key. */
29 typedef int (*public_function) (const char *, char *, int *);
31 /* Type of the lookup function for the secret key. */
32 typedef int (*secret_function) (const char *, char *, const char *, int *);
34 int
35 getpublickey (const char *name, char *key)
37 static service_user *startp;
38 static public_function start_fct;
39 service_user *nip;
40 union
42 public_function f;
43 void *ptr;
44 } fct;
45 enum nss_status status = NSS_STATUS_UNAVAIL;
46 int no_more;
48 if (startp == NULL)
50 no_more = __nss_publickey_lookup2 (&nip, "getpublickey", NULL, &fct.ptr);
51 if (no_more)
52 startp = (service_user *) -1;
53 else
55 startp = nip;
56 start_fct = fct.f;
59 else
61 fct.f = start_fct;
62 no_more = (nip = startp) == (service_user *) -1;
65 while (! no_more)
67 status = (*fct.f) (name, key, &errno);
69 no_more = __nss_next2 (&nip, "getpublickey", NULL, &fct.ptr, status, 0);
72 return status == NSS_STATUS_SUCCESS;
74 libc_hidden_nolink_sunrpc (getpublickey, GLIBC_2_0)
77 int
78 getsecretkey (const char *name, char *key, const char *passwd)
80 static service_user *startp;
81 static secret_function start_fct;
82 service_user *nip;
83 union
85 secret_function f;
86 void *ptr;
87 } fct;
88 enum nss_status status = NSS_STATUS_UNAVAIL;
89 int no_more;
91 if (startp == NULL)
93 no_more = __nss_publickey_lookup2 (&nip, "getsecretkey", NULL, &fct.ptr);
94 if (no_more)
95 startp = (service_user *) -1;
96 else
98 startp = nip;
99 start_fct = fct.f;
102 else
104 fct.f = start_fct;
105 no_more = (nip = startp) == (service_user *) -1;
108 while (! no_more)
110 status = (*fct.f) (name, key, passwd, &errno);
112 no_more = __nss_next2 (&nip, "getsecretkey", NULL, &fct.ptr, status, 0);
115 return status == NSS_STATUS_SUCCESS;
117 libc_hidden_nolink_sunrpc (getsecretkey, GLIBC_2_0)