.\" Automatically generated by Pod::Man 4.07 (Pod::Simple 3.32) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Lintian::Util 3" .TH Lintian::Util 3 "2019-05-26" "Lintian v2.15.0~bpo9+1" "Debian Package Checker" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Lintian::Util \- Lintian utility functions .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Lintian::Util qw(normalize_pkg_path); \& \& my $path = normalize_pkg_path(\*(Aqusr/bin/\*(Aq, \*(Aq../lib/git\-core/git\-pull\*(Aq); \& if (defined $path) { \& # ... \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module contains a number of utility subs that are nice to have, but on their own did not warrant their own module. .PP Most subs are imported only on request. .SH "VARIABLES" .IX Header "VARIABLES" .ie n .IP "$PKGNAME_REGEX" 4 .el .IP "\f(CW$PKGNAME_REGEX\fR" 4 .IX Item "$PKGNAME_REGEX" Regular expression that matches valid package names. The expression is not anchored and does not enforce any \*(L"boundary\*(R" characters. .ie n .IP "$PKGREPACK_REGEX" 4 .el .IP "\f(CW$PKGREPACK_REGEX\fR" 4 .IX Item "$PKGREPACK_REGEX" Regular expression that matches \*(L"repacked\*(R" package names. The expression is not anchored and does not enforce any \*(L"boundary\*(R" characters. .ie n .IP "$PKGVERSION_REGEX" 4 .el .IP "\f(CW$PKGVERSION_REGEX\fR" 4 .IX Item "$PKGVERSION_REGEX" Regular expression that matches valid package versions. The expression is not anchored and does not enforce any \*(L"boundary\*(R" characters. .SH "FUNCTIONS" .IX Header "FUNCTIONS" .IP "get_deb_info(\s-1DEBFILE\s0)" 4 .IX Item "get_deb_info(DEBFILE)" Extracts the control file from \s-1DEBFILE\s0 and returns it as a hashref. .Sp Basically, this is a fancy convenience for setting up an ar + tar pipe and passing said pipe to \*(L"parse_dpkg_control(HANDLE[, FLAGS[, \s-1LINES\s0]])\*(R". .Sp \&\s-1DEBFILE\s0 must be an ar file containing a \*(L"control.tar.gz\*(R" member, which in turn should contain a \*(L"control\*(R" file. If the \*(L"control\*(R" file is empty this will return an empty list. .Sp Note: the control file is only expected to have a single paragraph and thus only the first is returned (in the unlikely case that there are more than one). .Sp This function may fail with any of the messages that \&\*(L"parse_dpkg_control\*(R" do. It can also emit: .Sp .Vb 1 \& "cannot fork to unpack %s: %s\en" .Ve .IP "get_dsc_control (\s-1DSCFILE\s0)" 4 .IX Item "get_dsc_control (DSCFILE)" Convenience function for reading dsc files. It will read the \s-1DSCFILE\s0 using \*(L"read_dpkg_control(FILE[, FLAGS[, \s-1LINES\s0]])\*(R" and then return the first paragraph. If the file has no paragraphs, \f(CW\*(C`undef\*(C'\fR is returned instead. .Sp Note: the control file is only expected to have a single paragraph and thus only the first is returned (in the unlikely case that there are more than one). .Sp This function may fail with any of the messages that \&\*(L"read_dpkg_control(FILE[, FLAGS[, \s-1LINES\s0]])\*(R" do. .IP "drain_pipe(\s-1FD\s0)" 4 .IX Item "drain_pipe(FD)" Reads and discards any remaining contents from \s-1FD,\s0 which is assumed to be a pipe. This is mostly done to avoid having the \*(L"write\*(R"\-end die with a \s-1SIGPIPE\s0 due to a \*(L"broken pipe\*(R" (which can happen if you just close the pipe). .Sp May cause an exception if there are issues reading from the pipe. .Sp Caveat: This will block until the pipe is closed from the \*(L"write\*(R"\-end, so only use it with pipes where the \*(L"write\*(R"\-end will eventually close their end by themselves (or something else will make them close it). .IP "get_file_digest(\s-1ALGO, FILE\s0)" 4 .IX Item "get_file_digest(ALGO, FILE)" Creates an \s-1ALGO\s0 digest object that is seeded with the contents of \&\s-1FILE. \s0 If you just want the hex digest, please use \&\*(L"get_file_checksum(\s-1ALGO, FILE\s0)\*(R" instead. .Sp \&\s-1ALGO\s0 can be 'md5' or shaX, where X is any number supported by Digest::SHA (e.g. 'sha256'). .Sp This sub is a convenience wrapper around Digest::{\s-1MD5,SHA\s0}. .IP "get_file_checksum(\s-1ALGO, FILE\s0)" 4 .IX Item "get_file_checksum(ALGO, FILE)" Returns a hexadecimal string of the message digest checksum generated by the algorithm \s-1ALGO\s0 on \s-1FILE.\s0 .Sp \&\s-1ALGO\s0 can be 'md5' or shaX, where X is any number supported by Digest::SHA (e.g. 'sha256'). .Sp This sub is a convenience wrapper around Digest::{\s-1MD5,SHA\s0}. .IP "is_string_utf8_encoded(\s-1STRING\s0)" 4 .IX Item "is_string_utf8_encoded(STRING)" Returns a truth value if \s-1STRING\s0 can be decoded as valid \s-1UTF\-8.\s0 .IP "file_is_encoded_in_non_utf8 (...)" 4 .IX Item "file_is_encoded_in_non_utf8 (...)" Undocumented .IP "\fIdo_fork()\fR" 4 .IX Item "do_fork()" Overrides fork to reset signal handlers etc. in the child. .IP "clean_env ([\s-1CLOC\s0])" 4 .IX Item "clean_env ([CLOC])" Destructively cleans \f(CW%ENV\fR \- removes all variables \f(CW%ENV\fR except a selected few whitelisted variables. .Sp The list of whitelisted \f(CW%ENV\fR variables are: .Sp .Vb 3 \& PATH \& LC_ALL (*) \& TMPDIR .Ve .Sp (*) \s-1LC_ALL\s0 is a special case as clean_env will change its value to either \*(L"C.UTF\-8\*(R" or \*(L"C\*(R" (if \s-1CLOC\s0 is given and a truth value). .IP "perm2oct(\s-1PERM\s0)" 4 .IX Item "perm2oct(PERM)" Translates \s-1PERM\s0 to an octal permission. \s-1PERM\s0 should be a string describing the permissions as done by \fItar t\fR or \fIls \-l\fR. That is, it should be a string like \*(L"\-rw\-r\*(--r\-\-\*(R". .Sp If the string does not appear to be a valid permission, it will cause a trappable error. .Sp Examples: .Sp .Vb 3 \& # Good \& perm2oct(\*(Aq\-rw\-r\-\-r\-\-\*(Aq) == 0644 \& perm2oct(\*(Aq\-rwxr\-xr\-x\*(Aq) == 0755 \& \& # Bad \& perm2oct(\*(Aqbroken\*(Aq) # too short to be recognised \& perm2oct(\*(Aq\-resurunet\*(Aq) # contains unknown permissions .Ve .IP "run_cmd([\s-1OPTS, \s0]COMMAND[, \s-1ARGS...\s0])" 4 .IX Item "run_cmd([OPTS, ]COMMAND[, ARGS...])" Executes the given \f(CW\*(C`COMMAND\*(C'\fR with the (optional) arguments \f(CW\*(C`ARGS\*(C'\fR and returns the status code as one would see it from a shell script. Shell features cannot be used. .Sp \&\s-1OPTS,\s0 if given, is a hash reference with zero or more of the following key-value pairs: .RS 4 .IP "chdir" 4 .IX Item "chdir" The child process with chdir to the given directory before executing the command. .IP "in" 4 .IX Item "in" The \s-1STDIN\s0 of the child process will be reopened and read from the filename denoted by the value of this key. By default, \s-1STDIN\s0 will reopened to read from /dev/null. .IP "out" 4 .IX Item "out" The \s-1STDOUT\s0 of the child process will be reopened and write to filename denoted by the value of this key. By default, \s-1STDOUT\s0 is discarded. .IP "update-env-vars" 4 .IX Item "update-env-vars" Each key/value pair defined in the hashref associated with \fBupdate-env-vars\fR will be updated in the child processes's environment. If a value is \f(CW\*(C`undef\*(C'\fR, then the corresponding environment variable will be removed (if set). Otherwise, the environment value will be set to that value. .RE .RS 4 .RE .IP "copy_dir (\s-1ARGS\s0)" 4 .IX Item "copy_dir (ARGS)" Convenient way of calling \fIcp \-a \s-1ARGS\s0\fR. .IP "gunzip_file (\s-1IN, OUT\s0)" 4 .IX Item "gunzip_file (IN, OUT)" Decompresses contents of the file \s-1IN\s0 and stores the contents in the file \s-1OUT. IN\s0 is \fInot\fR removed by this call. On error, this function will cause a trappable error. .IP "open_gz (\s-1FILE\s0)" 4 .IX Item "open_gz (FILE)" Opens a handle that reads from the GZip compressed \s-1FILE.\s0 .Sp On failure, this sub emits a trappable error. .Sp Note: The handle may be a pipe from an external processes. .IP "internal_error (MSG[, ...])" 4 .IX Item "internal_error (MSG[, ...])" Use to signal an internal error. The argument(s) will used to print a diagnostic message to the user. .Sp If multiple arguments are given, they will be merged into a single string (by join (' ', \f(CW@_\fR)). If only one argument is given it will be stringified and used directly. .IP "fail (MSG[, ...])" 4 .IX Item "fail (MSG[, ...])" Deprecated alias of \*(L"internal_error\*(R". .IP "locate_helper_tool(\s-1TOOLNAME\s0)" 4 .IX Item "locate_helper_tool(TOOLNAME)" Given the name of a helper tool, returns the path to it. The tool must be available in the \*(L"helpers\*(R" subdir of one of the \*(L"lintian root\*(R" directories used by Lintian. .Sp The tool name should follow the same rules as check names. Particularly, third-party checks should namespace their tools in the same way they namespace their checks. E.g. \*(L"python/some\-helper\*(R". .Sp If the tool cannot be found, this sub will cause a trappable error. .IP "strip ([\s-1LINE\s0])" 4 .IX Item "strip ([LINE])" Strips whitespace from the beginning and the end of \s-1LINE\s0 and returns it. If \s-1LINE\s0 is omitted, \f(CW$_\fR will be used instead. Example .Sp .Vb 1 \& @lines = map { strip } <$fd>; .Ve .Sp In void context, the input argument will be modified so it can be used as a replacement for chomp in some cases: .Sp .Vb 4 \& while ( my $line = <$fd> ) { \& strip ($line); \& # $line no longer has any leading or trailing whitespace \& } .Ve .Sp Otherwise, a copy of the string is returned: .Sp .Vb 6 \& while ( my $orig = <$fd> ) { \& my $stripped = strip ($orig); \& if ($stripped ne $orig) { \& # $orig had leading or/and trailing whitespace \& } \& } .Ve .IP "lstrip ([\s-1LINE\s0])" 4 .IX Item "lstrip ([LINE])" Like strip but only strip leading whitespace. .IP "rstrip ([\s-1LINE\s0])" 4 .IX Item "rstrip ([LINE])" Like strip but only strip trailing whitespace. .IP "check_path (\s-1CMD\s0)" 4 .IX Item "check_path (CMD)" Returns 1 if \s-1CMD\s0 can be found in \s-1PATH \s0(i.e. \f(CW$ENV\fR{\s-1PATH\s0}) and is executable. Otherwise, the function return 0. .IP "dequote_name(\s-1STR, REMOVESLASH\s0)" 4 .IX Item "dequote_name(STR, REMOVESLASH)" Strip an extra layer quoting in index file names and optionally remove an initial \*(L"./\*(R" if any. .Sp Remove initial ./ by default .IP "signal_number2name(\s-1NUM\s0)" 4 .IX Item "signal_number2name(NUM)" Given a number, returns the name of the signal (without leading \&\*(L"\s-1SIG\*(R"\s0). Example: .Sp .Vb 1 \& signal_number2name(2) eq \*(AqINT\*(Aq .Ve .IP "normalize_pkg_path(\s-1PATH\s0)" 4 .IX Item "normalize_pkg_path(PATH)" Normalize \s-1PATH\s0 by removing superfluous path segments. \s-1PATH\s0 is assumed to be relative the package root. Note that the result will never start nor end with a slash, even if \s-1PATH\s0 does. .Sp As the name suggests, this is a path \*(L"normalization\*(R" rather than a true path resolution (for that use Cwd::realpath). Particularly, it assumes none of the path segments are symlinks. .Sp normalize_pkg_path will return \f(CW\*(C`q{}\*(C'\fR (i.e. the empty string) if \s-1PATH\s0 is normalized to the root dir and \f(CW\*(C`undef\*(C'\fR if the path cannot be normalized without escaping the package root. .Sp Examples: normalize_pkg_path('usr/share/java/../../../usr/share/ant/file') eq 'usr/share/ant/file' normalize_pkg_path('usr/..') eq q{}; .Sp .Vb 2 \& The following will return C: \& normalize_pkg_path(\*(Aqusr/bin/../../../../etc/passwd\*(Aq) .Ve .IP "normalize_pkg_path(\s-1CURDIR, LINK_TARGET\s0)" 4 .IX Item "normalize_pkg_path(CURDIR, LINK_TARGET)" Normalize the path obtained by following a link with \s-1LINK_TARGET\s0 as its target from \s-1CURDIR\s0 as the current directory. \s-1CURDIR\s0 is assumed to be relative to the package root. Note that the result will never start nor end with a slash, even if \s-1CURDIR\s0 or \s-1DEST\s0 does. .Sp normalize_pkg_path will return \f(CW\*(C`q{}\*(C'\fR (i.e. the empty string) if the target is the root dir and \f(CW\*(C`undef\*(C'\fR if the path cannot be normalized without escaping the package root. .Sp \&\fB\s-1CAVEAT\s0\fR: This function is \fInot always sufficient\fR to test if it is safe to open a given symlink. Use is_ancestor_of for that. If you must use this function, remember to check that the target is not a symlink (or if it is, that it can be resolved safely). .Sp Examples: .Sp .Vb 6 \& normalize_pkg_path(\*(Aqusr/share/java\*(Aq, \*(Aq../ant/file\*(Aq) eq \*(Aqusr/share/ant/file\*(Aq \& normalize_pkg_path(\*(Aqusr/share/java\*(Aq, \*(Aq../../../usr/share/ant/file\*(Aq) \& normalize_pkg_path(\*(Aqusr/share/java\*(Aq, \*(Aq/usr/share/ant/file\*(Aq) \& eq \*(Aqusr/share/ant/file\*(Aq \& normalize_pkg_path(\*(Aq/usr/share/java\*(Aq, \*(Aq/\*(Aq) eq q{}; \& normalize_pkg_path(\*(Aq/\*(Aq, \*(Aqusr/..\*(Aq) eq q{}; \& \& The following will return C: \& normalize_pkg_path(\*(Aqusr/bin\*(Aq, \*(Aq../../../../etc/passwd\*(Aq) \& normalize_pkg_path(\*(Aqusr/bin\*(Aq, \*(Aq/../etc/passwd\*(Aq) .Ve .IP "parse_boolean (\s-1STR\s0)" 4 .IX Item "parse_boolean (STR)" Attempt to parse \s-1STR\s0 as a boolean and return its value. If \s-1STR\s0 is not a valid/recognised boolean, the sub will invoke croak. .Sp The following values recognised (string checks are not case sensitive): .RS 4 .IP "The integer 0 is considered false" 4 .IX Item "The integer 0 is considered false" .PD 0 .IP "Any non-zero integer is considered true" 4 .IX Item "Any non-zero integer is considered true" .ie n .IP """true"", ""y"" and ""yes"" are considered true" 4 .el .IP "``true'', ``y'' and ``yes'' are considered true" 4 .IX Item "true, y and yes are considered true" .ie n .IP """false"", ""n"" and ""no"" are considered false" 4 .el .IP "``false'', ``n'' and ``no'' are considered false" 4 .IX Item "false, n and no are considered false" .RE .RS 4 .RE .IP "is_ancestor_of(\s-1PARENTDIR, PATH\s0)" 4 .IX Item "is_ancestor_of(PARENTDIR, PATH)" .PD Returns true if and only if \s-1PATH\s0 is \s-1PARENTDIR\s0 or a path stored somewhere within \s-1PARENTDIR \s0(or its subdirs). .Sp This function will resolve the paths; any failure to resolve the path will cause a trappable error. .IP "pipe_tee(\s-1INHANDLE,\s0 OUTHANDLES[, \s-1OPTS\s0])" 4 .IX Item "pipe_tee(INHANDLE, OUTHANDLES[, OPTS])" Read bytes from \s-1INHANDLE\s0 and copy them into all of the handles in the listref \s-1OUTHANDLES.\s0 The optional \s-1OPTS\s0 argument is a hashref of options, see below. .Sp The subroutine will continue to read from \s-1INHANDLE\s0 until it is exhausted or an error occurs (either during read or write). In case of errors, a trappable error will be raised. The handles are left open when the subroutine returns, caller must close them afterwards. .Sp Caller should ensure that handles are using \*(L"blocking\*(R" I/O. The subroutine will use sysread and syswrite when reading and writing. .Sp \&\s-1OPTS,\s0 if given, may contain the following key-value pairs: .RS 4 .IP "chunk_size" 4 .IX Item "chunk_size" A suggested buffer size for read/write. If given, it will be to sysread as \s-1LENGTH\s0 argument when reading from \s-1INHANDLE.\s0 .RE .RS 4 .RE .IP "untaint(\s-1VALUE\s0)" 4 .IX Item "untaint(VALUE)" Untaint \s-1VALUE\s0 .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fIlintian\fR\|(1)