1515
1616#define _GNU_SOURCE
1717
18- #ifdef __linux__
19- # include <sys/syscall.h>
20- #endif
21-
2218#include <arpa/inet.h>
2319#include <assert.h>
2420#include <ctype.h>
@@ -62,35 +58,6 @@ char *sshauth_privkey_passphrase(const char *privkey_path, void *priv);
6258
6359static pthread_once_t nc_client_context_once = PTHREAD_ONCE_INIT ;
6460static pthread_key_t nc_client_context_key ;
65- #ifdef __linux__
66- static struct nc_client_context context_main = {
67- .opts .ka = {
68- .enabled = 1 ,
69- .idle_time = 1 ,
70- .max_probes = 10 ,
71- .probe_interval = 5
72- },
73- .opts .monitoring_thread_data .lock = PTHREAD_MUTEX_INITIALIZER ,
74- #ifdef NC_ENABLED_SSH_TLS
75- .ssh_opts = {
76- .auth_pref = {{NC_SSH_AUTH_INTERACTIVE , 1 }, {NC_SSH_AUTH_PASSWORD , 2 }, {NC_SSH_AUTH_PUBLICKEY , 3 }},
77- .auth_password = sshauth_password ,
78- .auth_interactive = sshauth_interactive ,
79- .auth_privkey_passphrase = sshauth_privkey_passphrase ,
80- .knownhosts_mode = NC_SSH_KNOWNHOSTS_ASK
81- },
82- .ssh_ch_opts = {
83- .auth_pref = {{NC_SSH_AUTH_INTERACTIVE , 1 }, {NC_SSH_AUTH_PASSWORD , 2 }, {NC_SSH_AUTH_PUBLICKEY , 3 }},
84- .auth_password = sshauth_password ,
85- .auth_interactive = sshauth_interactive ,
86- .auth_privkey_passphrase = sshauth_privkey_passphrase ,
87- .knownhosts_mode = NC_SSH_KNOWNHOSTS_ASK
88- },
89- #endif /* NC_ENABLED_SSH_TLS */
90- /* .tls_ structures zeroed */
91- .refcount = 0
92- };
93- #endif
9461
9562static void
9663nc_client_context_free (void * ptr )
@@ -103,39 +70,30 @@ nc_client_context_free(void *ptr)
10370 return ;
10471 }
10572
106- #ifdef __linux__
107- /* in __linux__ we use static memory in the main thread,
108- * so this check is for programs terminating the main()
109- * function by pthread_exit() :)
110- */
111- if (c != & context_main )
112- #endif
113- {
114- /* for the main thread the same is done in nc_client_destroy() */
115- free (c -> opts .schema_searchpath );
116- for (i = 0 ; i < c -> opts .capabilities_count ; i ++ ) {
117- free (c -> opts .capabilities [i ]);
118- }
119- free (c -> opts .capabilities );
120- free (c -> unix_opts .username );
73+ /* for the main thread the same is done in nc_client_destroy() */
74+ free (c -> opts .schema_searchpath );
75+ for (i = 0 ; i < c -> opts .capabilities_count ; i ++ ) {
76+ free (c -> opts .capabilities [i ]);
77+ }
78+ free (c -> opts .capabilities );
79+ free (c -> unix_opts .username );
12180
12281#ifdef NC_ENABLED_SSH_TLS
123- for (i = 0 ; i < c -> opts .ch_bind_count ; ++ i ) {
124- close (c -> opts .ch_binds [i ].sock );
125- free ((char * )c -> opts .ch_binds [i ].address );
126- }
127- free (c -> opts .ch_binds );
128- c -> opts .ch_binds = NULL ;
129- c -> opts .ch_bind_count = 0 ;
82+ for (i = 0 ; i < c -> opts .ch_bind_count ; ++ i ) {
83+ close (c -> opts .ch_binds [i ].sock );
84+ free ((char * )c -> opts .ch_binds [i ].address );
85+ }
86+ free (c -> opts .ch_binds );
87+ c -> opts .ch_binds = NULL ;
88+ c -> opts .ch_bind_count = 0 ;
13089
131- _nc_client_ssh_destroy_opts (& c -> ssh_opts );
132- _nc_client_ssh_destroy_opts (& c -> ssh_ch_opts );
90+ _nc_client_ssh_destroy_opts (& c -> ssh_opts );
91+ _nc_client_ssh_destroy_opts (& c -> ssh_ch_opts );
13392
134- _nc_client_tls_destroy_opts (& c -> tls_opts );
135- _nc_client_tls_destroy_opts (& c -> tls_ch_opts );
93+ _nc_client_tls_destroy_opts (& c -> tls_opts );
94+ _nc_client_tls_destroy_opts (& c -> tls_ch_opts );
13695#endif /* NC_ENABLED_SSH_TLS */
137- free (c );
138- }
96+ free (c );
13997}
14098
14199static void
@@ -157,43 +115,35 @@ nc_client_context_location(void)
157115 e = pthread_getspecific (nc_client_context_key );
158116 if (!e ) {
159117 /* prepare ly_err storage */
160- #ifdef __linux__
161- if (getpid () == syscall (SYS_gettid )) {
162- /* main thread - use global variable instead of thread-specific variable. */
163- e = & context_main ;
164- } else
165- #endif /* __linux__ */
166- {
167- e = calloc (1 , sizeof * e );
168- /* set default values */
169- e -> refcount = 1 ;
170- e -> opts .ka .enabled = 1 ;
171- e -> opts .ka .idle_time = 1 ;
172- e -> opts .ka .max_probes = 10 ;
173- e -> opts .ka .probe_interval = 5 ;
118+ e = calloc (1 , sizeof * e );
119+ /* set default values */
120+ e -> refcount = 1 ;
121+ e -> opts .ka .enabled = 1 ;
122+ e -> opts .ka .idle_time = 1 ;
123+ e -> opts .ka .max_probes = 10 ;
124+ e -> opts .ka .probe_interval = 5 ;
174125#ifdef NC_ENABLED_SSH_TLS
175126# ifdef HAVE_TERMIOS
176- e -> ssh_opts .knownhosts_mode = NC_SSH_KNOWNHOSTS_ASK ;
127+ e -> ssh_opts .knownhosts_mode = NC_SSH_KNOWNHOSTS_ASK ;
177128# else
178- e -> ssh_opts .knownhosts_mode = NC_SSH_KNOWNHOSTS_ACCEPT ;
129+ e -> ssh_opts .knownhosts_mode = NC_SSH_KNOWNHOSTS_ACCEPT ;
179130# endif
180- e -> ssh_opts .auth_pref [0 ].type = NC_SSH_AUTH_INTERACTIVE ;
181- e -> ssh_opts .auth_pref [0 ].value = 1 ;
182- e -> ssh_opts .auth_pref [1 ].type = NC_SSH_AUTH_PASSWORD ;
183- e -> ssh_opts .auth_pref [1 ].value = 2 ;
184- e -> ssh_opts .auth_pref [2 ].type = NC_SSH_AUTH_PUBLICKEY ;
185- e -> ssh_opts .auth_pref [2 ].value = 3 ;
186- e -> ssh_opts .auth_password = sshauth_password ;
187- e -> ssh_opts .auth_interactive = sshauth_interactive ;
188- e -> ssh_opts .auth_privkey_passphrase = sshauth_privkey_passphrase ;
189-
190- /* callhome settings are the same */
191- memcpy (& e -> ssh_ch_opts , & e -> ssh_opts , sizeof e -> ssh_ch_opts );
192- e -> ssh_ch_opts .auth_pref [0 ].value = 1 ;
193- e -> ssh_ch_opts .auth_pref [1 ].value = 2 ;
194- e -> ssh_ch_opts .auth_pref [2 ].value = 3 ;
131+ e -> ssh_opts .auth_pref [0 ].type = NC_SSH_AUTH_INTERACTIVE ;
132+ e -> ssh_opts .auth_pref [0 ].value = 1 ;
133+ e -> ssh_opts .auth_pref [1 ].type = NC_SSH_AUTH_PASSWORD ;
134+ e -> ssh_opts .auth_pref [1 ].value = 2 ;
135+ e -> ssh_opts .auth_pref [2 ].type = NC_SSH_AUTH_PUBLICKEY ;
136+ e -> ssh_opts .auth_pref [2 ].value = 3 ;
137+ e -> ssh_opts .auth_password = sshauth_password ;
138+ e -> ssh_opts .auth_interactive = sshauth_interactive ;
139+ e -> ssh_opts .auth_privkey_passphrase = sshauth_privkey_passphrase ;
140+
141+ /* callhome settings are the same */
142+ memcpy (& e -> ssh_ch_opts , & e -> ssh_opts , sizeof e -> ssh_ch_opts );
143+ e -> ssh_ch_opts .auth_pref [0 ].value = 1 ;
144+ e -> ssh_ch_opts .auth_pref [1 ].value = 2 ;
145+ e -> ssh_ch_opts .auth_pref [2 ].value = 3 ;
195146#endif /* NC_ENABLED_SSH_TLS */
196- }
197147
198148 /* init the monitoring thread data lock */
199149 pthread_mutex_init (& e -> opts .monitoring_thread_data .lock , NULL );
0 commit comments