summaryrefslogtreecommitdiff
path: root/src/rpc
Commit message (Collapse)AuthorAgeFilesLines
* lib: Use g_clear_pointer() moreMichal Privoznik2022-02-083-22/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change was generated using the following spatch: @ rule1 @ expression a; identifier f; @@ <... - f(*a); ... when != a; - *a = NULL; + g_clear_pointer(a, f); ...> @ rule2 @ expression a; identifier f; @@ <... - f(a); ... when != a; - a = NULL; + g_clear_pointer(&a, f); ...> Then, I left some of the changes out, like tools/nss/ (which doesn't link with glib) and put back a comment in qemuBlockJobProcessEventCompletedActiveCommit() which coccinelle decided to remove (I have no idea why). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
* lib: Drop '&*' from '&*variable'Michal Privoznik2022-01-311-4/+4
| | | | | | | | Apparently, some of '&*variable' slipped in. Drop '&*' and access the variable directly. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ani Sinha <ani@anisinha.ca>
* rpc: Require dtrace sources to be generated firstMichal Privoznik2022-01-041-0/+1
| | | | | | | | | | The virt_socket_lib is built from virnetsocket.c (among others). But this file includes virprobe.h which includes libvirt_probes.h which is a generated file. But this dependency is not recorded in meson which may lead to a failed build. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
* virnettlscontext: Don't pass static key length to gnutls_dh_params_generate2()Michal Privoznik2022-01-031-3/+10
| | | | | | | | | | | | | | | | | | | | | | As encryption norms get more strict it's easy to fall on the insecure side. For instance, so far we are generating 2048 bits long prime for Diffie-Hellman keys. Some systems consider this not long enough. While we may just keep increasing the value passed to the corresponding gnutls_* function, that is not well maintainable. Instead, we may do what's recommended in the gnutls_* manpage. From gnutls_dh_params_generate2(3): It is recommended not to set the number of bits directly, but use gnutls_sec_param_to_pk_bits() instead. Looking into the gnutls_sec_param_to_pk_bits() then [1], 2048 bits corresponds to parameter MEDIUM. 1: https://www.gnutls.org/manual/gnutls.html#tab_003akey_002dsizes Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ani Sinha <ani@anisinha.ca> Reviewed-by: Ján Tomko <jtomko@redhat.com>
* virnettlscontext: Drop gnutls_dh_set_prime_bits()Michal Privoznik2022-01-031-2/+0
| | | | | | | | | | | | According to the gnutls_dh_set_prime_bits() manpage: The function has no effect in server side. Therefore, don't call it when creating server side context. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ani Sinha <ani@anisinha.ca> Reviewed-by: Ján Tomko <jtomko@redhat.com>
* rpc: Build only when XDR is availableMichal Privoznik2021-12-151-56/+58
| | | | | | | | | Our RPC layer is as tied to XDR as possible. Therefore, if we haven't detected and XDR library there's not much sense in trying to build RPC layer. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
* rpc: Separate out socket code into another static libMichal Privoznik2021-12-151-2/+22
| | | | | | | | | | | | | There's nothing RPC specific about virnettlscontext.c or virnetsocket.c. We use TLS for other things than just RPC encryption (e.g. for generating random numbers) and sockets can be used even without RPC. Move these two sources into a static library (virt_socket) so that other areas can use it even when RPC is disabled. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
* rpc: Introduce virNetClientStreamInData()Michal Privoznik2021-12-132-0/+68
| | | | | | | | | | | The aim of this function is to look at a virNetClientStream and tell whether the incoming packet (if there's one) contains data (type VIR_NET_STREAM) or a hole (type VIR_NET_STREAM_HOLE) and how big the section is. This function will be called from the remote driver in one of future commits. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
* virnetserver: Make pool job name less genericJiri Denemark2021-12-011-1/+2
| | | | | | | | | | | | | | | The generic "rpc-worker" name becomes a name of the associated task, which may than appear in logs and bring some confusion. Let's add a server name to it so that one can easily see which daemon the task belongs to, which is especially useful for split daemons. And since the name would be too long, we can drop the "-worker" part and just keep it as "rpc-*" and "prio-rpc-*". Such confusing entries can, for example, be found in audit log when SELinux is complaining that "rpc-worker" was denied access to something. Signed-off-by: Jiri Denemark <jdenemar@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* virnetserver: Use autoptr for virNetServer and virNetServerClientJiri Denemark2021-12-012-38/+28
| | | | | Signed-off-by: Jiri Denemark <jdenemar@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* virnetserver: Format functions consistentlyJiri Denemark2021-12-011-68/+112
| | | | | | | | | | | The file used a pretty inconsistent style for formatting function headers. Return types were both separate and on the same line as function names and functions were separated by one, two, and sometimes even three empty lines. Let's make it consistent by honoring our preferred coding style. Signed-off-by: Jiri Denemark <jdenemar@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* Switch away from virHashFreePeter Krempa2021-12-011-1/+1
| | | | | | | | | | | Use 'g_clear_pointer(&ptr, g_hash_table_unref)' instead. In few instances it allows us to also remove explicit clearing of pointers. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
* lib: Drop needless one line labelsMichal Privoznik2021-11-221-8/+2
| | | | | | | | | | In some cases we have a label that contains nothing but a return statement. The amount of such labels rises as we use automagic cleanup. Anyway, such labels are pointless and can be dropped. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
* Add suggestions for virt-pki-query-dn usageMartin Kletzander2021-11-121-1/+1
| | | | | | | To make it easier for users to figure out how the DN should be formatted. Signed-off-by: Martin Kletzander <mkletzan@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
* rpc: Resize dname for longer DN from TLS certsMartin Kletzander2021-11-111-8/+12
| | | | | | | And to make that easier, allocate it on the heap. Signed-off-by: Martin Kletzander <mkletzan@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
* virnetsocket: pass HOME and XDG_RUNTIME_DIR to sshДамјан Георгиевски2021-11-091-0/+1
| | | | | | | | | | | | | | | | | | | | | | openssh supports environment variable expansion in its ssh_config file[1]. These two environment variables can be used to expand paths for ssh sockets and other files. Ex. ``` Host * ControlMaster auto ControlPath ${XDG_RUNTIME_DIR}/ssh-%C.ctl IdentityAgent ${XDG_RUNTIME_DIR}/ssh-agent.socket ``` see also: [1] https://man7.org/linux/man-pages/man5/ssh_config.5.html#ENVIRONMENT_VARIABLES [2] https://gitlab.com/libvirt/libvirt/-/issues/232 Signed-off-by: Дамјан Георгиевски <gdamjan@gmail.com> Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* daemon: virNetSASLContext: store tcpMinSSFJán Tomko2021-11-042-2/+14
| | | | | | | | Store the minimum SSF value for TCP connections in virNetSASLContext and introduce a getter for it. Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* virthreadpool: Allow setting identity for workersMichal Privoznik2021-10-271-0/+1
| | | | | | | | | | | | In some cases the worker func running inside the pool may rely on virIdentity. While worker func could check for identity and set one it is not optimal - it may not have access to the identity of the thread creating the pool and thus would have to call virIdentityGetSystem(). Allow passing identity when creating the pool. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
* rpc: Temporarily stop accept()-ing new clients on EMFILEMichal Privoznik2021-10-204-2/+79
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit is related to 5de203f879 which I pushed a few days ago. While that commit prioritized closing clients socket over the rest of I/O process, this one goes one step further and temporarily suspends processing new connection requests. A brief recapitulation of the problem: 1) assume that libvirt is at the top of RLIMIT_NOFILE (that is no new FDs can be opened). 2) we have a client trying to connect to a UNIX/TCP socket Because of 2) our event loop sees POLLIN on the socket and thus calls virNetServerServiceAccept(). But since no new FDs can be opened (because of 1)) the request is not handled and we will get the same event on next iteration. The poll() will exit immediately because there is an event on the socket. Thus we end up in an endless loop. To break the loop and stop burning CPU cycles we can stop listening for events on the socket and set up a timer tho enable listening again after some time (I chose 5 seconds because of no obvious reason). There's another area where we play with temporarily suspending accept() of new clients - when a client disconnects and we check max_clients against number of current clients. Problem here is that max_clients can be orders of magnitude larger than RLIMIT_NOFILE but more importantly, what this code considers client disconnect is not equal to closing client's FD. A client disconnecting means that the corresponding client structure is removed from the internal list of clients. Closing of the client's FD is done from event loop - asynchronously. To avoid this part stepping on the toes of my fix, let's make the code NOP if socket timer (as described above) is active. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
* virnetsocket: Use g_auto* moreMichal Privoznik2021-10-151-37/+20
| | | | | | | | | There are few functions in virnetsocket.c where an object/memory is freed by explicit call. Use g_autoptr()/g_autofree/VIR_AUTOCLOSE to do that automatically. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
* virnetsocket: Don't free virCommand in virNetSocketNewConnectCommand()Michal Privoznik2021-10-151-5/+2
| | | | | | | | | | | | | | | | | | | The aim of virNetSocketNewConnectCommand() is to execute passed command and attach socket pair/pipe to it so that client socket can be opened (this is used for connections with alternative transports, e.g. ssh). The virCommand is created in a caller and then passed to virNetSocketNewConnectCommand() where it is freed using virCommandFree(). This approach is wrong on two levels: 1) The deallocation happens on a different level than allocation, 2) There's a WIN32 stub that just reports an error and doesn't free the command. However, with g_autoptr() trickery the command can be freed in caller. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
* rpc: mark source returned by virEventGLibAddSocketWatch as unusedJán Tomko2021-09-081-3/+3
| | | | | | | | | | | | | Two users of virEventGLibAddSocketWatch care about the GSource it returns. The other three free it by assigning it to an autofreed variable. Mark them with G_GNUC_UNUSED to make this obvious to the reader and the compiler. Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* src: stop checking virIdentityNew return valueDaniel P. Berrangé2021-08-061-4/+1
| | | | | | | This method will always succeed. Reviewed-by: Peter Krempa <pkrempa@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
* virNetServerGetClients: Remove pointless cleanupPeter Krempa2021-08-061-4/+2
| | | | | | | | | 'list' will always be NULL when reaching 'virObjectListFreeCount' thus we can remove the call as well as the 'ret' variable which was only ever equal to 'nclients' at the point when we returned the value. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* util: alloc: Reimplement VIR_APPEND_ELEMENT using virAppendElementPeter Krempa2021-08-063-8/+5
| | | | | | | | | | Use virAppendElement instead of virInsertElementsN to implement VIR_APPEND_ELEMENT which allows us to remove error handling as the only relevant errors were removed when switching to aborting memory allocation functions. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* virNetDaemonNew: `virHashNew` cannot return NULLTim Wiederhake2021-07-231-2/+1
| | | | | Signed-off-by: Tim Wiederhake <twiederh@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
* rpc: prefer SHA256 host key fingerprint with new libsshDaniel P. Berrangé2021-06-231-3/+10
| | | | | | | | | | The host key fingerprint for SSH servers is used in a scenario where cryptographic strength is important. We should thus be defaulting to use of SHA256 where available. We only need SHA1 for Ubuntu 18.04 which does not have libssh >= 0.8.1 Reviewed-by: Pavel Hrdina <phrdina@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
* virnetsocket: Mark @spawnDaemonPath of virNetSocketNewConnectUNIX() unusedMichal Privoznik2021-06-071-1/+1
| | | | | | | | | The virNetSocketNewConnectUNIX() function was changed in 48f66cfe3e. And its WIN32 version (which just reports an error) was updated too, but this new argument @spawnDaemonPath was not marked as unused. Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
* rpc: remove "spawnDaemon" parameterDaniel P. Berrangé2021-06-044-26/+11
| | | | | | | | | | The "spawnDaemon" and "binary" parameters are co-dependant, with the latter non-NULL, if-and-only-if the former is true. Getting rid of the "spawnDaemon" parameter simplifies life for the callers and eliminates an error checking scenario. Reviewed-by: Ján Tomko <jtomko@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
* Remove static analysis assertionsPeter Krempa2021-05-241-4/+0
| | | | | | | | | | None of them are currently needed to pass our upstream CI, most were either for ancient clang versions or coverity for silencing false positives. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Pavel Hrdina <phrdina@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* rpc: libssh2: Enable EC host keysBastian Germann2021-04-221-1/+15
| | | | | | | | | | | libssh2 has ECDSA and ED25519 support beginning with v1.9.0. libvirt cannot make use of those because it will handle them as unknown key types. Add support for those host key types. Signed-off-by: Bastian Germann <bastiangermann@fishpost.de> Reviewed-by: Neal Gompa <ngompa13@gmail.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* lib: Drop internal virXXXPtr typedefsMichal Privoznik2021-04-1330-1243/+1210
| | | | | | | | | | | | | | | | | | | | | | Historically, we declared pointer type to our types: typedef struct _virXXX virXXX; typedef virXXX *virXXXPtr; But usefulness of such declaration is questionable, at best. Unfortunately, we can't drop every such declaration - we have to carry some over, because they are part of public API (e.g. virDomainPtr). But for internal types - we can do drop them and use what every other C project uses 'virXXX *'. This change was generated by a very ugly shell script that generated sed script which was then called over each file in the repository. For the shell script refer to the cover letter: https://listman.redhat.com/archives/libvir-list/2021-March/msg00537.html Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
* api: add virNodeDeviceDefineXML()Jonathon Jongsma2021-04-071-0/+1
| | | | | | | | | With mediated devices, we can now define persistent node devices that can be started and stopped. In order to take advantage of this, we need an API to define new node devices. Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
* virnetsocket: Revert part of g_steal_pointer() rewriteMichal Privoznik2021-03-261-1/+2
| | | | | | | | | Turns out, the way that glib implements g_steal_pointer() is not compatible with function callbacks. And that's what my recent patch did in virNetSocketEventFree(). Revert that part. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
* lib: Use g_steal_pointer() moreMichal Privoznik2021-03-247-33/+17
| | | | | | | | | | | | | | | | Generated by the following spatch: @@ expression a, b; @@ + b = g_steal_pointer(&a); - b = a; ... when != a - a = NULL; Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
* Do not check return value of VIR_REALLOC_NJiri Denemark2021-03-222-10/+5
| | | | | Signed-off-by: Jiri Denemark <jdenemar@redhat.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
* Do not check return value of VIR_EXPAND_NJiri Denemark2021-03-226-48/+9
| | | | | Signed-off-by: Jiri Denemark <jdenemar@redhat.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
* lib: Put some variable declarations on individual linesMichal Privoznik2021-03-151-1/+2
| | | | | | | | | In short, virXXXPtr type is going away. With big bang. And to help us rewrite the code with a sed script, it's better if each variable is declared on its own line. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
* gendispatch: Don't use virXXXPtr for internal typesMichal Privoznik2021-03-151-33/+33
| | | | | | | | The use of virXXXPtr is going away soon, therefore use 'virXXX *' instead. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
* virnetdaemon: Introduce virNetDaemonQuitExecRestartPeter Krempa2021-03-122-0/+20
| | | | | | | | | | | | | Recent changes which meant to fix daemon shutdown broke the exec-restart capability of virtlogd and virtlockd, since the code actually closed all the sockets and shut down all the internals. Add virNetDaemonQuitExecRestart, which requests a shutdown of the process, but keeps all the services open and registered since they are preserved across the restart. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* virNetLibsshAuthenticatePrivkeyCb: Use virStrcpy instead of virStrncpyPeter Krempa2021-03-111-2/+1
| | | | | | | | We already assume that 'retr_passphrase.result' is a string, thus we can use virStrcpy instead. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
* virNetLibsshAuthenticatePrivkeyCb: Use g_autofree for 'actual_prompt'Peter Krempa2021-03-111-10/+4
| | | | | | | So that the 'error' label can be removed. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
* lib: Replace virFileMakePathWithMode() with g_mkdir_with_parents()Michal Privoznik2021-03-041-1/+1
| | | | | | | | | | | | | These functions are identical. Made using this spatch: @@ expression path, mode; @@ - virFileMakePathWithMode(path, mode) + g_mkdir_with_parents(path, mode) Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
* Use g_steal_pointer where possibleKristina Hanicova2021-03-011-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | Via coccinelle (not the handbag!) spatches used: @ rule1 @ identifier a, b; symbol NULL; @@ - b = a; ... when != a - a = NULL; + b = g_steal_pointer(&a); @@ - *b = a; ... when != a - a = NULL; + *b = g_steal_pointer(&a); Signed-off-by: Kristina Hanicova <khanicov@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com> Signed-off-by: Ján Tomko <jtomko@redhat.com>
* virJSONValueArrayAppend: Clear pointer when taking ownership of passed valuePeter Krempa2021-02-202-6/+3
| | | | | | | | | | The parent array takes ownership of the inserted value once all checks pass. Don't make the callers second-guess when that happens and modify the function to take a double pointer so that it can be cleared once the ownership is taken. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* virJSONValueObjectAppend: Clear pointer when taking ownership of passed valuePeter Krempa2021-02-204-14/+7
| | | | | | | | | | The parent object takes ownership of the inserted value once all checks pass. Don't make the callers second-guess when that happens and modify the function to take a double pointer so that it can be cleared once the ownership is taken. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* virNetServerPreExecRestart: Refactor memory cleanupPeter Krempa2021-02-201-25/+16
| | | | | | | Switch to using the 'g_auto*' helpers. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* virNetServerPreExecRestart: Drop error reporting from ↵Peter Krempa2021-02-201-32/+10
| | | | | | | | | | | virJSONValueObjectAppend* calls The functions report errors already and the error can nowadays only happen on programmer errors (if the passed virJSONValue isn't an object), which won't happen. Remove the reporting. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* virNetServerClientPreExecRestart: Refactor memory cleanupPeter Krempa2021-02-201-15/+11
| | | | | | | Switch to using the 'g_auto*' helpers. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* virNetServerServicePreExecRestart: Refactor memory cleanupPeter Krempa2021-02-201-22/+14
| | | | | | | Switch to using the 'g_auto*' helpers. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>