@@ -4014,6 +4014,7 @@ ndb_mgm_get_session(NdbMgmHandle handle, Uint64 id,
4014
4014
MGM_ARG (" id" , Int, Mandatory, " Node ID" ),
4015
4015
MGM_ARG (" m_stopSelf" , Int, Optional, " m_stopSelf" ),
4016
4016
MGM_ARG (" m_stop" , Int, Optional, " stop session" ),
4017
+ MGM_ARG (" tls" , Int, Optional, " session is using TLS" ),
4017
4018
MGM_ARG (" nodeid" , Int, Optional, " allocated node id" ),
4018
4019
MGM_ARG (" parser_buffer_len" , Int, Optional, " waiting in buffer" ),
4019
4020
MGM_ARG (" parser_status" , Int, Optional, " parser status" ),
@@ -4057,6 +4058,10 @@ ndb_mgm_get_session(NdbMgmHandle handle, Uint64 id,
4057
4058
rlen+=sizeof (s->parser_status );
4058
4059
}
4059
4060
4061
+ /* tls is a late addition to the struct, so check length */
4062
+ if (*len > rlen && prop->get (" tls" ,&(s->tls )))
4063
+ rlen+=sizeof (s->tls );
4064
+
4060
4065
*len= rlen;
4061
4066
retval= 1 ;
4062
4067
@@ -4230,6 +4235,122 @@ ndb_socket_t _ndb_mgm_get_socket(NdbMgmHandle h)
4230
4235
return h->socket .ndb_socket ();
4231
4236
}
4232
4237
4238
+ int ndb_mgm_has_tls (NdbMgmHandle h)
4239
+ {
4240
+ return h->socket .has_tls () ? 1 : 0 ;
4241
+ }
4242
+
4243
+ static ndb_mgm_cert_table * new_cert_table ()
4244
+ {
4245
+ ndb_mgm_cert_table * table = new ndb_mgm_cert_table;
4246
+ table->session_id = 0 ;
4247
+ table->peer_address = nullptr ;
4248
+ table->cert_serial = nullptr ;
4249
+ table->cert_name = nullptr ;
4250
+ table->cert_expires = nullptr ;
4251
+ table->next = nullptr ;
4252
+ return table;
4253
+ }
4254
+
4255
+ int ndb_mgm_list_certs (NdbMgmHandle handle, ndb_mgm_cert_table ** data)
4256
+ {
4257
+ DBUG_ENTER (" ndb_mgm_list_certs" );
4258
+ CHECK_HANDLE (handle, -1 );
4259
+ CHECK_CONNECTED (handle, -1 );
4260
+
4261
+ SecureSocketOutputStream out (handle->socket , handle->timeout );
4262
+ SecureSocketInputStream in (handle->socket , handle->timeout );
4263
+
4264
+ out.println (" list certs" );
4265
+ out.println (" %s" , " " );
4266
+
4267
+ /* See listCerts() and show_cert() in mgmsrv/Services.cpp for reply format */
4268
+ int ok = false ;
4269
+ char buf[1024 ];
4270
+
4271
+ in.gets (buf, sizeof (buf));
4272
+ if (strcmp (" list certs reply\n " , buf))
4273
+ DBUG_RETURN (-1 );
4274
+
4275
+ int ncerts = 0 ;
4276
+ struct ndb_mgm_cert_table * current = *data = nullptr ;
4277
+ while (in.gets (buf, sizeof (buf))) {
4278
+ if (strcmp (" \n " , buf) == 0 ) { /* Blank line at end of input */
4279
+ ok = true ;
4280
+ break ;
4281
+ }
4282
+ Vector<BaseString> parts;
4283
+ BaseString line (buf);
4284
+ if (line.split (parts, " :" , 2 ) != 2 )
4285
+ break ;
4286
+ if (parts[0 ] == " session" ) {
4287
+ ncerts++;
4288
+ current = new_cert_table ();
4289
+ current->next = *data;
4290
+ *data = current;
4291
+ current->session_id = strtoull (parts[1 ].c_str (), nullptr , 10 );
4292
+ }
4293
+ else {
4294
+ char * value = strdup (parts[1 ].substr (1 ).trim (" \n " ).c_str ());
4295
+ if (parts[0 ] == " address" )
4296
+ current->peer_address = value;
4297
+ else if (parts[0 ] == " serial" )
4298
+ current->cert_serial = value;
4299
+ else if (parts[0 ] == " name" )
4300
+ current->cert_name = value;
4301
+ else if (parts[0 ] == " expires" )
4302
+ current->cert_expires = value;
4303
+ else
4304
+ free (value); // unexpected input
4305
+ }
4306
+ }
4307
+
4308
+ if (ok) DBUG_RETURN (ncerts);
4309
+ DBUG_RETURN (-1 );
4310
+ }
4311
+
4312
+ void ndb_mgm_cert_table_free (ndb_mgm_cert_table ** list) {
4313
+ while (*list) {
4314
+ ndb_mgm_cert_table * t = *list;
4315
+ free ((void *) t->cert_expires );
4316
+ free ((void *) t->cert_name );
4317
+ free ((void *) t->cert_serial );
4318
+ free ((void *) t->peer_address );
4319
+ *list = t->next ;
4320
+ delete t;
4321
+ }
4322
+ }
4323
+
4324
+ int ndb_mgm_get_tls_stats (NdbMgmHandle handle, ndb_mgm_tls_stats * result) {
4325
+ DBUG_ENTER (" ndb_mgm_get_tls_stats" );
4326
+ CHECK_HANDLE (handle, -1 );
4327
+ CHECK_CONNECTED (handle, -1 );
4328
+
4329
+ const ParserRow<ParserDummy> reply[]= {
4330
+ MGM_CMD (" get tls stats reply" , nullptr , " " ),
4331
+ MGM_ARG (" accepted" , Int, Mandatory, " Total accepted connections" ),
4332
+ MGM_ARG (" upgraded" , Int, Mandatory, " Total connections upgraded to TLS" ),
4333
+ MGM_ARG (" current" , Int, Mandatory, " Current open connections" ),
4334
+ MGM_ARG (" tls" , Int, Mandatory, " Current connections using TLS" ),
4335
+ MGM_ARG (" authfail" , Int, Mandatory, " Total authorization errors" ),
4336
+ MGM_END ()
4337
+ };
4338
+
4339
+ const Properties * prop =
4340
+ ndb_mgm_call (handle, reply, " get tls stats" , nullptr );
4341
+
4342
+ CHECK_REPLY (handle, prop, 0 );
4343
+
4344
+ prop->get (" accepted" , & (result->accepted ));
4345
+ prop->get (" upgraded" , & (result->upgraded ));
4346
+ prop->get (" current" , & (result->current ));
4347
+ prop->get (" tls" , & (result->tls ));
4348
+ prop->get (" authfail" , & (result->authfail ));
4349
+
4350
+ delete prop;
4351
+ DBUG_RETURN (0 );
4352
+ }
4353
+
4233
4354
4234
4355
/*
4235
4356
Compare function for qsort() to sort events in
0 commit comments