X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=blobdiff_plain;f=src%2FPVE%2FTools.pm;h=2cd47333edf1dc043568ac0d5bcb0be782ca2828;hp=fe35ef225e46f35d52d5c374c00e3738b8b3871b;hb=ccf60d3bb8f0a9c1d554f761173431e704687bfb;hpb=0f3f314ed72735ece3e0b826193b1dd23e69e37c diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm index fe35ef2..2cd4733 100644 --- a/src/PVE/Tools.pm +++ b/src/PVE/Tools.pm @@ -4,7 +4,7 @@ use strict; use warnings; use POSIX qw(EINTR EEXIST EOPNOTSUPP); use IO::Socket::IP; -use Socket qw(AF_INET AF_INET6 AI_ALL AI_V4MAPPED); +use Socket qw(AF_INET AF_INET6 AI_ALL AI_V4MAPPED AI_CANONNAME SOCK_DGRAM); use IO::Select; use File::Basename; use File::Path qw(make_path); @@ -1081,7 +1081,7 @@ sub dump_logfile { } sub dump_journal { - my ($start, $limit, $since, $until) = @_; + my ($start, $limit, $since, $until, $service) = @_; my $lines = []; my $count = 0; @@ -1100,6 +1100,7 @@ sub dump_journal { my $cmd = ['journalctl', '-o', 'short', '--no-pager']; + push @$cmd, '--unit', $service if $service; push @$cmd, '--since', $since if $since; push @$cmd, '--until', $until if $until; run_command($cmd, outfunc => $parser); @@ -1197,6 +1198,24 @@ sub get_host_address_family { return $res[0]->{family}; } +# get the fully qualified domain name of a host +# same logic as hostname(1): The FQDN is the name getaddrinfo(3) returns, +# given a nodename as a parameter +sub get_fqdn { + my ($nodename) = @_; + + my $hints = { + flags => AI_CANONNAME, + socktype => SOCK_DGRAM + }; + + my ($err, @addrs) = Socket::getaddrinfo($nodename, undef, $hints); + + die "getaddrinfo: $err" if $err; + + return $addrs[0]->{canonname}; +} + # Parses any sane kind of host, or host+port pair: # The port is always optional and thus may be undef. sub parse_host_and_port { @@ -1443,4 +1462,18 @@ sub enter_systemd_scope { die "systemd job never completed\n" if !$done; } +my $salt_starter = time(); + +sub encrypt_pw { + my ($pw) = @_; + + $salt_starter++; + my $salt = substr(Digest::SHA::sha1_base64(time() + $salt_starter + $$), 0, 8); + + # crypt does not want '+' in salt (see 'man crypt') + $salt =~ s/\+/X/g; + + return crypt(encode("utf8", $pw), "\$5\$$salt\$"); +} + 1;