]> git.ipfire.org Git - thirdparty/glibc.git/blame - sunrpc/publickey.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sunrpc / publickey.c
CommitLineData
d4a089cf 1/* Get public or secret key from key server.
04277e02 2 Copyright (C) 1996-2019 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>
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 29typedef int (*public_function) (const char *, char *, int *);
d4a089cf
UD
30
31/* Type of the lookup function for the secret key. */
bd355af0 32typedef int (*secret_function) (const char *, char *, const char *, int *);
d4a089cf 33
d4a089cf
UD
34int
35getpublickey (const char *name, char *key)
36{
c4563d2d 37 static service_user *startp;
d4a089cf
UD
38 static public_function start_fct;
39 service_user *nip;
fb776f3e
AJ
40 union
41 {
42 public_function f;
43 void *ptr;
44 } fct;
d4a089cf
UD
45 enum nss_status status = NSS_STATUS_UNAVAIL;
46 int no_more;
47
48 if (startp == NULL)
49 {
c88ffc23 50 no_more = __nss_publickey_lookup2 (&nip, "getpublickey", NULL, &fct.ptr);
d4a089cf
UD
51 if (no_more)
52 startp = (service_user *) -1;
53 else
54 {
55 startp = nip;
fb776f3e 56 start_fct = fct.f;
d4a089cf
UD
57 }
58 }
59 else
60 {
fb776f3e 61 fct.f = start_fct;
d4a089cf
UD
62 no_more = (nip = startp) == (service_user *) -1;
63 }
64
65 while (! no_more)
66 {
fb776f3e 67 status = (*fct.f) (name, key, &errno);
d4a089cf 68
384ca551 69 no_more = __nss_next2 (&nip, "getpublickey", NULL, &fct.ptr, status, 0);
d4a089cf
UD
70 }
71
72 return status == NSS_STATUS_SUCCESS;
73}
021db4be 74libc_hidden_nolink_sunrpc (getpublickey, GLIBC_2_0)
d4a089cf
UD
75
76
77int
78getsecretkey (const char *name, char *key, const char *passwd)
79{
c4563d2d 80 static service_user *startp;
d4a089cf
UD
81 static secret_function start_fct;
82 service_user *nip;
fb776f3e
AJ
83 union
84 {
85 secret_function f;
86 void *ptr;
87 } fct;
d4a089cf
UD
88 enum nss_status status = NSS_STATUS_UNAVAIL;
89 int no_more;
90
91 if (startp == NULL)
92 {
c88ffc23 93 no_more = __nss_publickey_lookup2 (&nip, "getsecretkey", NULL, &fct.ptr);
d4a089cf
UD
94 if (no_more)
95 startp = (service_user *) -1;
96 else
97 {
98 startp = nip;
fb776f3e 99 start_fct = fct.f;
d4a089cf
UD
100 }
101 }
102 else
103 {
fb776f3e 104 fct.f = start_fct;
d4a089cf
UD
105 no_more = (nip = startp) == (service_user *) -1;
106 }
107
108 while (! no_more)
109 {
fb776f3e 110 status = (*fct.f) (name, key, passwd, &errno);
d4a089cf 111
384ca551 112 no_more = __nss_next2 (&nip, "getsecretkey", NULL, &fct.ptr, status, 0);
d4a089cf
UD
113 }
114
115 return status == NSS_STATUS_SUCCESS;
116}
021db4be 117libc_hidden_nolink_sunrpc (getsecretkey, GLIBC_2_0)