components/openssl/openssl-1.0.0/wanboot-openssl/wanboot-stubs.c
changeset 763 45da4d38492e
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 /* Content of this file is only needed for wanboot. */
       
    26 #ifdef	_BOOT
       
    27 
       
    28 #include <sys/types.h>
       
    29 #include <dirent.h>
       
    30 #include <errno.h>
       
    31 #include <stddef.h>
       
    32 
       
    33 /*
       
    34  * In OpenSSL 0.9.7 the EVP_read_pw_string now calls into the new "ui"
       
    35  * routines of 0.9.7, which is not compiled in the standalone, so it is
       
    36  * stubbed out here to avoid having to add a bunch of #ifndef's elsewhere.
       
    37  */
       
    38 /* ARGSUSED */
       
    39 int
       
    40 EVP_read_pw_string_min(char *buf, int min, int len, const char *prompt, int
       
    41     verify)
       
    42 {
       
    43 	return (-1); /* failure */
       
    44 }
       
    45 
       
    46 /*
       
    47  * In standalone issetugid() is always false.
       
    48  */
       
    49 int
       
    50 OPENSSL_issetugid(void)
       
    51 {
       
    52 	return (1);
       
    53 }
       
    54 
       
    55 /*
       
    56  * Directory routines -- currently, the only consumer of these interfaces
       
    57  * is $SRC/common/openssl/ssl/ssl_cert.c, and it has fallback code in the
       
    58  * case of failure, so we just fail opendir() and stub out the rest.  At
       
    59  * some point, we may need to provide a real implementation.
       
    60  */
       
    61 /* ARGSUSED */
       
    62 DIR *
       
    63 opendir(const char *dirname)
       
    64 {
       
    65 	errno = EACCES;
       
    66 	return (NULL);
       
    67 }
       
    68 
       
    69 /* ARGSUSED */
       
    70 struct dirent *
       
    71 readdir(DIR *dirp)
       
    72 {
       
    73 	return (NULL);
       
    74 }
       
    75 
       
    76 /* ARGSUSED */
       
    77 int
       
    78 closedir(DIR *dirp)
       
    79 {
       
    80 	return (0);
       
    81 }
       
    82 
       
    83 /*
       
    84  * Atoi is used on multiple places in libcrypto.
       
    85  * This implementation is taken from stand-alone libsock library:
       
    86  * usr/src/stand/lib/sock/sock_test.c
       
    87  * Alternative solution: just extern it here, wanboot has -lsock anyway.
       
    88  */
       
    89 #ifndef	isdigit
       
    90 #define	isdigit(c) ((c) >= '0' && (c) <= '9')
       
    91 #endif
       
    92 
       
    93 #ifndef	isspace
       
    94 #define	isspace(c) ((c) == ' ' || (c) == '\t' || (c) == '\n' || \
       
    95 		    (c) == '\r' || (c) == '\f' || (c) == '\013')
       
    96 #endif
       
    97 int
       
    98 atoi(const char *p)
       
    99 {
       
   100 	int n;
       
   101 	int c = *p++, neg = 0;
       
   102 
       
   103 	while (isspace(c)) {
       
   104 		c = *p++;
       
   105 	}
       
   106 	if (!isdigit(c)) {
       
   107 		switch (c) {
       
   108 		case '-':
       
   109 			neg++;
       
   110 			/* FALLTHROUGH */
       
   111 		case '+':
       
   112 			c = *p++;
       
   113 		}
       
   114 	}
       
   115 	for (n = 0; isdigit(c); c = *p++) {
       
   116 		n *= 10; /* two steps to avoid unnecessary overflow */
       
   117 		n += '0' - c; /* accum neg to avoid surprises at MAX */
       
   118 	}
       
   119 	return (neg ? n : -n);
       
   120 }
       
   121 
       
   122 #endif	/* _BOOT */