Update.
[glibc.git] / sunrpc / publickey.c
blobecf57bc90cecb3a0d48d592c829570b0361f84ea
1 /* Get public or secret key from key server.
2 Copyright (C) 1996, 1997, 1998, 1999, 2002 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, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #include <errno.h>
22 #include <rpc/netdb.h>
23 #include <rpc/auth_des.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 /* The lookup function for the first entry of this service. */
35 extern int __nss_publickey_lookup (service_user **nip, const char *name,
36 void **fctp) internal_function;
39 int
40 getpublickey (const char *name, char *key)
42 static service_user *startp;
43 static public_function start_fct;
44 service_user *nip;
45 public_function fct;
46 enum nss_status status = NSS_STATUS_UNAVAIL;
47 int no_more;
49 if (startp == NULL)
51 no_more = __nss_publickey_lookup (&nip, "getpublickey", (void **) &fct);
52 if (no_more)
53 startp = (service_user *) -1;
54 else
56 startp = nip;
57 start_fct = fct;
60 else
62 fct = start_fct;
63 no_more = (nip = startp) == (service_user *) -1;
66 while (! no_more)
68 status = (*fct) (name, key, &errno);
70 no_more = __nss_next (&nip, "getpublickey", (void **) &fct, status, 0);
73 return status == NSS_STATUS_SUCCESS;
75 libc_hidden_def (getpublickey)
78 int
79 getsecretkey (const char *name, char *key, const char *passwd)
81 static service_user *startp;
82 static secret_function start_fct;
83 service_user *nip;
84 secret_function fct;
85 enum nss_status status = NSS_STATUS_UNAVAIL;
86 int no_more;
88 if (startp == NULL)
90 no_more = __nss_publickey_lookup (&nip, "getsecretkey", (void **) &fct);
91 if (no_more)
92 startp = (service_user *) -1;
93 else
95 startp = nip;
96 start_fct = fct;
99 else
101 fct = start_fct;
102 no_more = (nip = startp) == (service_user *) -1;
105 while (! no_more)
107 status = (*fct) (name, key, passwd, &errno);
109 no_more = __nss_next (&nip, "getsecretkey", (void **) &fct, status, 0);
112 return status == NSS_STATUS_SUCCESS;