112 #if !defined(_POSIX_C_SOURCE) && defined(OPENSSL_SYS_VMS)
113 #define _POSIX_C_SOURCE 2
121 #if !defined(OPENSSL_SYSNAME_WIN32) && !defined(NETWARE_CLIB)
124 #include <sys/types.h>
135 #ifndef OPENSSL_NO_ENGINE
138 #ifndef OPENSSL_NO_RSA
142 #ifndef OPENSSL_NO_JPAKE
143 #include <openssl/jpake.h>
151 static int WIN32_rename(
const char *from,
const char *to);
152 #define rename(from,to) WIN32_rename((from),(to))
163 static int set_table_opts(
unsigned long *
flags,
const char *
arg,
const NAME_EX_TBL *in_tbl);
164 static int set_multi_opts(
unsigned long *
flags,
const char *
arg,
const NAME_EX_TBL *in_tbl);
166 #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_RSA)
170 const char *key_descrip,
int format);
180 static char *buf=NULL;
181 static char **
arg=NULL;
188 if (fseek(fp,0,SEEK_END)==0)
189 len=ftell(fp), rewind(fp);
202 if (buf == NULL)
return(0);
204 len=fread(buf,1,len,fp);
205 if (len <= 1)
return(0);
222 while (*p && (*p !=
'\n')) p++;
228 while (*p && ((*p !=
' ') && (*p !=
'\t') && (*p !=
'\n')))
238 while (*p && ((*p ==
' ') || (*p ==
'\t') || (*p ==
'\n')))
248 while (*p && (*p !=
'\n')) p++;
262 if ((*s ==
'D') || (*s ==
'd'))
264 else if ((*s ==
'T') || (*s ==
't'))
266 else if ((*s ==
'N') || (*s ==
'n'))
268 else if ((*s ==
'S') || (*s ==
's'))
270 else if ((*s ==
'M') || (*s ==
'm'))
273 || (strcmp(s,
"PKCS12") == 0) || (strcmp(s,
"pkcs12") == 0)
274 || (strcmp(s,
"P12") == 0) || (strcmp(s,
"p12") == 0))
276 else if ((*s ==
'E') || (*s ==
'e'))
278 else if ((*s ==
'P') || (*s ==
'p'))
280 if (s[1] ==
'V' || s[1] ==
'v')
289 #if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16) || defined(OPENSSL_SYS_NETWARE)
297 for (i=n-1; i>0; i--)
299 if ((in[i] ==
'/') || (in[i] ==
'\\') || (in[i] ==
':'))
309 #if defined(OPENSSL_SYS_NETWARE)
311 if ((n > 4) && (p[n-4] ==
'.') &&
312 ((p[n-3] ==
'n') || (p[n-3] ==
'N')) &&
313 ((p[n-2] ==
'l') || (p[n-2] ==
'L')) &&
314 ((p[n-1] ==
'm') || (p[n-1] ==
'M')))
318 if ((n > 4) && (p[n-4] ==
'.') &&
319 ((p[n-3] ==
'e') || (p[n-3] ==
'E')) &&
320 ((p[n-2] ==
'x') || (p[n-2] ==
'X')) &&
321 ((p[n-1] ==
'e') || (p[n-1] ==
'E')))
330 if ((p[i] >=
'A') && (p[i] <=
'Z'))
338 #ifdef OPENSSL_SYS_VMS
344 while(*chars !=
'\0')
355 strncpy(out,p,size-1);
394 for (i=0; i<arg->
count; i++)
403 while (*p && ((*p ==
' ') || (*p ==
'\t') || (*p ==
'\n')))
408 if (num >= arg->
count)
411 int tlen = arg->
count + 20;
413 sizeof(
char *)*tlen);
419 for (i = num; i < arg->
count; i++)
425 if ((*p ==
'\'') || (*p ==
'\"'))
429 while (*p && (*p != i))
435 while (*p && ((*p !=
' ') &&
436 (*p !=
'\t') && (*p !=
'\n')))
477 static int ui_open(
UI *ui)
491 const char *password =
493 if (password && password[0] !=
'\0')
515 const char *password =
517 if (password && password[0] !=
'\0')
526 static int ui_close(
UI *ui)
552 const char *prompt_info = NULL;
553 const char *password = NULL;
566 res = strlen(password);
569 memcpy(buf, password, res);
590 if (ok >= 0 && verify)
630 static char *app_get_pass(
BIO *err,
char *arg,
int keepbio);
632 int app_passwd(
BIO *err,
char *arg1,
char *arg2,
char **pass1,
char **pass2)
635 if(!arg2 || !arg1 || strcmp(arg1, arg2)) same = 0;
638 *pass1 = app_get_pass(err, arg1, same);
639 if(!*pass1)
return 0;
640 }
else if(pass1) *pass1 = NULL;
642 *pass2 = app_get_pass(err, arg2, same ? 2 : 0);
643 if(!*pass2)
return 0;
644 }
else if(pass2) *pass2 = NULL;
648 static char *app_get_pass(
BIO *err,
char *arg,
int keepbio)
651 static BIO *pwdbio = NULL;
653 if(!strncmp(arg,
"pass:", 5))
return BUF_strdup(arg + 5);
654 if(!strncmp(arg,
"env:", 4)) {
655 tmp = getenv(arg + 4);
657 BIO_printf(err,
"Can't read environment variable %s\n", arg + 4);
662 if(!keepbio || !pwdbio) {
663 if(!strncmp(arg,
"file:", 5)) {
666 BIO_printf(err,
"Can't open file %s\n", arg + 5);
678 }
else if(!strncmp(arg,
"fd:", 3)) {
682 if((i < 0) || !pwdbio) {
683 BIO_printf(err,
"Can't access file descriptor %s\n", arg + 3);
690 }
else if(!strcmp(arg,
"stdin")) {
693 BIO_printf(err,
"Can't open BIO for stdin\n");
697 BIO_printf(err,
"Invalid password argument \"%s\"\n", arg);
707 BIO_printf(err,
"Error reading password from BIO\n");
710 tmp = strchr(tpass,
'\n');
726 if(!(sktmp = NCONF_get_section(conf, p))) {
727 BIO_printf(err,
"problem loading oid section %s\n", p);
733 BIO_printf(err,
"problem creating object %s=%s\n",
741 static int load_pkcs12(
BIO *err,
BIO *in,
const char *desc,
752 BIO_printf(err,
"Error loading PKCS12 file for %s\n", desc);
765 BIO_printf(err,
"Passpharse callback error for %s\n",
774 "Mac verify error (wrong password?) in PKCS12 file for %s\n", desc);
801 # ifndef OPENSSL_NO_SETVBUF_IONBF
802 setvbuf(stdin, NULL, _IONBF, 0);
828 nx->header->length) != 0))
830 NETSCAPE_X509_free(nx);
831 BIO_printf(err,
"Error reading header on certificate\n");
836 NETSCAPE_X509_free(nx);
839 x=PEM_read_bio_X509_AUX(cert,NULL,
843 if (!load_pkcs12(err, cert,cert_descrip, NULL, NULL,
848 BIO_printf(err,
"bad input format specified for %s\n",
855 BIO_printf(err,
"unable to load certificate\n");
863 const char *pass,
ENGINE *
e,
const char *key_descrip)
872 if (file == NULL && (!maybe_stdin || format ==
FORMAT_ENGINE))
877 #ifndef OPENSSL_NO_ENGINE
885 ui_method, &cb_data);
888 BIO_printf(err,
"cannot load %s from engine\n",key_descrip);
901 if (file == NULL && maybe_stdin)
904 # ifndef OPENSSL_NO_SETVBUF_IONBF
905 setvbuf(stdin, NULL, _IONBF, 0);
927 #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_RSA)
929 pkey = load_netscape_key(err, key, file, key_descrip, format);
933 if (!load_pkcs12(err, key, key_descrip,
938 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DSA) && !defined (OPENSSL_NO_RC4)
947 BIO_printf(err,
"bad input format specified for key file\n");
954 BIO_printf(err,
"unable to load %s\n", key_descrip);
961 const char *pass,
ENGINE *
e,
const char *key_descrip)
970 if (file == NULL && (!maybe_stdin || format ==
FORMAT_ENGINE))
975 #ifndef OPENSSL_NO_ENGINE
982 ui_method, &cb_data);
992 if (file == NULL && maybe_stdin)
995 # ifndef OPENSSL_NO_SETVBUF_IONBF
996 setvbuf(stdin, NULL, _IONBF, 0);
1013 #ifndef OPENSSL_NO_RSA
1031 rsa = PEM_read_bio_RSAPublicKey(key, NULL,
1046 pkey=PEM_read_bio_PUBKEY(key,NULL,
1049 #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_RSA)
1051 pkey = load_netscape_key(err, key, file, key_descrip, format);
1053 #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DSA)
1059 BIO_printf(err,
"bad input format specified for key file\n");
1065 BIO_printf(err,
"unable to load %s\n", key_descrip);
1069 #if !defined(OPENSSL_NO_RC4) && !defined(OPENSSL_NO_RSA)
1071 load_netscape_key(
BIO *err,
BIO *
key,
const char *file,
1072 const char *key_descrip,
int format)
1077 const unsigned char *
p;
1083 if (buf == NULL || pkey == NULL)
1100 p=(
unsigned char *)buf->
data;
1115 static int load_certs_crls(
BIO *err,
const char *file,
int format,
1116 const char *pass,
ENGINE *
e,
const char *desc,
1131 BIO_printf(err,
"bad input format specified for %s\n", desc);
1143 desc, file ? file :
"stdin");
1148 xis = PEM_X509_INFO_read_bio(bio, NULL,
1170 if (xi->
x509 && pcerts)
1176 if (xi->
crl && pcrls)
1208 pcerts ?
"certificates" :
"CRLs");
1215 const char *pass,
ENGINE *e,
const char *desc)
1218 if (!load_certs_crls(err, file, format, pass, e, desc, &certs, NULL))
1224 const char *pass,
ENGINE *e,
const char *desc)
1227 if (!load_certs_crls(err, file, format, pass, e, desc, NULL, &crls))
1232 #define X509V3_EXT_UNKNOWN_MASK (0xfL << 16)
1234 #define X509V3_EXT_DEFAULT 0
1236 #define X509V3_EXT_ERROR_UNKNOWN (1L << 16)
1238 #define X509V3_EXT_PARSE_UNKNOWN (2L << 16)
1240 #define X509V3_EXT_DUMP_UNKNOWN (3L << 16)
1242 #define X509_FLAG_CA (X509_FLAG_NO_ISSUER | X509_FLAG_NO_PUBKEY | \
1243 X509_FLAG_NO_HEADER | X509_FLAG_NO_VERSION)
1268 return set_multi_opts(flags, arg, cert_tbl);
1303 return set_multi_opts(flags, arg, ex_tbl);
1308 if (!strcasecmp(arg,
"none"))
1310 else if (!strcasecmp(arg,
"copy"))
1312 else if (!strcasecmp(arg,
"copyall"))
1324 int i, idx, ret = 0;
1327 exts = X509_REQ_get_extensions(req);
1342 X509_EXTENSION_free(tmpext);
1344 }
while (idx != -1);
1362 static int set_multi_opts(
unsigned long *
flags,
const char *arg,
const NAME_EX_TBL *in_tbl)
1368 vals = X509V3_parse_list(arg);
1371 if (!set_table_opts(flags, val->
name, in_tbl))
1378 static int set_table_opts(
unsigned long *flags,
const char *arg,
const NAME_EX_TBL *in_tbl)
1387 }
else if (c ==
'+') {
1392 for(ptbl = in_tbl; ptbl->
name; ptbl++) {
1393 if(!strcasecmp(arg, ptbl->
name)) {
1394 *flags &= ~ptbl->
mask;
1395 if(c) *flags |= ptbl->
flag;
1396 else *flags &= ~ptbl->
flag;
1432 if (lookup == NULL)
goto end;
1435 BIO_printf(bp,
"Error loading file %s\n", CAfile);
1441 if (lookup == NULL)
goto end;
1444 BIO_printf(bp,
"Error loading directory %s\n", CApath);
1456 #ifndef OPENSSL_NO_ENGINE
1458 static ENGINE *try_load_engine(
BIO *err,
const char *engine,
int debug)
1479 if(strcmp(engine,
"auto") == 0)
1481 BIO_printf(err,
"enabling auto ENGINE support\n");
1486 && (e = try_load_engine(err, engine, debug)) == NULL)
1488 BIO_printf(err,
"invalid engine \"%s\"\n", engine);
1517 static int load_config_called = 0;
1518 if (load_config_called)
1520 load_config_called = 1;
1530 BIO_printf(err,
"Error configuring OpenSSL\n");
1546 #ifndef OPENSSL_SYS_VMS
1559 while (*n ==
'0') n++;
1567 for (aa=a[
DB_serial]; *aa ==
'0'; aa++);
1568 for (bb=b[
DB_serial]; *bb ==
'0'; bb++);
1569 return(strcmp(aa,bb));
1572 static int index_name_qual(
char **a)
1573 {
return(a[0][0] ==
'V'); }
1579 {
return(strcmp(a[
DB_name], b[DB_name])); }
1596 ai=ASN1_INTEGER_new();
1597 if (ai == NULL)
goto err;
1642 if (ai != NULL) ASN1_INTEGER_free(ai);
1655 j = strlen(serialfile);
1657 j = strlen(serialfile) + strlen(suffix) + 1;
1668 #ifndef OPENSSL_SYS_VMS
1669 j =
BIO_snprintf(buf[0],
sizeof buf[0],
"%s.%s", serialfile, suffix);
1671 j =
BIO_snprintf(buf[0],
sizeof buf[0],
"%s-%s", serialfile, suffix);
1704 if (ai != NULL) ASN1_INTEGER_free(ai);
1713 i = strlen(serialfile) + strlen(old_suffix);
1714 j = strlen(serialfile) + strlen(new_suffix);
1722 #ifndef OPENSSL_SYS_VMS
1724 serialfile, new_suffix);
1727 serialfile, new_suffix);
1729 #ifndef OPENSSL_SYS_VMS
1731 serialfile, old_suffix);
1734 serialfile, old_suffix);
1738 serialfile, buf[1]);
1740 if (rename(serialfile,buf[1]) < 0 &&
errno != ENOENT
1746 "unable to rename %s to %s\n",
1747 serialfile, buf[1]);
1755 if (rename(buf[0],serialfile) < 0)
1758 "unable to rename %s to %s\n",
1761 rename(buf[1],serialfile);
1798 CA_DB *retdb = NULL;
1801 CONF *dbattr_conf = NULL;
1819 #ifndef OPENSSL_SYS_VMS
1820 BIO_snprintf(buf[0],
sizeof buf[0],
"%s.attr", dbfile);
1822 BIO_snprintf(buf[0],
sizeof buf[0],
"%s-attr", dbfile);
1825 if (
NCONF_load(dbattr_conf,buf[0],&errorline) <= 0)
1830 "error on line %ld of db attribute file '%s'\n"
1843 fprintf(stderr,
"Out of memory\n");
1882 "error creating serial number index:(%ld,%ld,%ld)\n",
1911 j = strlen(dbfile) + strlen(suffix);
1918 #ifndef OPENSSL_SYS_VMS
1919 j =
BIO_snprintf(buf[2],
sizeof buf[2],
"%s.attr", dbfile);
1921 j =
BIO_snprintf(buf[2],
sizeof buf[2],
"%s-attr", dbfile);
1923 #ifndef OPENSSL_SYS_VMS
1924 j =
BIO_snprintf(buf[1],
sizeof buf[1],
"%s.attr.%s", dbfile, suffix);
1926 j =
BIO_snprintf(buf[1],
sizeof buf[1],
"%s-attr-%s", dbfile, suffix);
1928 #ifndef OPENSSL_SYS_VMS
1929 j =
BIO_snprintf(buf[0],
sizeof buf[0],
"%s.%s", dbfile, suffix);
1931 j =
BIO_snprintf(buf[0],
sizeof buf[0],
"%s-%s", dbfile, suffix);
1943 if (j <= 0)
goto err;
1966 int rotate_index(
const char *dbfile,
const char *new_suffix,
const char *old_suffix)
1971 i = strlen(dbfile) + strlen(old_suffix);
1972 j = strlen(dbfile) + strlen(new_suffix);
1980 #ifndef OPENSSL_SYS_VMS
1981 j =
BIO_snprintf(buf[4],
sizeof buf[4],
"%s.attr", dbfile);
1983 j =
BIO_snprintf(buf[4],
sizeof buf[4],
"%s-attr", dbfile);
1985 #ifndef OPENSSL_SYS_VMS
1987 dbfile, new_suffix);
1990 dbfile, new_suffix);
1992 #ifndef OPENSSL_SYS_VMS
1994 dbfile, new_suffix);
1997 dbfile, new_suffix);
1999 #ifndef OPENSSL_SYS_VMS
2001 dbfile, old_suffix);
2004 dbfile, old_suffix);
2006 #ifndef OPENSSL_SYS_VMS
2008 dbfile, old_suffix);
2011 dbfile, old_suffix);
2017 if (rename(dbfile,buf[1]) < 0 &&
errno != ENOENT
2023 "unable to rename %s to %s\n",
2032 if (rename(buf[0],dbfile) < 0)
2035 "unable to rename %s to %s\n",
2038 rename(buf[1],dbfile);
2045 if (rename(buf[4],buf[3]) < 0 &&
errno != ENOENT
2051 "unable to rename %s to %s\n",
2054 rename(dbfile,buf[0]);
2055 rename(buf[1],dbfile);
2062 if (rename(buf[2],buf[4]) < 0)
2065 "unable to rename %s to %s\n",
2068 rename(buf[3],buf[4]);
2069 rename(dbfile,buf[0]);
2070 rename(buf[1],dbfile);
2122 size_t buflen = strlen(subject)+1;
2124 size_t max_ne = buflen / 2 + 1;
2129 char *sp = subject, *
bp = buf;
2135 if (!buf || !ne_types || !ne_values)
2141 if (*subject !=
'/')
2154 ne_types[ne_num] =
bp;
2167 else if (*sp ==
'=')
2178 BIO_printf(
bio_err,
"end of string encountered while processing type of subject name element #%d\n", ne_num);
2181 ne_values[ne_num] =
bp;
2194 else if (*sp ==
'/')
2201 else if (*sp ==
'+' && multirdn)
2205 mval[ne_num+1] = -1;
2215 if (!(n = X509_NAME_new()))
2218 for (i = 0; i < ne_num; i++)
2222 BIO_printf(
bio_err,
"Subject Attribute %s has no known NID, skipped\n", ne_types[i]);
2228 BIO_printf(
bio_err,
"No value provided for Subject Attribute %s, skipped\n", ne_types[i]);
2256 unsigned long flags = 0;
2258 int purpose = 0, depth = -1;
2259 char **oldargs = *pargs;
2260 char *arg = **pargs, *argn = (*pargs)[1];
2262 if (!strcmp(arg,
"-policy"))
2278 else if (strcmp(arg,
"-purpose") == 0)
2299 else if (strcmp(arg,
"-verify_depth") == 0)
2314 else if (strcmp(arg,
"-attime") == 0)
2323 if (sscanf(argn,
"%li", ×tamp) != 1)
2326 "Error parsing timestamp %s\n",
2331 at_time = (time_t) timestamp;
2335 else if (!strcmp(arg,
"-ignore_critical"))
2337 else if (!strcmp(arg,
"-issuer_checks"))
2339 else if (!strcmp(arg,
"-crl_check"))
2341 else if (!strcmp(arg,
"-crl_check_all"))
2343 else if (!strcmp(arg,
"-policy_check"))
2345 else if (!strcmp(arg,
"-explicit_policy"))
2347 else if (!strcmp(arg,
"-inhibit_any"))
2349 else if (!strcmp(arg,
"-inhibit_map"))
2351 else if (!strcmp(arg,
"-x509_strict"))
2353 else if (!strcmp(arg,
"-extended_crl"))
2355 else if (!strcmp(arg,
"-use_deltas"))
2357 else if (!strcmp(arg,
"-policy_print"))
2359 else if (!strcmp(arg,
"-check_ss_sig"))
2397 *pargc -= *pargs - oldargs;
2411 unsigned char tbuf[1024];
2417 if ((maxlen != -1) && maxlen < 1024)
2443 char *stmp, *vtmp = NULL;
2447 vtmp = strchr(stmp,
':');
2458 static void nodes_print(
BIO *out,
const char *name,
2480 int explicit_policy;
2490 BIO_printf(out,
"Require explicit Policy: %s\n",
2491 explicit_policy ?
"True" :
"False");
2493 nodes_print(out,
"Authority", X509_policy_tree_get0_policies(tree));
2494 nodes_print(out,
"User", X509_policy_tree_get0_user_policies(tree));
2499 #if !defined(OPENSSL_NO_JPAKE) && !defined(OPENSSL_NO_PSK)
2501 static JPAKE_CTX *jpake_init(
const char *us,
const char *them,
2511 BN_hex2bn(&p,
"F9E5B365665EA7A05A9C534502780FEE6F1AB5BD4F49947FD036DBD7E905269AF46EF28B0FC07487EE4F5D20FB3C0AF8E700F3A2FA3414970CBED44FEDFF80CE78D800F184BB82435D137AADA2C6C16523247930A63B85661D1FC817A51ACD96168E95898A1F83A79FFB529368AA7833ABD1B0C3AEDDB14D2E1A2F71D99F763F");
2517 BN_bin2bn((
const unsigned char *)secret, strlen(secret), bnsecret);
2538 static void jpake_send_step1(
BIO *bconn,
JPAKE_CTX *ctx)
2544 jpake_send_part(bconn, &s1.
p1);
2545 jpake_send_part(bconn, &s1.
p2);
2550 static void jpake_send_step2(
BIO *bconn,
JPAKE_CTX *ctx)
2556 jpake_send_part(bconn, &s2);
2561 static void jpake_send_step3a(
BIO *bconn,
JPAKE_CTX *ctx)
2572 static void jpake_send_step3b(
BIO *bconn,
JPAKE_CTX *ctx)
2583 static void readbn(
BIGNUM **bn,
BIO *bconn)
2588 l =
BIO_gets(bconn, buf,
sizeof buf);
2590 assert(buf[l-1] ==
'\n');
2597 readbn(&p->
gx, bconn);
2598 readbn(&p->
zkpx.
gr, bconn);
2599 readbn(&p->
zkpx.
b, bconn);
2602 static void jpake_receive_step1(
JPAKE_CTX *ctx,
BIO *bconn)
2607 jpake_receive_part(&s1.
p1, bconn);
2608 jpake_receive_part(&s1.
p2, bconn);
2617 static void jpake_receive_step2(
JPAKE_CTX *ctx,
BIO *bconn)
2622 jpake_receive_part(&s2, bconn);
2631 static void jpake_receive_step3a(
JPAKE_CTX *ctx,
BIO *bconn)
2638 assert(l ==
sizeof s3a.
hhk);
2647 static void jpake_receive_step3b(
JPAKE_CTX *ctx,
BIO *bconn)
2654 assert(l ==
sizeof s3b.
hk);
2668 BIO_puts(out,
"Authenticating with JPAKE\n");
2670 ctx = jpake_init(
"client",
"server", secret);
2675 jpake_send_step1(bconn, ctx);
2676 jpake_receive_step1(ctx, bconn);
2677 jpake_send_step2(bconn, ctx);
2678 jpake_receive_step2(ctx, bconn);
2679 jpake_send_step3a(bconn, ctx);
2680 jpake_receive_step3b(ctx, bconn);
2682 BIO_puts(out,
"JPAKE authentication succeeded, setting PSK\n");
2697 BIO_puts(out,
"Authenticating with JPAKE\n");
2699 ctx = jpake_init(
"server",
"client", secret);
2704 jpake_receive_step1(ctx, bconn);
2705 jpake_send_step1(bconn, ctx);
2706 jpake_receive_step2(ctx, bconn);
2707 jpake_send_step2(bconn, ctx);
2708 jpake_receive_step3a(ctx, bconn);
2709 jpake_send_step3b(bconn, ctx);
2711 BIO_puts(out,
"JPAKE authentication succeeded, setting PSK\n");
2723 #if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
2736 size_t i, start = 0;
2746 for (i = 0; i <=
len; ++i)
2748 if (i == len || in[i] ==
',')
2750 if (i - start > 255)
2755 out[start] = i - start;
2773 # define fileno(a) (int)_fileno(a)
2776 # include <windows.h>
2779 static int WIN32_rename(
const char *from,
const char *to)
2781 TCHAR *tfrom=NULL,*tto;
2785 if (
sizeof(TCHAR) == 1)
2787 tfrom = (TCHAR *)from;
2792 size_t i,flen=strlen(from)+1,tlen=strlen(to)+1;
2793 tfrom = (TCHAR *)malloc(
sizeof(TCHAR)*(flen+tlen));
2794 if (tfrom==NULL)
goto err;
2796 #if !defined(_WIN32_WCE) || _WIN32_WCE>=101
2797 if (!MultiByteToWideChar(CP_ACP,0,from,flen,(WCHAR *)tfrom,flen))
2799 for (i=0;i<flen;i++) tfrom[i]=(TCHAR)from[i];
2800 #if !defined(_WIN32_WCE) || _WIN32_WCE>=101
2801 if (!MultiByteToWideChar(CP_ACP,0,to, tlen,(WCHAR *)tto, tlen))
2803 for (i=0;i<tlen;i++) tto[i] =(TCHAR)to[i];
2806 if (MoveFile(tfrom,tto))
goto ok;
2808 if (err==ERROR_ALREADY_EXISTS || err==ERROR_FILE_EXISTS)
2810 if (DeleteFile(tto) && MoveFile(tfrom,tto))
2814 if (err==ERROR_FILE_NOT_FOUND || err==ERROR_PATH_NOT_FOUND)
2816 else if (err==ERROR_ACCESS_DENIED)
2823 if (tfrom!=NULL && tfrom!=(TCHAR *)from) free(tfrom);
2834 static ULARGE_INTEGER tmstart;
2835 static int warning=1;
2837 static HANDLE proc=NULL;
2841 if (GetVersion() < 0x80000000)
2842 proc = OpenProcess(PROCESS_QUERY_INFORMATION,FALSE,
2843 GetCurrentProcessId());
2844 if (proc==NULL) proc = (HANDLE)-1;
2847 if (usertime && proc!=(HANDLE)-1)
2850 GetProcessTimes(proc,&junk,&junk,&junk,&now);
2857 if (usertime && warning)
2860 "this program on idle system.\n");
2863 GetSystemTime(&systime);
2864 SystemTimeToFileTime(&systime,&now);
2869 tmstart.u.LowPart = now.dwLowDateTime;
2870 tmstart.u.HighPart = now.dwHighDateTime;
2873 ULARGE_INTEGER tmstop;
2875 tmstop.u.LowPart = now.dwLowDateTime;
2876 tmstop.u.HighPart = now.dwHighDateTime;
2878 ret = (__int64)(tmstop.QuadPart - tmstart.QuadPart)*1e-7;
2884 #elif defined(OPENSSL_SYS_NETWARE)
2890 static clock_t tmstart;
2891 static int warning=1;
2893 if (usertime && warning)
2896 "this program on idle system.\n");
2900 if (stop==
TM_START) tmstart = clock();
2901 else ret = (clock()-tmstart)/(
double)CLOCKS_PER_SEC;
2906 #elif defined(OPENSSL_SYSTEM_VXWORKS)
2912 #ifdef CLOCK_REALTIME
2913 static struct timespec tmstart;
2914 struct timespec now;
2916 static unsigned long tmstart;
2919 static int warning=1;
2921 if (usertime && warning)
2924 "this program on idle system.\n");
2928 #ifdef CLOCK_REALTIME
2929 clock_gettime(CLOCK_REALTIME,&now);
2931 else ret = ( (now.tv_sec+now.tv_nsec*1e-9)
2932 - (tmstart.tv_sec+tmstart.tv_nsec*1e-9) );
2936 else ret = (now - tmstart)/(
double)sysClkRateGet();
2941 #elif defined(OPENSSL_SYSTEM_VMS)
2947 static clock_t tmstart;
2954 if (usertime) now = rus.tms_utime;
2960 gettimeofday(&tv,NULL);
2962 (
unsigned long long)tv.tv_sec*CLK_TCK +
2963 (
unsigned long long)tv.tv_usec*(1000000/CLK_TCK)
2968 else ret = (now - tmstart)/(
double)(CLK_TCK);
2973 #elif defined(_SC_CLK_TCK)
2974 #include <sys/times.h>
2980 clock_t now = times(&rus);
2981 static clock_t tmstart;
2983 if (usertime) now = rus.tms_utime;
2988 long int tck = sysconf(_SC_CLK_TCK);
2989 ret = (now - tmstart)/(
double)tck;
2996 #include <sys/time.h>
2997 #include <sys/resource.h>
3004 static struct timeval tmstart;
3006 if (usertime) getrusage(RUSAGE_SELF,&rus), now = rus.ru_utime;
3007 else gettimeofday(&now,NULL);
3010 else ret = ( (now.tv_sec+now.tv_usec*1e-6)
3011 - (tmstart.tv_sec+tmstart.tv_usec*1e-6) );
3022 WIN32_FIND_DATA FileData;
3023 #if defined(UNICODE) || defined(_UNICODE)
3024 size_t i, len_0 = strlen(name)+1;
3026 if (len_0 >
sizeof(FileData.cFileName)/
sizeof(FileData.cFileName[0]))
3029 #if !defined(_WIN32_WCE) || _WIN32_WCE>=101
3030 if (!MultiByteToWideChar(CP_ACP,0,name,len_0,FileData.cFileName,len_0))
3032 for (i=0;i<len_0;i++)
3033 FileData.cFileName[i] = (WCHAR)name[i];
3035 hList = FindFirstFile(FileData.cFileName,&FileData);
3037 hList = FindFirstFile(name,&FileData);
3039 if (hList == INVALID_HANDLE_VALUE)
return -1;
3041 return ((FileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)!=0);
3044 #include <sys/stat.h>
3046 # if defined(_S_IFMT) && defined(_S_IFDIR)
3047 # define S_ISDIR(a) (((a) & _S_IFMT) == _S_IFDIR)
3049 # define S_ISDIR(a) (((a) & S_IFMT) == S_IFDIR)
3055 #if defined(S_ISDIR)
3058 if (stat(name,&st)==0)
return S_ISDIR(st.st_mode);
3067 #if defined(_WIN32) && defined(STD_INPUT_HANDLE)
3071 if (ReadFile(GetStdHandle(STD_INPUT_HANDLE),buf,siz,&n,NULL))
3077 {
return read(fileno(stdin),buf,siz); }
3080 #if defined(_WIN32) && defined(STD_OUTPUT_HANDLE)
3084 if (WriteFile(GetStdHandle(STD_OUTPUT_HANDLE),buf,siz,&n,NULL))
3090 {
return write(fileno(stdout),buf,siz); }