components/openssl/openssl-1.0.0-wanboot/files/stubs.c
changeset 763 45da4d38492e
parent 762 d87f60e41094
child 764 1927dad105b7
equal deleted inserted replaced
762:d87f60e41094 763:45da4d38492e
     1 /*
       
     2  * CDDL HEADER START
       
     3  *
       
     4  * The contents of this file are subject to the terms of the
       
     5  * Common Development and Distribution License (the "License").
       
     6  * You may not use this file except in compliance with the License.
       
     7  *
       
     8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
       
     9  * or http://www.opensolaris.org/os/licensing.
       
    10  * See the License for the specific language governing permissions
       
    11  * and limitations under the License.
       
    12  *
       
    13  * When distributing Covered Code, include this CDDL HEADER in each
       
    14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
       
    15  * If applicable, add the following below this CDDL HEADER, with the
       
    16  * fields enclosed by brackets "[]" replaced with your own identifying
       
    17  * information: Portions Copyright [yyyy] [name of copyright owner]
       
    18  *
       
    19  * CDDL HEADER END
       
    20  */
       
    21 /*
       
    22  * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
       
    23  */
       
    24 
       
    25 
       
    26 #include <sys/types.h>
       
    27 #include <dirent.h>
       
    28 #include <errno.h>
       
    29 #include <stddef.h>
       
    30 
       
    31 /*
       
    32  * In OpenSSL 0.9.7 the EVP_read_pw_string now calls into the new "ui"
       
    33  * routines of 0.9.7, which is not compiled in the standalone, so it is
       
    34  * stubbed out here to avoid having to add a bunch of #ifndef's elsewhere.
       
    35  */
       
    36 /* ARGSUSED */
       
    37 int
       
    38 EVP_read_pw_string_min(char *buf, int min, int len, const char *prompt, int
       
    39     verify)
       
    40 {
       
    41 	return (-1); /* failure */
       
    42 }
       
    43 
       
    44 /*
       
    45  * In standalone issetugid() is always false.
       
    46  */
       
    47 int
       
    48 OPENSSL_issetugid(void)
       
    49 {
       
    50 	return (1);
       
    51 }
       
    52 
       
    53 /*
       
    54  * Directory routines -- currently, the only consumer of these interfaces
       
    55  * is $SRC/common/openssl/ssl/ssl_cert.c, and it has fallback code in the
       
    56  * case of failure, so we just fail opendir() and stub out the rest.  At
       
    57  * some point, we may need to provide a real implementation.
       
    58  */
       
    59 /* ARGSUSED */
       
    60 DIR *
       
    61 opendir(const char *dirname)
       
    62 {
       
    63 	errno = EACCES;
       
    64 	return (NULL);
       
    65 }
       
    66 
       
    67 /* ARGSUSED */
       
    68 struct dirent *
       
    69 readdir(DIR *dirp)
       
    70 {
       
    71 	return (NULL);
       
    72 }
       
    73 
       
    74 /* ARGSUSED */
       
    75 int
       
    76 closedir(DIR *dirp)
       
    77 {
       
    78 	return (0);
       
    79 }
       
    80 
       
    81 /*
       
    82  * Atoi is used on multiple places in libcrypto.
       
    83  * This implementation is taken from stand-alone libsock library:
       
    84  * usr/src/stand/lib/sock/sock_test.c
       
    85  * Alternative solution: just extern it here, wanboot has -lsock anyway.
       
    86  */
       
    87 #ifndef	isdigit
       
    88 #define	isdigit(c) ((c) >= '0' && (c) <= '9')
       
    89 #endif
       
    90 
       
    91 #ifndef	isspace
       
    92 #define	isspace(c) ((c) == ' ' || (c) == '\t' || (c) == '\n' || \
       
    93 		    (c) == '\r' || (c) == '\f' || (c) == '\013')
       
    94 #endif
       
    95 int
       
    96 atoi(const char *p)
       
    97 {
       
    98 	int n;
       
    99 	int c = *p++, neg = 0;
       
   100 
       
   101 	while (isspace(c)) {
       
   102 		c = *p++;
       
   103 	}
       
   104 	if (!isdigit(c)) {
       
   105 		switch (c) {
       
   106 		case '-':
       
   107 			neg++;
       
   108 			/* FALLTHROUGH */
       
   109 		case '+':
       
   110 			c = *p++;
       
   111 		}
       
   112 	}
       
   113 	for (n = 0; isdigit(c); c = *p++) {
       
   114 		n *= 10; /* two steps to avoid unnecessary overflow */
       
   115 		n += '0' - c; /* accum neg to avoid surprises at MAX */
       
   116 	}
       
   117 	return (neg ? n : -n);
       
   118 }