ReactOS 0.4.15-dev-5664-g3bf4ef6
getpublickey.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009, Sun Microsystems, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * - Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * - Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 * - Neither the name of Sun Microsystems, Inc. nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28/*
29#include <sys/cdefs.h>
30*/
31
32/*
33 * publickey.c
34 * Copyright (C) 1986, Sun Microsystems, Inc.
35 */
36
37/*
38 * Public key lookup routines
39 */
40#include <wintirpc.h>
41#ifndef _WIN32
42#include <stdio.h>
43//#include <pwd.h>
44#include <rpc/rpc.h>
45#include <rpc/key_prot.h>
46#include <rpcsvc/yp_prot.h>
47#include <rpcsvc/ypclnt.h>
48#include <string.h>
49#include <stdlib.h>
50
51#define PKFILE "/etc/publickey"
52
53/*
54 * Hack to let ypserv/rpc.nisd use AUTH_DES.
55 */
57
58/*
59 * Get somebody's public key
60 */
61int
62__getpublickey_real(netname, publickey)
63 char *netname;
64 char *publickey;
65{
66 char lookup[3 * HEXKEYBYTES];
67 char *p;
68
69 if (publickey == NULL)
70 return (0);
71 if (!getpublicandprivatekey(netname, lookup))
72 return (0);
73 p = strchr(lookup, ':');
74 if (p == NULL) {
75 return (0);
76 }
77 *p = '\0';
78 (void) strncpy(publickey, lookup, HEXKEYBYTES);
79 publickey[HEXKEYBYTES] = '\0';
80 return (1);
81}
82
83/*
84 * reads the file /etc/publickey looking for a + to optionally go to the
85 * yellow pages
86 */
87
88int
90 char *key;
91 char *ret;
92{
93 char buf[1024]; /* big enough */
94 char *res;
95 FILE *fd;
96 char *mkey;
97 char *mval;
98
99 fd = fopen(PKFILE, "r");
100 if (fd == NULL)
101 return (0);
102 for (;;) {
103 res = fgets(buf, sizeof(buf), fd);
104 if (res == NULL) {
105 fclose(fd);
106 return (0);
107 }
108 if (res[0] == '#')
109 continue;
110 else if (res[0] == '+') {
111#ifdef YP
112 char *PKMAP = "publickey.byname";
113 char *lookup;
114 char *domain;
115 int err;
116 int len;
117
118 err = yp_get_default_domain(&domain);
119 if (err) {
120 continue;
121 }
122 lookup = NULL;
123 err = yp_match(domain, PKMAP, key, strlen(key), &lookup, &len);
124 if (err) {
125#ifdef DEBUG
126 fprintf(stderr, "match failed error %d\n", err);
127#endif
128 continue;
129 }
130 lookup[len] = 0;
131 strcpy(ret, lookup);
132 fclose(fd);
133 free(lookup);
134 return (2);
135#else /* YP */
136#ifdef DEBUG
138"Bad record in %s '+' -- NIS not supported in this library copy\n", PKFILE);
139#endif /* DEBUG */
140 continue;
141#endif /* YP */
142 } else {
143 mkey = strsep(&res, "\t ");
144 if (mkey == NULL) {
146 "Bad record in %s -- %s", PKFILE, buf);
147 continue;
148 }
149 do {
150 mval = strsep(&res, " \t#\n");
151 } while (mval != NULL && !*mval);
152 if (mval == NULL) {
154 "Bad record in %s val problem - %s", PKFILE, buf);
155 continue;
156 }
157 if (strcmp(mkey, key) == 0) {
158 strcpy(ret, mval);
159 fclose(fd);
160 return (1);
161 }
162 }
163 }
164}
165
166int getpublickey(netname, publickey)
167 const char *netname;
168 char *publickey;
169{
171 return(__getpublickey_LOCAL(netname, publickey));
172 else
173 return(__getpublickey_real(netname, publickey));
174}
175#endif /* ! _WIN32 */
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
char * strchr(const char *String, int ch)
Definition: utclib.c:501
#define free
Definition: debug_ros.c:5
#define NULL
Definition: types.h:112
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
static ULONG lookup[16]
Definition: vga.c:38
int __getpublickey_real(char *netname, char *publickey)
Definition: getpublickey.c:62
#define PKFILE
Definition: getpublickey.c:51
int(* __getpublickey_LOCAL)()=0
Definition: getpublickey.c:56
int getpublicandprivatekey(char *key, char *ret)
Definition: getpublickey.c:89
int getpublickey(char *netname, char *publickey) const
Definition: getpublickey.c:166
GLuint res
Definition: glext.h:9613
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLfloat GLfloat p
Definition: glext.h:8902
GLenum GLsizei len
Definition: glext.h:6722
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP char *__cdecl fgets(_Out_writes_z_(_MaxCount) char *_Buf, _In_ int _MaxCount, _Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
#define err(...)
static int fd
Definition: io.c:51
Definition: cookie.c:42
Definition: copy.c:22
int ret