]> sourceware.org Git - glibc.git/blob - sunrpc/publickey.c
1998-12-20 Roland McGrath <roland@baalperazim.frob.com>
[glibc.git] / sunrpc / publickey.c
1 /* Get public or secret key from key server.
2 Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
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
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
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
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21 #include <errno.h>
22 #include <rpc/netdb.h>
23
24 #include "nsswitch.h"
25
26
27 /* Type of the lookup function for the public key. */
28 typedef int (*public_function) (const char *, char *, int *);
29
30 /* Type of the lookup function for the secret key. */
31 typedef int (*secret_function) (const char *, char *, const char *, int *);
32
33 /* The lookup function for the first entry of this service. */
34 extern int __nss_publickey_lookup (service_user **nip, const char *name,
35 void **fctp);
36
37
38 int
39 getpublickey (const char *name, char *key)
40 {
41 static service_user *startp = NULL;
42 static public_function start_fct;
43 service_user *nip;
44 public_function fct;
45 enum nss_status status = NSS_STATUS_UNAVAIL;
46 int no_more;
47
48 if (startp == NULL)
49 {
50 no_more = __nss_publickey_lookup (&nip, "getpublickey", (void **) &fct);
51 if (no_more)
52 startp = (service_user *) -1;
53 else
54 {
55 startp = nip;
56 start_fct = fct;
57 }
58 }
59 else
60 {
61 fct = start_fct;
62 no_more = (nip = startp) == (service_user *) -1;
63 }
64
65 while (! no_more)
66 {
67 status = (*fct) (name, key, &errno);
68
69 no_more = __nss_next (&nip, "getpublickey", (void **) &fct, status, 0);
70 }
71
72 return status == NSS_STATUS_SUCCESS;
73 }
74
75
76 int
77 getsecretkey (const char *name, char *key, const char *passwd)
78 {
79 static service_user *startp = NULL;
80 static secret_function start_fct;
81 service_user *nip;
82 secret_function fct;
83 enum nss_status status = NSS_STATUS_UNAVAIL;
84 int no_more;
85
86 if (startp == NULL)
87 {
88 no_more = __nss_publickey_lookup (&nip, "getsecretkey", (void **) &fct);
89 if (no_more)
90 startp = (service_user *) -1;
91 else
92 {
93 startp = nip;
94 start_fct = fct;
95 }
96 }
97 else
98 {
99 fct = start_fct;
100 no_more = (nip = startp) == (service_user *) -1;
101 }
102
103 while (! no_more)
104 {
105 status = (*fct) (name, key, passwd, &errno);
106
107 no_more = __nss_next (&nip, "getsecretkey", (void **) &fct, status, 0);
108 }
109
110 return status == NSS_STATUS_SUCCESS;
111 }
This page took 0.047325 seconds and 6 git commands to generate.