1*28e78c13Sjsg.\" $OpenBSD: BIO_dup_chain.3,v 1.2 2023/04/09 06:27:52 jsg Exp $ 253d779efSschwarze.\" 353d779efSschwarze.\" Copyright (c) 2022 Ingo Schwarze <schwarze@openbsd.org> 453d779efSschwarze.\" 553d779efSschwarze.\" Permission to use, copy, modify, and distribute this software for any 653d779efSschwarze.\" purpose with or without fee is hereby granted, provided that the above 753d779efSschwarze.\" copyright notice and this permission notice appear in all copies. 853d779efSschwarze.\" 953d779efSschwarze.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 1053d779efSschwarze.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 1153d779efSschwarze.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 1253d779efSschwarze.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 1353d779efSschwarze.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 1453d779efSschwarze.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 1553d779efSschwarze.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 1653d779efSschwarze.\" 17*28e78c13Sjsg.Dd $Mdocdate: April 9 2023 $ 1853d779efSschwarze.Dt BIO_DUP_CHAIN 3 1953d779efSschwarze.Os 2053d779efSschwarze.Sh NAME 2153d779efSschwarze.Nm BIO_dup_chain , 2253d779efSschwarze.Nm BIO_dup_state 2353d779efSschwarze.Nd copy a BIO chain 2453d779efSschwarze.Sh SYNOPSIS 2553d779efSschwarze.In openssl/bio.h 2653d779efSschwarze.Ft BIO * 2753d779efSschwarze.Fn BIO_dup_chain "BIO *b" 2853d779efSschwarze.Ft long 2953d779efSschwarze.Fn BIO_dup_state "BIO *b" "BIO *new_bio" 3053d779efSschwarze.Sh DESCRIPTION 3153d779efSschwarze.Fn BIO_dup_chain 3253d779efSschwarzecopies the chain starting at 3353d779efSschwarze.Fa b 3453d779efSschwarzeby iteratively copying 3553d779efSschwarze.Fa b 3653d779efSschwarzeand all the BIOs following it 3753d779efSschwarzeand joining the copies in the same order as in the original chain. 3853d779efSschwarzeThe copying operation is neither a deep copy nor a shallow copy. 3953d779efSschwarze.Pp 4053d779efSschwarzeSome parts of the state of each BIO are copied, 4153d779efSschwarzein particular with respect to the values returned by 4253d779efSschwarze.Xr BIO_get_init 3 , 4353d779efSschwarze.Xr BIO_test_flags 3 , 4453d779efSschwarzeand 4553d779efSschwarze.Xr BIO_get_shutdown 3 . 4653d779efSschwarze.\" XXX new_bio->num = bio->num; 4753d779efSschwarzeOther parts of the state of the BIOs are not copied 4853d779efSschwarzebut instead initialized to 0, 4953d779efSschwarzein particular with respect to the values returned by 5053d779efSschwarze.Xr BIO_number_read 3 , 5153d779efSschwarze.Xr BIO_number_written 3 , 5253d779efSschwarzeand 5353d779efSschwarze.Xr BIO_get_retry_reason 3 . 5453d779efSschwarzeThe custom data pointer that can be used by custom BIO types 5553d779efSschwarzeand that can be retrieved with 5653d779efSschwarze.Xr BIO_get_data 3 57*28e78c13Sjsgis set to 5853d779efSschwarze.Dv NULL 5953d779efSschwarzein the copied BIO objects rather than copied. 6053d779efSschwarzeThe reference count of each BIO in the copied chain is set to 1. 6153d779efSschwarze.Pp 6253d779efSschwarzeFor each BIO in the chain, copying the data that was set with 6353d779efSschwarze.Xr BIO_set_ex_data 3 6453d779efSschwarzeis attempted, which may involve calling application-defined 6553d779efSschwarzecallback functions. 6653d779efSschwarze.Pp 6753d779efSschwarzeThe following pointers are copied 6853d779efSschwarzerather than creating deep copies of the objects pointed to: 6953d779efSschwarze.Bl -bullet 7053d779efSschwarze.It 7153d779efSschwarzeThe 7253d779efSschwarze.Fa type 7353d779efSschwarzepointer used for creating each BIO with 7453d779efSschwarze.Xr BIO_new 3 , 7553d779efSschwarzeimplying that functions like 7653d779efSschwarze.Xr BIO_method_name 3 7753d779efSschwarzereturn pointers to the same strings for the BIOs in the copied chain, 7853d779efSschwarzeand that these strings are not copied. 7953d779efSschwarze.It 8053d779efSschwarzeAll function pointers, in particular those installed with 8153d779efSschwarze.Xr BIO_set_callback_ex 3 8253d779efSschwarzeand 8353d779efSschwarze.Xr BIO_get_callback_ex 3 . 8453d779efSschwarze.It 8553d779efSschwarzeThe pointer installed with 8653d779efSschwarze.Xr BIO_set_callback_arg 3 , 8753d779efSschwarzewhich implies that for BIOs using 8853d779efSschwarze.Xr BIO_debug_callback 3 , 8953d779efSschwarzethose in the copied chain use the same BIOs for debugging output 9053d779efSschwarzeas the corresponding ones in the original chain, 9153d779efSschwarzeand none of the debugging output BIOs are copied. 9253d779efSschwarze.El 9353d779efSschwarze.Pp 9453d779efSschwarze.Fn BIO_dup_state 9553d779efSschwarzeis a macro that calls 9653d779efSschwarze.Xr BIO_ctrl 3 9753d779efSschwarzewith a 9853d779efSschwarze.Fa cmd 9953d779efSschwarzeargument of 10053d779efSschwarze.Dv BIO_CTRL_DUP . 10153d779efSschwarzeIt is automatically called for each BIO during 10253d779efSschwarze.Fn BIO_dup_chain 10353d779efSschwarzeafter the copied BIO is initialized and data copied into it, 10453d779efSschwarzebut before the data set with 10553d779efSschwarze.Xr BIO_set_ex_data 3 10653d779efSschwarzeis copied into the new BIO and before it is linked into the new chain. 10753d779efSschwarze.Pp 10853d779efSschwarzeThis control operation may modify the operation of 10953d779efSschwarze.Fn BIO_dup_chain 11053d779efSschwarzefor particular types of BIOs contained in the chain, 11153d779efSschwarzefor example initializing or copying additional data. 11253d779efSschwarzeFor BIO types provided by the library, such additional effects 11353d779efSschwarzeare documented in the respective manual pages, in particular in 11453d779efSschwarze.Xr BIO_f_buffer 3 , 11553d779efSschwarze.Xr BIO_f_cipher 3 , 11653d779efSschwarze.Xr BIO_f_md 3 , 11753d779efSschwarze.Xr BIO_f_ssl 3 , 11853d779efSschwarze.Xr BIO_s_bio 3 , 11953d779efSschwarzeand 12053d779efSschwarze.Xr BIO_s_connect 3 . 12153d779efSschwarze.Sh RETURN VALUES 12253d779efSschwarze.Fn BIO_dup_chain 12353d779efSschwarzereturns a pointer to the newly allocated copy of the BIO 12453d779efSschwarze.Fa b 12553d779efSschwarzeon success or 12653d779efSschwarze.Dv NULL 12753d779efSschwarzeon failure . 12853d779efSschwarze.Pp 12953d779efSschwarze.Fn BIO_dup_state 13053d779efSschwarzereturns 1 on success or a value less than or equal to zero on failure. 13153d779efSschwarze.Sh SEE ALSO 13253d779efSschwarze.Xr BIO_get_data 3 , 13353d779efSschwarze.Xr BIO_new 3 , 13453d779efSschwarze.Xr BIO_next 3 , 13553d779efSschwarze.Xr BIO_push 3 13653d779efSschwarze.Sh HISTORY 13753d779efSschwarze.Fn BIO_dup_chain 13853d779efSschwarzeand 13953d779efSschwarze.Fn BIO_dup_state 14053d779efSschwarzefirst appeared in SSLeay 0.8.0 and have been available since 14153d779efSschwarze.Ox 2.4 . 142