pax_global_header 0000666 0000000 0000000 00000000064 13701116425 0014512 g ustar 00root root 0000000 0000000 52 comment=cb3bb194cca88211cbfcdde2f10c0f43c3fb8ec3
keyutils-1.6.3/ 0000775 0000000 0000000 00000000000 13701116425 0013372 5 ustar 00root root 0000000 0000000 keyutils-1.6.3/.gitignore 0000664 0000000 0000000 00000000126 13701116425 0015361 0 ustar 00root root 0000000 0000000 *~
*.o
*.os
*.so
*.a
*.so.*
/keyctl
/request-key
/key.dns_resolver
/rpmbuild
test.out
keyutils-1.6.3/LICENCE.GPL 0000664 0000000 0000000 00000043115 13701116425 0015004 0 ustar 00root root 0000000 0000000 GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C) 19yy
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.
keyutils-1.6.3/LICENCE.LGPL 0000664 0000000 0000000 00000063522 13701116425 0015124 0 ustar 00root root 0000000 0000000 GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the Lesser GPL. It also counts
as the successor of the GNU Library Public License, version 2, hence
the version number 2.1.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Lesser General Public License, applies to some
specially designated software packages--typically libraries--of the
Free Software Foundation and other authors who decide to use it. You
can use it too, but we suggest you first think carefully about whether
this license or the ordinary General Public License is the better
strategy to use in any particular case, based on the explanations below.
When we speak of free software, we are referring to freedom of use,
not price. Our General Public Licenses are designed to make sure that
you have the freedom to distribute copies of free software (and charge
for this service if you wish); that you receive source code or can get
it if you want it; that you can change the software and use pieces of
it in new free programs; and that you are informed that you can do
these things.
To protect your rights, we need to make restrictions that forbid
distributors to deny you these rights or to ask you to surrender these
rights. These restrictions translate to certain responsibilities for
you if you distribute copies of the library or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link other code with the library, you must provide
complete object files to the recipients, so that they can relink them
with the library after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
We protect your rights with a two-step method: (1) we copyright the
library, and (2) we offer you this license, which gives you legal
permission to copy, distribute and/or modify the library.
To protect each distributor, we want to make it very clear that
there is no warranty for the free library. Also, if the library is
modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.
Finally, software patents pose a constant threat to the existence of
any free program. We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
restrictive license from a patent holder. Therefore, we insist that
any patent license obtained for a version of the library must be
consistent with the full freedom of use specified in this license.
Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License. This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License. We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.
When a program is linked with a library, whether statically or using
a shared library, the combination of the two is legally speaking a
combined work, a derivative of the original library. The ordinary
General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom. The Lesser General
Public License permits more lax criteria for linking other code with
the library.
We call this license the "Lesser" General Public License because it
does Less to protect the user's freedom than the ordinary General
Public License. It also provides other free software developers Less
of an advantage over competing non-free programs. These disadvantages
are the reason we use the ordinary General Public License for many
libraries. However, the Lesser license provides advantages in certain
special circumstances.
For example, on rare occasions, there may be a special need to
encourage the widest possible use of a certain library, so that it becomes
a de-facto standard. To achieve this, non-free programs must be
allowed to use the library. A more frequent case is that a free
library does the same job as widely used non-free libraries. In this
case, there is little to gain by limiting the free library to free
software only, so we use the Lesser General Public License.
In other cases, permission to use a particular library in non-free
programs enables a greater number of people to use a large body of
free software. For example, permission to use the GNU C Library in
non-free programs enables many more people to use the whole GNU
operating system, as well as its variant, the GNU/Linux operating
system.
Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.
GNU LESSER GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library or other
program which contains a notice placed by the copyright holder or
other authorized party saying it may be distributed under the terms of
this Lesser General Public License (also called "this License").
Each licensee is addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (1) uses at run time a
copy of the library already present on the user's computer system,
rather than copying library functions into the executable, and (2)
will operate properly with a modified version of the library, if
the user installs one, as long as the modified version is
interface-compatible with the version that the work was made with.
c) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
d) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
e) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the materials to be distributed need not include anything that is
normally distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Lesser General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).
To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
Copyright (C)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!
keyutils-1.6.3/Makefile 0000664 0000000 0000000 00000025201 13701116425 0015032 0 ustar 00root root 0000000 0000000 CPPFLAGS := -I.
CFLAGS := -g -Wall -Werror
CXXFLAGS := -g -Wall -Werror
INSTALL := install
DESTDIR :=
SPECFILE := keyutils.spec
NO_GLIBC_KEYERR := 0
NO_ARLIB := 0
NO_SOLIB := 0
ETCDIR := /etc
BINDIR := /bin
SBINDIR := /sbin
SHAREDIR := /usr/share/keyutils
MANDIR := /usr/share/man
MAN1 := $(MANDIR)/man1
MAN3 := $(MANDIR)/man3
MAN5 := $(MANDIR)/man5
MAN7 := $(MANDIR)/man7
MAN8 := $(MANDIR)/man8
INCLUDEDIR := /usr/include
LN := ln
LNS := $(LN) -sf
PREFIX := /usr
###############################################################################
#
# Determine the current package version from the specfile
#
###############################################################################
vermajor := $(shell grep "%define vermajor" $(SPECFILE))
verminor := $(shell grep "%define verminor" $(SPECFILE))
MAJOR := $(word 3,$(vermajor))
MINOR := $(word 3,$(verminor))
VERSION := $(MAJOR).$(MINOR)
TARBALL := keyutils-$(VERSION).tar
ZTARBALL := $(TARBALL).bz2
###############################################################################
#
# Determine the current library version from the version script
#
###############################################################################
libversion := $(filter KEYUTILS_%,$(shell grep ^KEYUTILS_ version.lds))
libversion := $(lastword $(libversion))
libversion := $(lastword $(libversion))
APIVERSION := $(subst KEYUTILS_,,$(libversion))
vernumbers := $(subst ., ,$(APIVERSION))
APIMAJOR := $(firstword $(vernumbers))
ARLIB := libkeyutils.a
DEVELLIB := libkeyutils.so
SONAME := libkeyutils.so.$(APIMAJOR)
LIBNAME := libkeyutils.so.$(APIVERSION)
###############################################################################
#
# Guess at the appropriate lib directory and word size
#
###############################################################################
ifeq ($(origin LIBDIR),undefined)
LIBDIR := $(shell ldd /usr/bin/make | grep '\(/libc[.]\)' | sed -e 's!.*\(/.*\)/libc[.].*!\1!')
endif
ifeq ($(origin USRLIBDIR),undefined)
USRLIBDIR := $(patsubst /lib/%,/usr/lib/%,$(LIBDIR))
endif
BUILDFOR := $(shell file /usr/bin/make | sed -e 's!.*ELF \(32\|64\)-bit.*!\1!')-bit
ifeq ($(origin CFLAGS),undefined)
ifeq ($(BUILDFOR),32-bit)
CFLAGS += -m32
LIBDIR := /lib
USRLIBDIR := /usr/lib
else
ifeq ($(BUILDFOR),64-bit)
CFLAGS += -m64
LIBDIR := /lib64
USRLIBDIR := /usr/lib64
endif
endif
endif
PKGCONFIG := libkeyutils.pc
PKGCONFIG_DIR := pkgconfig
###############################################################################
#
# This is necessary if glibc doesn't know about the key management error codes
#
###############################################################################
ifeq ($(NO_GLIBC_KEYERR),1)
CFLAGS += -DNO_GLIBC_KEYERR
LIBLIBS := -ldl -lc
else
LIBLIBS :=
endif
###############################################################################
#
# Normal build rule
#
###############################################################################
all: keyctl request-key key.dns_resolver cxx
###############################################################################
#
# Build the libraries
#
###############################################################################
#RPATH = -Wl,-rpath,$(LIBDIR)
VCPPFLAGS := -DPKGBUILD="\"$(shell date -u +%F)\""
VCPPFLAGS += -DPKGVERSION="\"keyutils-$(VERSION)\""
VCPPFLAGS += -DAPIVERSION="\"libkeyutils-$(APIVERSION)\""
ifeq ($(NO_ARLIB),0)
all: $(ARLIB)
$(ARLIB): keyutils.o
$(AR) rcs $@ $<
keyutils.o: keyutils.c keyutils.h Makefile
$(CC) $(CPPFLAGS) $(VCPPFLAGS) $(CFLAGS) -UNO_GLIBC_KEYERR -o $@ -c $<
LIB_DEPENDENCY := libkeyutils.a
endif
ifeq ($(NO_SOLIB),0)
all: $(DEVELLIB)
$(DEVELLIB): $(SONAME)
$(LNS) $< $@
$(SONAME): $(LIBNAME)
$(LNS) $< $@
LIBVERS := -shared -Wl,-soname,$(SONAME) -Wl,--version-script,version.lds
$(LIBNAME): keyutils.os version.lds Makefile
$(CC) $(CFLAGS) -fPIC $(LDFLAGS) $(LIBVERS) -o $@ keyutils.os $(LIBLIBS)
keyutils.os: keyutils.c keyutils.h Makefile
$(CC) $(CPPFLAGS) $(VCPPFLAGS) $(CFLAGS) -fPIC -o $@ -c $<
LIB_DEPENDENCY := $(DEVELLIB)
endif
###############################################################################
#
# Build the programs
#
###############################################################################
%.o: %.c keyutils.h Makefile
$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $<
keyctl: keyctl.o keyctl_testing.o keyctl_watch.o $(LIB_DEPENDENCY)
$(CC) -L. $(CFLAGS) $(LDFLAGS) $(RPATH) -o $@ \
keyctl.o keyctl_testing.o keyctl_watch.o -lkeyutils
keyctl.o keyctl_testing.o keyctl_watch.o: keyctl.h
keyctl_watch.o: watch_queue.h
request-key: request-key.o $(LIB_DEPENDENCY)
$(CC) -L. $(CFLAGS) $(LDFLAGS) $(RPATH) -o $@ $< -lkeyutils
key.dns_resolver: key.dns_resolver.o dns.afsdb.o $(LIB_DEPENDENCY)
$(CC) -L. $(CFLAGS) $(LDFLAGS) $(RPATH) -o $@ \
key.dns_resolver.o dns.afsdb.o -lkeyutils -lresolv
key.dns_resolver.o: key.dns_resolver.c key.dns.h
dns.afsdb.o: dns.afsdb.c key.dns.h
###############################################################################
#
# Check that the header file has valid C++ syntax
#
###############################################################################
cxx.stamp: keyutils.h Makefile
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -x c++-header -fsyntax-only $<
touch $@
cxx: cxx.stamp
.PHONY: cxx
###############################################################################
#
# Install everything
#
###############################################################################
pkgconfig:
sed \
-e 's,@VERSION\@,$(VERSION),g' \
-e 's,@prefix\@,$(PREFIX),g' \
-e 's,@exec_prefix\@,$(PREFIX),g' \
-e 's,@libdir\@,$(USRLIBDIR),g' \
-e 's,@includedir\@,$(INCLUDEDIR),g' \
< $(PKGCONFIG).in > $(PKGCONFIG) || rm $(PKGCONFIG)
install: all
ifeq ($(NO_ARLIB),0)
$(INSTALL) -D -m 0644 $(ARLIB) $(DESTDIR)$(USRLIBDIR)/$(ARLIB)
endif
ifeq ($(NO_SOLIB),0)
$(INSTALL) -D $(LIBNAME) $(DESTDIR)$(LIBDIR)/$(LIBNAME)
$(LNS) $(LIBNAME) $(DESTDIR)$(LIBDIR)/$(SONAME)
mkdir -p $(DESTDIR)$(USRLIBDIR)
$(LNS) $(LIBDIR)/$(SONAME) $(DESTDIR)$(USRLIBDIR)/$(DEVELLIB)
sed \
-e 's,@VERSION\@,$(VERSION),g' \
-e 's,@prefix\@,$(PREFIX),g' \
-e 's,@exec_prefix\@,$(PREFIX),g' \
-e 's,@libdir\@,$(USRLIBDIR),g' \
-e 's,@includedir\@,$(INCLUDEDIR),g' \
< $(PKGCONFIG).in > $(PKGCONFIG) || rm $(PKGCONFIG)
$(INSTALL) -D $(PKGCONFIG) $(DESTDIR)$(LIBDIR)/$(PKGCONFIG_DIR)/$(PKGCONFIG)
rm $(PKGCONFIG)
endif
$(INSTALL) -D keyctl $(DESTDIR)$(BINDIR)/keyctl
$(INSTALL) -D request-key $(DESTDIR)$(SBINDIR)/request-key
$(INSTALL) -D request-key-debug.sh $(DESTDIR)$(SHAREDIR)/request-key-debug.sh
$(INSTALL) -D key.dns_resolver $(DESTDIR)$(SBINDIR)/key.dns_resolver
$(INSTALL) -D -m 0644 request-key.conf $(DESTDIR)$(ETCDIR)/request-key.conf
mkdir -p $(DESTDIR)$(ETCDIR)/request-key.d
mkdir -p $(DESTDIR)$(ETCDIR)/keyutils
mkdir -p $(DESTDIR)$(MAN1)
$(INSTALL) -m 0644 $(wildcard man/*.1) $(DESTDIR)$(MAN1)
mkdir -p $(DESTDIR)$(MAN3)
$(INSTALL) -m 0644 $(wildcard man/*.3) $(DESTDIR)$(MAN3)
mkdir -p $(DESTDIR)$(MAN5)
$(INSTALL) -m 0644 $(wildcard man/*.5) $(DESTDIR)$(MAN5)
mkdir -p $(DESTDIR)$(MAN7)
$(INSTALL) -m 0644 $(wildcard man/*.7) $(DESTDIR)$(MAN7)
mkdir -p $(DESTDIR)$(MAN8)
$(INSTALL) -m 0644 $(wildcard man/*.8) $(DESTDIR)$(MAN8)
$(LNS) keyctl_describe.3 $(DESTDIR)$(MAN3)/keyctl_describe_alloc.3
$(LNS) keyctl_get_security.3 $(DESTDIR)$(MAN3)/keyctl_get_security_alloc.3
$(LNS) keyctl_instantiate.3 $(DESTDIR)$(MAN3)/keyctl_instantiate_iov.3
$(LNS) keyctl_instantiate.3 $(DESTDIR)$(MAN3)/keyctl_reject.3
$(LNS) keyctl_instantiate.3 $(DESTDIR)$(MAN3)/keyctl_negate.3
$(LNS) keyctl_instantiate.3 $(DESTDIR)$(MAN3)/keyctl_assume_authority.3
$(LNS) keyctl_link.3 $(DESTDIR)$(MAN3)/keyctl_unlink.3
$(LNS) keyctl_read.3 $(DESTDIR)$(MAN3)/keyctl_read_alloc.3
$(LNS) recursive_key_scan.3 $(DESTDIR)$(MAN3)/recursive_session_key_scan.3
$(LNS) keyctl_dh_compute.3 $(DESTDIR)$(MAN3)/keyctl_dh_compute_alloc.3
$(LNS) keyctl_dh_compute.3 $(DESTDIR)$(MAN3)/keyctl_dh_compute_kdf.3
$(INSTALL) -D -m 0644 keyutils.h $(DESTDIR)$(INCLUDEDIR)/keyutils.h
###############################################################################
#
# Run tests
#
###############################################################################
test:
$(MAKE) -C tests run
###############################################################################
#
# Clean up
#
###############################################################################
clean:
$(MAKE) -C tests clean
$(RM) libkeyutils.so* libkeyutils.a libkeyutils.pc
$(RM) keyctl request-key key.dns_resolver
$(RM) *.o *.os *~
$(RM) debugfiles.list debugsources.list
$(RM) cxx.stamp
distclean: clean
$(RM) -r rpmbuild $(TARBALL)
###############################################################################
#
# Generate a tarball
#
###############################################################################
$(ZTARBALL):
git archive --prefix=keyutils-$(VERSION)/ --format tar -o $(TARBALL) HEAD
bzip2 -9 <$(TARBALL) >$(ZTARBALL)
tarball: $(ZTARBALL)
###############################################################################
#
# Generate an RPM
#
###############################################################################
SRCBALL := rpmbuild/SOURCES/$(TARBALL)
ZSRCBALL := rpmbuild/SOURCES/$(ZTARBALL)
BUILDID := .local
rpmver0 := $(shell rpmspec -q ./keyutils.spec --define "buildid $(BUILDID)")
rpmver1 := $(word 1,$(rpmver0))
rpmver2 := $(subst ., ,$(rpmver1))
rpmver3 := $(lastword $(rpmver2))
rpmver4 := $(patsubst %.$(rpmver3),%,$(rpmver1))
rpmver := $(patsubst keyutils-%,%,$(rpmver4))
SRPM := rpmbuild/SRPMS/keyutils-$(rpmver).src.rpm
RPMBUILDDIRS := \
--define "_srcrpmdir $(CURDIR)/rpmbuild/SRPMS" \
--define "_rpmdir $(CURDIR)/rpmbuild/RPMS" \
--define "_sourcedir $(CURDIR)/rpmbuild/SOURCES" \
--define "_specdir $(CURDIR)/rpmbuild/SPECS" \
--define "_builddir $(CURDIR)/rpmbuild/BUILD" \
--define "_buildrootdir $(CURDIR)/rpmbuild/BUILDROOT"
RPMFLAGS := \
--define "buildid $(BUILDID)"
srpm:
mkdir -p rpmbuild
chmod ug-s rpmbuild
mkdir -p rpmbuild/{SPECS,SOURCES,BUILD,BUILDROOT,RPMS,SRPMS}
git archive --prefix=keyutils-$(VERSION)/ --format tar -o $(SRCBALL) HEAD
bzip2 -9 <$(SRCBALL) >$(ZSRCBALL)
rpmbuild -ts $(ZSRCBALL) --define "_srcrpmdir rpmbuild/SRPMS" $(RPMFLAGS)
rpm: srpm
rpmbuild --rebuild $(SRPM) $(RPMBUILDDIRS) $(RPMFLAGS)
rpmlint: rpm
rpmlint $(SRPM) $(CURDIR)/rpmbuild/RPMS/*/keyutils-{,libs-,libs-devel-,debuginfo-}$(rpmver).*.rpm
###############################################################################
#
# Build debugging
#
###############################################################################
show_vars:
@echo VERSION=$(VERSION)
@echo APIVERSION=$(APIVERSION)
@echo LIBDIR=$(LIBDIR)
@echo USRLIBDIR=$(USRLIBDIR)
@echo BUILDFOR=$(BUILDFOR)
@echo SONAME=$(SONAME)
@echo LIBNAME=$(LIBNAME)
@echo SRPM=$(SRPM)
@echo rpmver=$(rpmver)
keyutils-1.6.3/README 0000664 0000000 0000000 00000000630 13701116425 0014251 0 ustar 00root root 0000000 0000000 These tools are used to control the key management system built into the Linux
kernel.
To build and install the tools and manual pages, run:
make
make install
If your glibc does not contain definitions for the new error codes and system
calls, then try:
make NO_GLIBC_KEYERR=1
The tools are licensed under the GPL and the utility library under the LGPL.
Copies of these are included in this tarball.
keyutils-1.6.3/SUBMITTING_PATCHES 0000664 0000000 0000000 00000003614 13701116425 0016155 0 ustar 00root root 0000000 0000000 ==================
SUBMITTING PATCHES
==================
Patches can be sent to the keyrings@vger.kernel.org mailing list or directly to
David Howells , the author, in a private email.
When sending patches to be included in keyutils, please certify that your patch
meets the criteria below by including include a sign-off line in your email
which looks like this:
Signed-off-by: Random J Developer
This confirms that you are permitted to submit the patch for inclusion in
keyutils under the GPLv2 licence (utilities and documentation) or the LGPLv2.1
licence (library). The full text of the certificate is as follows:
Developer's Certificate of Origin v1.1
======================================
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source licences
indicated in the file; or
(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
licence and I have the right under that licence to submit that
work with modifications, whether created in whole or in part
by me, under the same open source licence (unless I am
permitted to submit under a different licence), as indicated
in the file; or
(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.
and also that:
(d) I understand and agree that this project and the contribution are
public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source licence(s) involved.
keyutils-1.6.3/dns.afsdb.c 0000664 0000000 0000000 00000021617 13701116425 0015407 0 ustar 00root root 0000000 0000000 /*
* DNS Resolver Module User-space Helper for AFSDB records
*
* Copyright (C) Wang Lei (wang840925@gmail.com) 2010
* Authors: Wang Lei (wang840925@gmail.com)
*
* Copyright (C) David Howells (dhowells@redhat.com) 2018
*
* This is a userspace tool for querying AFSDB RR records in the DNS on behalf
* of the kernel, and converting the VL server addresses to IPv4 format so that
* they can be used by the kAFS filesystem.
*
* As some function like res_init() should use the static library, which is a
* bug of libresolv, that is the reason for cifs.upcall to reimplement.
*
* To use this program, you must tell /sbin/request-key how to invoke it. You
* need to have the keyutils package installed and something like the following
* lines added to your /etc/request-key.conf file:
*
* #OP TYPE DESCRIPTION CALLOUT INFO PROGRAM ARG1 ARG2 ARG3 ...
* ====== ============ =========== ============ ==========================
* create dns_resolver afsdb:* * /sbin/key.dns_resolver %k
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "key.dns.h"
/*
*
*/
static void afsdb_hosts_to_addrs(ns_msg handle, ns_sect section)
{
char *vllist[MAX_VLS]; /* list of name servers */
int vlsnum = 0; /* number of name servers in list */
int rrnum;
ns_rr rr;
int subtype, i, ret;
unsigned int ttl = UINT_MAX, rr_ttl;
debug("AFSDB RR count is %d", ns_msg_count(handle, section));
/* Look at all the resource records in this section. */
for (rrnum = 0; rrnum < ns_msg_count(handle, section); rrnum++) {
/* Expand the resource record number rrnum into rr. */
if (ns_parserr(&handle, section, rrnum, &rr)) {
_error("ns_parserr failed : %m");
continue;
}
/* We're only interested in AFSDB records */
if (ns_rr_type(rr) == ns_t_afsdb) {
vllist[vlsnum] = malloc(MAXDNAME);
if (!vllist[vlsnum])
error("Out of memory");
subtype = ns_get16(ns_rr_rdata(rr));
/* Expand the name server's domain name */
if (ns_name_uncompress(ns_msg_base(handle),
ns_msg_end(handle),
ns_rr_rdata(rr) + 2,
vllist[vlsnum],
MAXDNAME) < 0)
error("ns_name_uncompress failed");
rr_ttl = ns_rr_ttl(rr);
if (ttl > rr_ttl)
ttl = rr_ttl;
/* Check the domain name we've just unpacked and add it to
* the list of VL servers if it is not a duplicate.
* If it is a duplicate, just ignore it.
*/
for (i = 0; i < vlsnum; i++)
if (strcasecmp(vllist[i], vllist[vlsnum]) == 0)
goto next_one;
/* Turn the hostname into IP addresses */
ret = dns_resolver(vllist[vlsnum], NULL);
if (ret) {
debug("AFSDB RR can't resolve."
"subtype:%d, server name:%s, netmask:%u",
subtype, vllist[vlsnum], mask);
goto next_one;
}
info("AFSDB RR subtype:%d, server name:%s, ip:%*.*s, ttl:%u",
subtype, vllist[vlsnum],
(int)payload[payload_index - 1].iov_len,
(int)payload[payload_index - 1].iov_len,
(char *)payload[payload_index - 1].iov_base,
ttl);
/* prepare for the next record */
vlsnum++;
continue;
next_one:
free(vllist[vlsnum]);
}
}
key_expiry = ttl;
info("ttl: %u", key_expiry);
}
/*
*
*/
static void srv_hosts_to_addrs(ns_msg handle, ns_sect section)
{
char *vllist[MAX_VLS]; /* list of name servers */
int vlsnum = 0; /* number of name servers in list */
int rrnum;
ns_rr rr;
int subtype, i, ret;
unsigned short pref, weight, port;
unsigned int ttl = UINT_MAX, rr_ttl;
char sport[8];
debug("SRV RR count is %d", ns_msg_count(handle, section));
/* Look at all the resource records in this section. */
for (rrnum = 0; rrnum < ns_msg_count(handle, section); rrnum++) {
/* Expand the resource record number rrnum into rr. */
if (ns_parserr(&handle, section, rrnum, &rr)) {
_error("ns_parserr failed : %m");
continue;
}
if (ns_rr_type(rr) == ns_t_srv) {
vllist[vlsnum] = malloc(MAXDNAME);
if (!vllist[vlsnum])
error("Out of memory");
subtype = ns_get16(ns_rr_rdata(rr));
/* Expand the name server's domain name */
if (ns_name_uncompress(ns_msg_base(handle),
ns_msg_end(handle),
ns_rr_rdata(rr) + 6,
vllist[vlsnum],
MAXDNAME) < 0) {
_error("ns_name_uncompress failed");
continue;
}
rr_ttl = ns_rr_ttl(rr);
if (ttl > rr_ttl)
ttl = rr_ttl;
pref = ns_get16(ns_rr_rdata(rr));
weight = ns_get16(ns_rr_rdata(rr) + 2);
port = ns_get16(ns_rr_rdata(rr) + 4);
info("rdata %u %u %u", pref, weight, port);
sprintf(sport, "+%hu", port);
/* Check the domain name we've just unpacked and add it to
* the list of VL servers if it is not a duplicate.
* If it is a duplicate, just ignore it.
*/
for (i = 0; i < vlsnum; i++)
if (strcasecmp(vllist[i], vllist[vlsnum]) == 0)
goto next_one;
/* Turn the hostname into IP addresses */
ret = dns_resolver(vllist[vlsnum], sport);
if (ret) {
debug("SRV RR can't resolve."
"subtype:%d, server name:%s, netmask:%u",
subtype, vllist[vlsnum], mask);
goto next_one;
}
info("SRV RR subtype:%d, server name:%s, ip:%*.*s, ttl:%u",
subtype, vllist[vlsnum],
(int)payload[payload_index - 1].iov_len,
(int)payload[payload_index - 1].iov_len,
(char *)payload[payload_index - 1].iov_base,
ttl);
/* prepare for the next record */
vlsnum++;
continue;
next_one:
free(vllist[vlsnum]);
}
}
key_expiry = ttl;
info("ttl: %u", key_expiry);
}
/*
* Look up an AFSDB record to get the VL server addresses.
*/
static int dns_query_AFSDB(const char *cell)
{
int response_len; /* buffer length */
ns_msg handle; /* handle for response message */
union {
HEADER hdr;
u_char buf[NS_PACKETSZ];
} response; /* response buffers */
debug("Get AFSDB RR for cell name:'%s'", cell);
/* query the dns for an AFSDB resource record */
response_len = res_query(cell,
ns_c_in,
ns_t_afsdb,
response.buf,
sizeof(response));
if (response_len < 0) {
/* negative result */
_nsError(h_errno, cell);
return -1;
}
if (ns_initparse(response.buf, response_len, &handle) < 0)
error("ns_initparse: %m");
/* look up the hostnames we've obtained to get the actual addresses */
afsdb_hosts_to_addrs(handle, ns_s_an);
info("DNS query AFSDB RR results:%u ttl:%u", payload_index, key_expiry);
return 0;
}
/*
* Look up an SRV record to get the VL server addresses [RFC 5864].
*/
static int dns_query_VL_SRV(const char *cell)
{
int response_len; /* buffer length */
ns_msg handle; /* handle for response message */
union {
HEADER hdr;
u_char buf[NS_PACKETSZ];
} response;
char name[1024];
snprintf(name, sizeof(name), "_afs3-vlserver._udp.%s", cell);
debug("Get VL SRV RR for name:'%s'", name);
response_len = res_query(name,
ns_c_in,
ns_t_srv,
response.buf,
sizeof(response));
if (response_len < 0) {
/* negative result */
_nsError(h_errno, cell);
return -1;
}
if (ns_initparse(response.buf, response_len, &handle) < 0)
error("ns_initparse: %m");
/* look up the hostnames we've obtained to get the actual addresses */
srv_hosts_to_addrs(handle, ns_s_an);
info("DNS query VL SRV RR results:%u ttl:%u", payload_index, key_expiry);
return 0;
}
/*
* Instantiate the key.
*/
static __attribute__((noreturn))
void afs_instantiate(const char *cell)
{
int ret;
/* set the key's expiry time from the minimum TTL encountered */
if (!debug_mode) {
ret = keyctl_set_timeout(key, key_expiry);
if (ret == -1)
error("%s: keyctl_set_timeout: %m", __func__);
}
/* handle a lack of results */
if (payload_index == 0)
nsError(NO_DATA, cell);
/* must include a NUL char at the end of the payload */
payload[payload_index].iov_base = "";
payload[payload_index++].iov_len = 1;
dump_payload();
/* load the key with data key */
if (!debug_mode) {
ret = keyctl_instantiate_iov(key, payload, payload_index, 0);
if (ret == -1)
error("%s: keyctl_instantiate: %m", __func__);
}
exit(0);
}
/*
* Look up VL servers for AFS.
*/
void afs_look_up_VL_servers(const char *cell, char *options)
{
/* Is the IP address family limited? */
if (strcmp(options, "ipv4") == 0)
mask = INET_IP4_ONLY;
else if (strcmp(options, "ipv6") == 0)
mask = INET_IP6_ONLY;
if (dns_query_VL_SRV(cell) != 0)
dns_query_AFSDB(cell);
afs_instantiate(cell);
}
keyutils-1.6.3/key.dns.h 0000664 0000000 0000000 00000004144 13701116425 0015121 0 ustar 00root root 0000000 0000000 /*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public Licence as published by
* the Free Software Foundation; either version 2 of the Licence, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public Licence for more details.
*/
#define _GNU_SOURCE
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define MAX_VLS 15 /* Max Volume Location Servers Per-Cell */
#define INET_IP4_ONLY 0x1
#define INET_IP6_ONLY 0x2
#define INET_ALL 0xFF
#define ONE_ADDR_ONLY 0x100
/*
* key.dns_resolver.c
*/
extern key_serial_t key;
extern int debug_mode;
extern unsigned mask;
extern unsigned int key_expiry;
#define N_PAYLOAD 256
extern struct iovec payload[N_PAYLOAD];
extern int payload_index;
extern __attribute__((format(printf, 1, 2), noreturn))
void error(const char *fmt, ...);
extern __attribute__((format(printf, 1, 2)))
void _error(const char *fmt, ...);
extern __attribute__((format(printf, 1, 2)))
void warning(const char *fmt, ...);
extern __attribute__((format(printf, 1, 2)))
void info(const char *fmt, ...);
extern __attribute__((noreturn))
void nsError(int err, const char *domain);
extern void _nsError(int err, const char *domain);
extern __attribute__((format(printf, 1, 2)))
void debug(const char *fmt, ...);
extern void append_address_to_payload(const char *addr);
extern void dump_payload(void);
extern int dns_resolver(const char *server_name, const char *port);
/*
* dns.afsdb.c
*/
extern __attribute__((noreturn))
void afs_look_up_VL_servers(const char *cell, char *options);
keyutils-1.6.3/key.dns_resolver.c 0000664 0000000 0000000 00000040377 13701116425 0017045 0 ustar 00root root 0000000 0000000 /*
* DNS Resolver Module User-space Helper for AFSDB records
*
* Copyright (C) Wang Lei (wang840925@gmail.com) 2010
* Authors: Wang Lei (wang840925@gmail.com)
* David Howells (dhowells@redhat.com)
*
* This is a userspace tool for querying AFSDB RR records in the DNS on behalf
* of the kernel, and converting the VL server addresses to IPv4 format so that
* they can be used by the kAFS filesystem.
*
* Compile with:
*
* cc -o key.dns_resolver key.dns_resolver.c -lresolv -lkeyutils
*
* As some function like res_init() should use the static library, which is a
* bug of libresolv, that is the reason for cifs.upcall to reimplement.
*
* To use this program, you must tell /sbin/request-key how to invoke it. You
* need to have the keyutils package installed and something like the following
* lines added to your /etc/request-key.conf file:
*
* #OP TYPE DESCRIPTION CALLOUT INFO PROGRAM ARG1 ARG2 ARG3 ...
* ====== ============ =========== ============ ==========================
* create dns_resolver afsdb:* * /sbin/key.dns_resolver %k
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "key.dns.h"
static const char *DNS_PARSE_VERSION = "1.0";
static const char prog[] = "key.dns_resolver";
static const char key_type[] = "dns_resolver";
static const char a_query_type[] = "a";
static const char aaaa_query_type[] = "aaaa";
static const char afsdb_query_type[] = "afsdb";
static const char *config_file = "/etc/keyutils/key.dns_resolver.conf";
static bool config_specified = false;
key_serial_t key;
static int verbose;
int debug_mode;
unsigned mask = INET_ALL;
unsigned int key_expiry = 5;
/*
* segmental payload
*/
struct iovec payload[N_PAYLOAD];
int payload_index;
/*
* Print an error to stderr or the syslog, negate the key being created and
* exit
*/
void error(const char *fmt, ...)
{
va_list va;
va_start(va, fmt);
if (isatty(2)) {
vfprintf(stderr, fmt, va);
fputc('\n', stderr);
} else {
vsyslog(LOG_ERR, fmt, va);
}
va_end(va);
/*
* on error, negatively instantiate the key ourselves so that we can
* make sure the kernel doesn't hang it off of a searchable keyring
* and interfere with the next attempt to instantiate the key.
*/
if (!debug_mode)
keyctl_negate(key, 1, KEY_REQKEY_DEFL_DEFAULT);
exit(1);
}
#define error(FMT, ...) error("Error: " FMT, ##__VA_ARGS__);
/*
* Just print an error to stderr or the syslog
*/
void _error(const char *fmt, ...)
{
va_list va;
va_start(va, fmt);
if (isatty(2)) {
vfprintf(stderr, fmt, va);
fputc('\n', stderr);
} else {
vsyslog(LOG_ERR, fmt, va);
}
va_end(va);
}
/*
* Print a warning to stderr or the syslog
*/
void warning(const char *fmt, ...)
{
va_list va;
va_start(va, fmt);
if (isatty(2)) {
vfprintf(stderr, fmt, va);
fputc('\n', stderr);
} else {
vsyslog(LOG_WARNING, fmt, va);
}
va_end(va);
}
/*
* Print status information
*/
void info(const char *fmt, ...)
{
va_list va;
if (verbose < 1)
return;
va_start(va, fmt);
if (isatty(1)) {
fputs("I: ", stdout);
vfprintf(stdout, fmt, va);
fputc('\n', stdout);
} else {
vsyslog(LOG_INFO, fmt, va);
}
va_end(va);
}
/*
* Print a nameserver error and exit
*/
static const int ns_errno_map[] = {
[0] = ECONNREFUSED,
[HOST_NOT_FOUND] = ENODATA,
[TRY_AGAIN] = EAGAIN,
[NO_RECOVERY] = ECONNREFUSED,
[NO_DATA] = ENODATA,
};
void _nsError(int err, const char *domain)
{
if (isatty(2))
fprintf(stderr, "NS:%s: %s.\n", domain, hstrerror(err));
else
syslog(LOG_INFO, "%s: %s", domain, hstrerror(err));
if (err >= sizeof(ns_errno_map) / sizeof(ns_errno_map[0]))
err = ECONNREFUSED;
else
err = ns_errno_map[err];
info("Reject the key with error %d", err);
}
void nsError(int err, const char *domain)
{
unsigned timeout;
int ret;
_nsError(err, domain);
switch (err) {
case TRY_AGAIN:
timeout = 1;
break;
case 0:
case NO_RECOVERY:
timeout = 10;
break;
default:
timeout = 1 * 60;
break;
}
if (!debug_mode) {
ret = keyctl_reject(key, timeout, err, KEY_REQKEY_DEFL_DEFAULT);
if (ret == -1)
error("%s: keyctl_reject: %m", __func__);
}
exit(0);
}
/*
* Print debugging information
*/
void debug(const char *fmt, ...)
{
va_list va;
if (verbose < 2)
return;
va_start(va, fmt);
if (isatty(1)) {
fputs("D: ", stdout);
vfprintf(stdout, fmt, va);
fputc('\n', stdout);
} else {
vsyslog(LOG_DEBUG, fmt, va);
}
va_end(va);
}
/*
* Append an address to the payload segment list
*/
void append_address_to_payload(const char *addr)
{
size_t sz = strlen(addr);
char *copy;
int loop;
debug("append '%s'", addr);
if (payload_index + 2 > N_PAYLOAD - 1)
return;
/* discard duplicates */
for (loop = 0; loop < payload_index; loop++)
if (payload[loop].iov_len == sz &&
memcmp(payload[loop].iov_base, addr, sz) == 0)
return;
copy = malloc(sz);
if (!copy)
error("%s: malloc: %m", __func__);
memcpy(copy, addr, sz);
if (payload_index != 0) {
payload[payload_index ].iov_base = ",";
payload[payload_index++].iov_len = 1;
}
payload[payload_index ].iov_base = copy;
payload[payload_index++].iov_len = sz;
}
/*
* Dump the payload when debugging
*/
void dump_payload(void)
{
size_t plen, n;
char *buf, *p;
int loop;
if (debug_mode)
verbose = 1;
if (verbose < 1)
return;
plen = 0;
for (loop = 0; loop < payload_index; loop++) {
n = payload[loop].iov_len;
debug("seg[%d]: %zu", loop, n);
plen += n;
}
if (plen == 0) {
info("The key instantiation data is empty");
return;
}
debug("total: %zu", plen);
buf = malloc(plen + 1);
if (!buf)
return;
p = buf;
for (loop = 0; loop < payload_index; loop++) {
n = payload[loop].iov_len;
memcpy(p, payload[loop].iov_base, n);
p += n;
}
info("The key instantiation data is '%s'", buf);
info("The expiry time is %us", key_expiry);
free(buf);
}
/*
* Perform address resolution on a hostname and add the resulting address as a
* string to the list of payload segments.
*/
int dns_resolver(const char *server_name, const char *port)
{
struct addrinfo hints, *addr, *ai;
char buf[INET6_ADDRSTRLEN + 8 + 1];
int ret, len;
void *sa;
debug("Resolve '%s' with %x", server_name, mask);
memset(&hints, 0, sizeof(hints));
switch (mask & INET_ALL) {
case INET_IP4_ONLY: hints.ai_family = AF_INET; debug("IPv4"); break;
case INET_IP6_ONLY: hints.ai_family = AF_INET6; debug("IPv6"); break;
default: break;
}
/* resolve name to ip */
ret = getaddrinfo(server_name, NULL, &hints, &addr);
if (ret) {
info("unable to resolve hostname: %s [%s]",
server_name, gai_strerror(ret));
return -1;
}
for (ai = addr; ai; ai = ai->ai_next) {
debug("RR: %x,%x,%x,%x,%x,%s",
ai->ai_flags, ai->ai_family,
ai->ai_socktype, ai->ai_protocol,
ai->ai_addrlen, ai->ai_canonname);
/* convert address to string */
switch (ai->ai_family) {
case AF_INET:
if (!(mask & INET_IP4_ONLY))
continue;
sa = &(((struct sockaddr_in *)ai->ai_addr)->sin_addr);
len = INET_ADDRSTRLEN;
break;
case AF_INET6:
if (!(mask & INET_IP6_ONLY))
continue;
sa = &(((struct sockaddr_in6 *)ai->ai_addr)->sin6_addr);
len = INET6_ADDRSTRLEN;
break;
default:
debug("Address of unknown family %u", addr->ai_family);
continue;
}
if (!inet_ntop(ai->ai_family, sa, buf, len))
error("%s: inet_ntop: %m", __func__);
if (port)
strcat(buf, port);
append_address_to_payload(buf);
if (mask & ONE_ADDR_ONLY)
break;
}
freeaddrinfo(addr);
return 0;
}
/*
* Look up a A and/or AAAA records to get host addresses
*
* The callout_info is parsed for request options. For instance, "ipv4" to
* request only IPv4 addresses, "ipv6" to request only IPv6 addresses and
* "list" to get multiple addresses.
*/
static __attribute__((noreturn))
int dns_query_a_or_aaaa(const char *hostname, char *options)
{
int ret;
debug("Get A/AAAA RR for hostname:'%s', options:'%s'",
hostname, options);
if (!options[0]) {
/* legacy mode */
mask = INET_IP4_ONLY | ONE_ADDR_ONLY;
} else {
char *k, *val;
mask = INET_ALL | ONE_ADDR_ONLY;
do {
k = options;
options = strchr(options, ' ');
if (!options)
options = k + strlen(k);
else
*options++ = '\0';
if (!*k)
continue;
if (strchr(k, ','))
error("Option name '%s' contains a comma", k);
val = strchr(k, '=');
if (val)
*val++ = '\0';
debug("Opt %s", k);
if (strcmp(k, "ipv4") == 0) {
mask &= ~INET_ALL;
mask |= INET_IP4_ONLY;
} else if (strcmp(k, "ipv6") == 0) {
mask &= ~INET_ALL;
mask |= INET_IP6_ONLY;
} else if (strcmp(k, "list") == 0) {
mask &= ~ONE_ADDR_ONLY;
}
} while (*options);
}
/* Turn the hostname into IP addresses */
ret = dns_resolver(hostname, NULL);
if (ret)
nsError(NO_DATA, hostname);
/* handle a lack of results */
if (payload_index == 0)
nsError(NO_DATA, hostname);
/* must include a NUL char at the end of the payload */
payload[payload_index].iov_base = "";
payload[payload_index++].iov_len = 1;
dump_payload();
/* load the key with data key */
if (!debug_mode) {
ret = keyctl_set_timeout(key, key_expiry);
if (ret == -1)
error("%s: keyctl_set_timeout: %m", __func__);
ret = keyctl_instantiate_iov(key, payload, payload_index, 0);
if (ret == -1)
error("%s: keyctl_instantiate: %m", __func__);
}
exit(0);
}
/*
* Read the config file.
*/
static void read_config(void)
{
FILE *f;
char buf[4096], *b, *p, *k, *v;
unsigned int line = 0, u;
int n;
info("READ CONFIG %s", config_file);
f = fopen(config_file, "r");
if (!f) {
if (errno == ENOENT && !config_specified) {
debug("%s: %m", config_file);
return;
}
error("%s: %m", config_file);
}
while (fgets(buf, sizeof(buf) - 1, f)) {
line++;
/* Trim off leading and trailing spaces and discard whole-line
* comments.
*/
b = buf;
while (isspace(*b))
b++;
if (!*b || *b == '#')
continue;
p = strchr(b, '\n');
if (!p)
error("%s:%u: line missing newline or too long", config_file, line);
while (p > buf && isspace(p[-1]))
p--;
*p = 0;
/* Split into key[=value] pairs and trim spaces. */
k = b;
v = NULL;
b = strchr(b, '=');
if (b) {
char quote = 0;
bool esc = false;
if (b == k)
error("%s:%u: Unspecified key",
config_file, line);
/* NUL-terminate the key. */
for (p = b - 1; isspace(*p); p--)
;
p[1] = 0;
/* Strip leading spaces */
b++;
while (isspace(*b))
b++;
if (!*b)
goto missing_value;
if (*b == '"' || *b == '\'') {
quote = *b;
b++;
}
v = p = b;
while (*b) {
if (esc) {
switch (*b) {
case ' ':
case '\t':
case '"':
case '\'':
case '\\':
break;
default:
goto invalid_escape_char;
}
esc = false;
*p++ = *b++;
continue;
}
if (*b == '\\') {
esc = true;
b++;
continue;
}
if (*b == quote) {
b++;
if (*b)
goto post_quote_data;
quote = 0;
break;
}
if (!quote && *b == '#')
break; /* Terminal comment */
*p++ = *b++;
}
if (esc)
error("%s:%u: Incomplete escape", config_file, line);
if (quote)
error("%s:%u: Unclosed quotes", config_file, line);
*p = 0;
}
if (strcmp(k, "default_ttl") == 0) {
if (!v)
goto missing_value;
if (sscanf(v, "%u%n", &u, &n) != 1)
goto bad_value;
if (v[n])
goto extra_data;
if (u < 1 || u > INT_MAX)
goto out_of_range;
key_expiry = u;
} else {
warning("%s:%u: Unknown option '%s'", config_file, line, k);
}
}
if (ferror(f) || fclose(f) == EOF)
error("%s: %m", config_file);
return;
missing_value:
error("%s:%u: %s: Missing value", config_file, line, k);
invalid_escape_char:
error("%s:%u: %s: Invalid char in escape", config_file, line, k);
post_quote_data:
error("%s:%u: %s: Data after closing quote", config_file, line, k);
bad_value:
error("%s:%u: %s: Bad value", config_file, line, k);
extra_data:
error("%s:%u: %s: Extra data supplied", config_file, line, k);
out_of_range:
error("%s:%u: %s: Value out of range", config_file, line, k);
}
/*
* Dump the configuration after parsing the config file.
*/
static __attribute__((noreturn))
void config_dumper(void)
{
printf("default_ttl = %u\n", key_expiry);
exit(0);
}
/*
* Print usage details,
*/
static __attribute__((noreturn))
void usage(void)
{
if (isatty(2)) {
fprintf(stderr,
"Usage: %s [-vv] [-c config] key_serial\n",
prog);
fprintf(stderr,
"Usage: %s -D [-vv] [-c config] \n",
prog);
} else {
info("Usage: %s [-vv] [-c config] key_serial", prog);
}
exit(2);
}
static const struct option long_options[] = {
{ "config", 0, NULL, 'c' },
{ "debug", 0, NULL, 'D' },
{ "dump-config", 0, NULL, 2 },
{ "verbose", 0, NULL, 'v' },
{ "version", 0, NULL, 'V' },
{ NULL, 0, NULL, 0 }
};
/*
*
*/
int main(int argc, char *argv[])
{
int ktlen, qtlen, ret;
char *keyend, *p;
char *callout_info = NULL;
char *buf = NULL, *name;
bool dump_config = false;
openlog(prog, 0, LOG_DAEMON);
while ((ret = getopt_long(argc, argv, "c:vDV", long_options, NULL)) != -1) {
switch (ret) {
case 'c':
config_file = optarg;
config_specified = true;
continue;
case 2:
dump_config = true;
continue;
case 'D':
debug_mode = 1;
continue;
case 'V':
printf("version: %s from %s (%s)\n",
DNS_PARSE_VERSION,
keyutils_version_string,
keyutils_build_string);
exit(0);
case 'v':
verbose++;
continue;
default:
if (!isatty(2))
syslog(LOG_ERR, "unknown option: %c", ret);
usage();
}
}
argc -= optind;
argv += optind;
read_config();
if (dump_config)
config_dumper();
if (!debug_mode) {
if (argc != 1)
usage();
/* get the key ID */
if (!**argv)
error("Invalid blank key ID");
key = strtol(*argv, &p, 10);
if (*p)
error("Invalid key ID format");
/* get the key description (of the form "x;x;x;x;:") */
ret = keyctl_describe_alloc(key, &buf);
if (ret == -1)
error("keyctl_describe_alloc failed: %m");
/* get the callout_info (which can supply options) */
ret = keyctl_read_alloc(KEY_SPEC_REQKEY_AUTH_KEY, (void **)&callout_info);
if (ret == -1)
error("Invalid key callout_info read: %m");
} else {
if (argc != 2)
usage();
ret = asprintf(&buf, "%s;-1;-1;0;%s", key_type, argv[0]);
if (ret < 0)
error("Error %m");
callout_info = argv[1];
}
ret = 1;
info("Key description: '%s'", buf);
info("Callout info: '%s'", callout_info);
p = strchr(buf, ';');
if (!p)
error("Badly formatted key description '%s'", buf);
ktlen = p - buf;
/* make sure it's the type we are expecting */
if (ktlen != sizeof(key_type) - 1 ||
memcmp(buf, key_type, ktlen) != 0)
error("Key type is not supported: '%*.*s'", ktlen, ktlen, buf);
keyend = buf + ktlen + 1;
/* the actual key description follows the last semicolon */
keyend = rindex(keyend, ';');
if (!keyend)
error("Invalid key description: %s", buf);
keyend++;
name = index(keyend, ':');
if (!name)
dns_query_a_or_aaaa(keyend, callout_info);
qtlen = name - keyend;
name++;
info("Query type: '%*.*s'", qtlen, qtlen, keyend);
if ((qtlen == sizeof(a_query_type) - 1 &&
memcmp(keyend, a_query_type, sizeof(a_query_type) - 1) == 0) ||
(qtlen == sizeof(aaaa_query_type) - 1 &&
memcmp(keyend, aaaa_query_type, sizeof(aaaa_query_type) - 1) == 0)
) {
info("Do DNS query of A/AAAA type for:'%s' mask:'%s'",
name, callout_info);
dns_query_a_or_aaaa(name, callout_info);
}
if (qtlen == sizeof(afsdb_query_type) - 1 &&
memcmp(keyend, afsdb_query_type, sizeof(afsdb_query_type) - 1) == 0
) {
info("Do AFS VL server query for:'%s' mask:'%s'",
name, callout_info);
afs_look_up_VL_servers(name, callout_info);
}
error("Query type: \"%*.*s\" is not supported", qtlen, qtlen, keyend);
}
keyutils-1.6.3/keyctl.c 0000664 0000000 0000000 00000154545 13701116425 0015047 0 ustar 00root root 0000000 0000000 /* keyctl.c: key control program
*
* Copyright (C) 2005, 2011 Red Hat, Inc. All Rights Reserved.
* Written by David Howells (dhowells@redhat.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#define _GNU_SOURCE
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "keyutils.h"
#include
#include "keyctl.h"
static void try_wipe_memory(void *s, size_t n)
{
#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
#if __GLIBC_PREREQ(2,25)
explicit_bzero(s, n);
#endif
#endif
}
static nr void act_keyctl___version(int argc, char *argv[]);
static nr void act_keyctl_id(int argc, char *argv[]);
static nr void act_keyctl_show(int argc, char *argv[]);
static nr void act_keyctl_add(int argc, char *argv[]);
static nr void act_keyctl_padd(int argc, char *argv[]);
static nr void act_keyctl_request(int argc, char *argv[]);
static nr void act_keyctl_request2(int argc, char *argv[]);
static nr void act_keyctl_prequest2(int argc, char *argv[]);
static nr void act_keyctl_update(int argc, char *argv[]);
static nr void act_keyctl_pupdate(int argc, char *argv[]);
static nr void act_keyctl_newring(int argc, char *argv[]);
static nr void act_keyctl_revoke(int argc, char *argv[]);
static nr void act_keyctl_clear(int argc, char *argv[]);
static nr void act_keyctl_link(int argc, char *argv[]);
static nr void act_keyctl_unlink(int argc, char *argv[]);
static nr void act_keyctl_search(int argc, char *argv[]);
static nr void act_keyctl_read(int argc, char *argv[]);
static nr void act_keyctl_pipe(int argc, char *argv[]);
static nr void act_keyctl_print(int argc, char *argv[]);
static nr void act_keyctl_list(int argc, char *argv[]);
static nr void act_keyctl_rlist(int argc, char *argv[]);
static nr void act_keyctl_describe(int argc, char *argv[]);
static nr void act_keyctl_rdescribe(int argc, char *argv[]);
static nr void act_keyctl_chown(int argc, char *argv[]);
static nr void act_keyctl_chgrp(int argc, char *argv[]);
static nr void act_keyctl_setperm(int argc, char *argv[]);
static nr void act_keyctl_session(int argc, char *argv[]);
static nr void act_keyctl_instantiate(int argc, char *argv[]);
static nr void act_keyctl_pinstantiate(int argc, char *argv[]);
static nr void act_keyctl_negate(int argc, char *argv[]);
static nr void act_keyctl_timeout(int argc, char *argv[]);
static nr void act_keyctl_security(int argc, char *argv[]);
static nr void act_keyctl_new_session(int argc, char *argv[]);
static nr void act_keyctl_reject(int argc, char *argv[]);
static nr void act_keyctl_reap(int argc, char *argv[]);
static nr void act_keyctl_purge(int argc, char *argv[]);
static nr void act_keyctl_invalidate(int argc, char *argv[]);
static nr void act_keyctl_get_persistent(int argc, char *argv[]);
static nr void act_keyctl_dh_compute(int argc, char *argv[]);
static nr void act_keyctl_dh_compute_kdf(int argc, char *argv[]);
static nr void act_keyctl_dh_compute_kdf_oi(int argc, char *argv[]);
static nr void act_keyctl_restrict_keyring(int argc, char *argv[]);
static nr void act_keyctl_pkey_query(int argc, char *argv[]);
static nr void act_keyctl_pkey_encrypt(int argc, char *argv[]);
static nr void act_keyctl_pkey_decrypt(int argc, char *argv[]);
static nr void act_keyctl_pkey_sign(int argc, char *argv[]);
static nr void act_keyctl_pkey_verify(int argc, char *argv[]);
static nr void act_keyctl_move(int argc, char *argv[]);
static nr void act_keyctl_supports(int argc, char *argv[]);
static const struct command commands[] = {
{ act_keyctl___version, "--version", "" },
{ act_keyctl_add, "add", "[-x] " },
{ act_keyctl_chgrp, "chgrp", " " },
{ act_keyctl_chown, "chown", " " },
{ act_keyctl_clear, "clear", "" },
{ act_keyctl_describe, "describe", "" },
{ act_keyctl_dh_compute, "dh_compute", " " },
{ act_keyctl_dh_compute_kdf, "dh_compute_kdf", " " },
{ act_keyctl_dh_compute_kdf_oi, "dh_compute_kdf_oi", "[-x] " },
{ act_keyctl_get_persistent, "get_persistent", " []" },
{ act_keyctl_id, "id", "" },
{ act_keyctl_instantiate, "instantiate","[-x] " },
{ act_keyctl_invalidate,"invalidate", "" },
{ act_keyctl_link, "link", " " },
{ act_keyctl_list, "list", "" },
{ act_keyctl_move, "move", "[-f] " },
{ act_keyctl_negate, "negate", " " },
{ act_keyctl_new_session, "new_session", "[]" },
{ act_keyctl_newring, "newring", " " },
{ act_keyctl_padd, "padd", "[-x] " },
{ act_keyctl_pinstantiate, "pinstantiate","[-x] " },
{ act_keyctl_pipe, "pipe", "" },
{ act_keyctl_pkey_query, "pkey_query", " [k=v]*" },
{ act_keyctl_pkey_encrypt, "pkey_encrypt", " [k=v]*" },
{ act_keyctl_pkey_decrypt, "pkey_decrypt", " [k=v]*" },
{ act_keyctl_pkey_sign, "pkey_sign", " [k=v]*" },
{ act_keyctl_pkey_verify, "pkey_verify", " [k=v]*" },
{ act_keyctl_prequest2, "prequest2", " []" },
{ act_keyctl_print, "print", "" },
{ act_keyctl_pupdate, "pupdate", "[-x] " },
{ act_keyctl_purge, "purge", "" },
{ NULL, "purge", "[-p] [-i] " },
{ NULL, "purge", "-s " },
{ act_keyctl_rdescribe, "rdescribe", " [sep]" },
{ act_keyctl_read, "read", "" },
{ act_keyctl_reap, "reap", "[-v]" },
{ act_keyctl_reject, "reject", " " },
{ act_keyctl_request, "request", " []" },
{ act_keyctl_request2, "request2", " []" },
{ act_keyctl_restrict_keyring, "restrict_keyring", " [ []]" },
{ act_keyctl_revoke, "revoke", "" },
{ act_keyctl_rlist, "rlist", "" },
{ act_keyctl_search, "search", " []" },
{ act_keyctl_security, "security", "" },
{ act_keyctl_session, "session", "" },
{ NULL, "session", "- [ ...]" },
{ NULL, "session", " [ ...]" },
{ act_keyctl_setperm, "setperm", " " },
{ act_keyctl_show, "show", "[-x] []" },
{ act_keyctl_supports, "supports", "[ | --raw]" },
{ act_keyctl_timeout, "timeout", " " },
{ act_keyctl_unlink, "unlink", " []" },
{ act_keyctl_update, "update", "[-x] " },
{ act_keyctl_watch, "watch", "[-f] " },
{ act_keyctl_watch_add, "watch_add", " " },
{ act_keyctl_watch_rm, "watch_rm", " " },
{ act_keyctl_watch_session, "watch_session", "[-f] [-n ] [ ...]" },
{ act_keyctl_watch_sync, "watch_sync", "" },
{ act_keyctl_test, "--test", "..." },
{ NULL, NULL, NULL }
};
static int dump_key_tree(key_serial_t keyring, const char *name, int hex_key_IDs);
static void *read_file(const char *name, size_t *_size);
static uid_t myuid;
static gid_t mygid, *mygroups;
static int myngroups;
static int verbose;
/*****************************************************************************/
/*
* handle an error
*/
void error(const char *msg)
{
perror(msg);
exit(1);
}
/*****************************************************************************/
/*
*
*/
int main(int argc, char *argv[])
{
do_command(argc, argv, commands, "");
}
/*
* Execute the appropriate subcommand.
*/
void do_command(int argc, char **argv,
const struct command *commands, const char *group)
{
const struct command *cmd, *best;
int n;
argv++;
argc--;
if (argc == 0)
format();
/* find the best fit command */
best = NULL;
n = strlen(*argv);
for (cmd = commands; cmd->name; cmd++) {
if (!cmd->action)
continue;
if (strlen(cmd->name) > n)
continue;
if (memcmp(cmd->name, *argv, n) != 0)
continue;
if (cmd->name[n] == 0) {
/* exact match */
best = cmd;
break;
}
/* partial match */
if (best) {
fprintf(stderr, "Ambiguous %scommand\n", group);
exit(2);
}
best = cmd;
}
if (!best) {
fprintf(stderr, "Unknown %scommand\n", group);
exit(2);
}
best->action(argc, argv);
}
/*****************************************************************************/
/*
* display command format information
*/
void format(void)
{
const struct command *cmd;
fprintf(stderr, "Format:\n");
for (cmd = commands; cmd->name; cmd++)
fprintf(stderr, " keyctl %s %s\n", cmd->name, cmd->format);
fprintf(stderr, "\n");
fprintf(stderr, "Key/keyring ID:\n");
fprintf(stderr, " numeric keyring ID\n");
fprintf(stderr, " @t thread keyring\n");
fprintf(stderr, " @p process keyring\n");
fprintf(stderr, " @s session keyring\n");
fprintf(stderr, " @u user keyring\n");
fprintf(stderr, " @us user default session keyring\n");
fprintf(stderr, " @g group keyring\n");
fprintf(stderr, " @a assumed request_key authorisation key\n");
fprintf(stderr, "\n");
fprintf(stderr, " can be \"user\" for a user-defined keyring\n");
fprintf(stderr, "If you do this, prefix the description with \":\"\n");
exit(2);
} /* end format() */
/*****************************************************************************/
/*
* Display version information
*/
static void act_keyctl___version(int argc, char *argv[])
{
printf("keyctl from %s (Built %s)\n",
keyutils_version_string, keyutils_build_string);
exit(0);
}
/*****************************************************************************/
/*
* grab data from stdin
*/
static char *grab_stdin(size_t *_size)
{
static char input[1024 * 1024 + 1];
int n, tmp;
n = 0;
do {
tmp = read(0, input + n, sizeof(input) - 1 - n);
if (tmp < 0)
error("stdin");
if (tmp == 0)
break;
n += tmp;
} while (n < sizeof(input));
if (n >= sizeof(input)) {
fprintf(stderr, "Too much data read on stdin\n");
exit(1);
}
input[n] = '\0';
*_size = n;
return input;
} /* end grab_stdin() */
/*
* Convert hex to binary if need be.
*/
void hex2bin(void **_data, size_t *_datalen, bool as_hex)
{
unsigned char *buf, *q, h, l;
char *p, *end;
if (!as_hex || *_datalen == 0)
return;
q = buf = malloc(*_datalen / 2 + 2);
if (!buf) {
try_wipe_memory(*_data, *_datalen);
error("malloc");
}
p = *_data;
end = p + *_datalen;
while (p < end) {
if (isspace(*p)) {
p++;
continue;
}
if (end - p < 2) {
fprintf(stderr, "Short hex doublet\n");
goto ret_exit;
}
if (!isxdigit(p[0]) || !isxdigit(p[1])) {
fprintf(stderr, "Bad hex doublet\n");
goto ret_exit;
}
h = isdigit(p[0]) ? p[0] - '0' : tolower(p[0]) - 'a' + 0xa;
l = isdigit(p[1]) ? p[1] - '0' : tolower(p[1]) - 'a' + 0xa;
p += 2;
*q++ = (h << 4) | l;
}
try_wipe_memory(*_data, *_datalen);
*q = 0;
*_data = buf;
*_datalen = q - buf;
return;
ret_exit:
try_wipe_memory(*_data, *_datalen);
try_wipe_memory(buf, q - buf);
exit(1);
}
/*
* Load the groups list and grab the process's UID and GID.
*/
static void grab_creds(void)
{
static int inited;
if (inited)
return;
inited = 1;
/* grab my UID, GID and groups */
myuid = geteuid();
mygid = getegid();
myngroups = getgroups(0, NULL);
if (myuid == -1 || mygid == -1 || myngroups == -1)
error("Unable to get UID/GID/#Groups\n");
mygroups = calloc(myngroups, sizeof(gid_t));
if (!mygroups)
error("calloc");
myngroups = getgroups(myngroups, mygroups);
if (myngroups < 0)
error("Unable to get Groups\n");
}
/*****************************************************************************/
/*
* convert the permissions mask to a string representing the permissions we
* have actually been granted
*/
static void calc_perms(char *pretty, key_perm_t perm, uid_t uid, gid_t gid)
{
unsigned perms;
gid_t *pg;
int loop;
grab_creds();
perms = (perm & KEY_POS_ALL) >> 24;
if (uid == myuid) {
perms |= (perm & KEY_USR_ALL) >> 16;
goto write_mask;
}
if (gid != -1) {
if (gid == mygid) {
perms |= (perm & KEY_GRP_ALL) >> 8;
goto write_mask;
}
pg = mygroups;
for (loop = myngroups; loop > 0; loop--, pg++) {
if (gid == *pg) {
perms |= (perm & KEY_GRP_ALL) >> 8;
goto write_mask;
}
}
}
perms |= (perm & KEY_OTH_ALL);
write_mask:
sprintf(pretty, "--%c%c%c%c%c%c",
perms & KEY_OTH_SETATTR ? 'a' : '-',
perms & KEY_OTH_LINK ? 'l' : '-',
perms & KEY_OTH_SEARCH ? 's' : '-',
perms & KEY_OTH_WRITE ? 'w' : '-',
perms & KEY_OTH_READ ? 'r' : '-',
perms & KEY_OTH_VIEW ? 'v' : '-');
} /* end calc_perms() */
/*****************************************************************************/
/*
* Get a key or keyring ID.
*/
static void act_keyctl_id(int argc, char *argv[])
{
key_serial_t key;
if (argc != 2)
format();
key = get_key_id(argv[1]);
key = keyctl_get_keyring_ID(key, 0);
if (key < 0)
error("keyctl_get_keyring_ID");
printf("%d\n", key);
exit(0);
}
/*****************************************************************************/
/*
* show the parent process's session keyring
*/
static void act_keyctl_show(int argc, char *argv[])
{
key_serial_t keyring = KEY_SPEC_SESSION_KEYRING;
int hex_key_IDs = 0;
if (argc >= 2 && strcmp(argv[1], "-x") == 0) {
hex_key_IDs = 1;
argc--;
argv++;
}
if (argc > 2)
format();
if (argc == 2)
keyring = get_key_id(argv[1]);
dump_key_tree(keyring, argc == 2 ? "Keyring" : "Session Keyring", hex_key_IDs);
exit(0);
} /* end act_keyctl_show() */
/*****************************************************************************/
/*
* add a key
*/
static void act_keyctl_add(int argc, char *argv[])
{
key_serial_t dest;
size_t datalen;
void *data;
bool as_hex = false;
int ret;
if (argc > 1 && strcmp(argv[1], "-x") == 0) {
as_hex = true;
argc--;
argv++;
}
if (argc != 5)
format();
data = argv[3];
datalen = strlen(argv[3]);
hex2bin(&data, &datalen, as_hex);
dest = get_key_id(argv[4]);
ret = add_key(argv[1], argv[2], data, datalen, dest);
try_wipe_memory(data, datalen);
if (ret < 0)
error("add_key");
/* print the resulting key ID */
printf("%d\n", ret);
exit(0);
} /* end act_keyctl_add() */
/*****************************************************************************/
/*
* add a key, reading from a pipe
*/
static void act_keyctl_padd(int argc, char *argv[])
{
key_serial_t dest;
size_t datalen;
void *data;
bool as_hex = false;
int ret;
if (argc > 1 && strcmp(argv[1], "-x") == 0) {
as_hex = true;
argc--;
argv++;
}
if (argc != 4)
format();
data = grab_stdin(&datalen);
hex2bin(&data, &datalen, as_hex);
dest = get_key_id(argv[3]);
ret = add_key(argv[1], argv[2], data, datalen, dest);
try_wipe_memory(data, datalen);
if (ret < 0)
error("add_key");
/* print the resulting key ID */
printf("%d\n", ret);
exit(0);
} /* end act_keyctl_padd() */
/*****************************************************************************/
/*
* request a key
*/
static void act_keyctl_request(int argc, char *argv[])
{
key_serial_t dest;
int ret;
if (argc != 3 && argc != 4)
format();
dest = 0;
if (argc == 4)
dest = get_key_id(argv[3]);
ret = request_key(argv[1], argv[2], NULL, dest);
if (ret < 0)
error("request_key");
/* print the resulting key ID */
printf("%d\n", ret);
exit(0);
} /* end act_keyctl_request() */
/*****************************************************************************/
/*
* request a key, with recourse to /sbin/request-key
*/
static void act_keyctl_request2(int argc, char *argv[])
{
key_serial_t dest;
int ret;
if (argc != 4 && argc != 5)
format();
dest = 0;
if (argc == 5)
dest = get_key_id(argv[4]);
ret = request_key(argv[1], argv[2], argv[3], dest);
if (ret < 0)
error("request_key");
/* print the resulting key ID */
printf("%d\n", ret);
exit(0);
} /* end act_keyctl_request2() */
/*****************************************************************************/
/*
* request a key, with recourse to /sbin/request-key, reading the callout info
* from a pipe
*/
static void act_keyctl_prequest2(int argc, char *argv[])
{
char *args[6];
size_t datalen;
if (argc != 3 && argc != 4)
format();
args[0] = argv[0];
args[1] = argv[1];
args[2] = argv[2];
args[3] = grab_stdin(&datalen);
args[4] = argv[3];
args[5] = NULL;
act_keyctl_request2(argc + 1, args);
} /* end act_keyctl_prequest2() */
/*****************************************************************************/
/*
* update a key
*/
static void act_keyctl_update(int argc, char *argv[])
{
key_serial_t key;
size_t datalen;
void *data;
bool as_hex = false;
int ret;
if (argc > 1 && strcmp(argv[1], "-x") == 0) {
as_hex = true;
argc--;
argv++;
}
if (argc != 3)
format();
data = argv[2];
datalen = strlen(argv[2]);
hex2bin(&data, &datalen, as_hex);
key = get_key_id(argv[1]);
ret = keyctl_update(key, data, datalen);
try_wipe_memory(data, datalen);
if (ret < 0)
error("keyctl_update");
exit(0);
} /* end act_keyctl_update() */
/*****************************************************************************/
/*
* update a key, reading from a pipe
*/
static void act_keyctl_pupdate(int argc, char *argv[])
{
key_serial_t key;
size_t datalen;
void *data;
bool as_hex = false;
int ret;
if (argc > 1 && strcmp(argv[1], "-x") == 0) {
as_hex = true;
argc--;
argv++;
}
if (argc != 2)
format();
key = get_key_id(argv[1]);
data = grab_stdin(&datalen);
hex2bin(&data, &datalen, as_hex);
ret = keyctl_update(key, data, datalen);
try_wipe_memory(data, datalen);
if (ret < 0)
error("keyctl_update");
exit(0);
} /* end act_keyctl_pupdate() */
/*****************************************************************************/
/*
* create a new keyring
*/
static void act_keyctl_newring(int argc, char *argv[])
{
key_serial_t dest;
int ret;
if (argc != 3)
format();
dest = get_key_id(argv[2]);
ret = add_key("keyring", argv[1], NULL, 0, dest);
if (ret < 0)
error("add_key");
printf("%d\n", ret);
exit(0);
} /* end act_keyctl_newring() */
/*****************************************************************************/
/*
* revoke a key
*/
static void act_keyctl_revoke(int argc, char *argv[])
{
key_serial_t key;
if (argc != 2)
format();
key = get_key_id(argv[1]);
if (keyctl_revoke(key) < 0)
error("keyctl_revoke");
exit(0);
} /* end act_keyctl_revoke() */
/*****************************************************************************/
/*
* clear a keyring
*/
static void act_keyctl_clear(int argc, char *argv[])
{
key_serial_t keyring;
if (argc != 2)
format();
keyring = get_key_id(argv[1]);
if (keyctl_clear(keyring) < 0)
error("keyctl_clear");
exit(0);
} /* end act_keyctl_clear() */
/*****************************************************************************/
/*
* link a key to a keyring
*/
static void act_keyctl_link(int argc, char *argv[])
{
key_serial_t keyring, key;
if (argc != 3)
format();
key = get_key_id(argv[1]);
keyring = get_key_id(argv[2]);
if (keyctl_link(key, keyring) < 0)
error("keyctl_link");
exit(0);
} /* end act_keyctl_link() */
/*
* Attempt to unlink a key matching the ID
*/
static int act_keyctl_unlink_func(key_serial_t parent, key_serial_t key,
char *desc, int desc_len, void *data)
{
key_serial_t *target = data;
if (key == *target)
return keyctl_unlink(key, parent) < 0 ? 0 : 1;
return 0;
}
/*
* Unlink a key from a keyring or from the session keyring tree.
*/
static void act_keyctl_unlink(int argc, char *argv[])
{
key_serial_t keyring, key;
int n;
if (argc != 2 && argc != 3)
format();
key = get_key_id(argv[1]);
if (argc == 3) {
keyring = get_key_id(argv[2]);
if (keyctl_unlink(key, keyring) < 0)
error("keyctl_unlink");
} else {
n = recursive_session_key_scan(act_keyctl_unlink_func, &key);
printf("%d links removed\n", n);
}
exit(0);
}
/*****************************************************************************/
/*
* search a keyring for a key
*/
static void act_keyctl_search(int argc, char *argv[])
{
key_serial_t keyring, dest;
int ret;
if (argc != 4 && argc != 5)
format();
keyring = get_key_id(argv[1]);
dest = 0;
if (argc == 5)
dest = get_key_id(argv[4]);
ret = keyctl_search(keyring, argv[2], argv[3], dest);
if (ret < 0)
error("keyctl_search");
/* print the ID of the key we found */
printf("%d\n", ret);
exit(0);
} /* end act_keyctl_search() */
/*****************************************************************************/
/*
* read a key
*/
static void act_keyctl_read(int argc, char *argv[])
{
key_serial_t key;
void *buffer;
char *p;
int ret, sep, col;
if (argc != 2)
format();
key = get_key_id(argv[1]);
/* read the key payload data */
ret = keyctl_read_alloc(key, &buffer);
if (ret < 0)
error("keyctl_read_alloc");
if (ret == 0) {
printf("No data in key\n");
exit(0);
}
/* hexdump the contents */
printf("%u bytes of data in key:\n", ret);
sep = 0;
col = 0;
p = buffer;
do {
if (sep) {
putchar(sep);
sep = 0;
}
printf("%02hhx", *p);
p++;
col++;
if (col % 32 == 0)
sep = '\n';
else if (col % 4 == 0)
sep = ' ';
} while (--ret > 0);
printf("\n");
exit(0);
} /* end act_keyctl_read() */
/*****************************************************************************/
/*
* read a key and dump raw to stdout
*/
static void act_keyctl_pipe(int argc, char *argv[])
{
key_serial_t key;
void *buffer;
int ret;
if (argc != 2)
format();
key = get_key_id(argv[1]);
/* read the key payload data */
ret = keyctl_read_alloc(key, &buffer);
if (ret < 0)
error("keyctl_read_alloc");
if (ret > 0 && write(1, buffer, ret) < 0)
error("write");
exit(0);
} /* end act_keyctl_pipe() */
/*****************************************************************************/
/*
* read a key and dump to stdout in printable form
*/
static void act_keyctl_print(int argc, char *argv[])
{
key_serial_t key;
void *buffer;
char *p;
int loop, ret;
if (argc != 2)
format();
key = get_key_id(argv[1]);
/* read the key payload data */
ret = keyctl_read_alloc(key, &buffer);
if (ret < 0)
error("keyctl_read_alloc");
/* see if it's printable */
p = buffer;
for (loop = ret; loop > 0; loop--, p++)
if (!isprint(*p))
goto not_printable;
/* it is */
printf("%s\n", (char *) buffer);
exit(0);
not_printable:
/* it isn't */
printf(":hex:");
p = buffer;
for (loop = ret; loop > 0; loop--, p++)
printf("%02hhx", *p);
printf("\n");
exit(0);
} /* end act_keyctl_print() */
/*****************************************************************************/
/*
* list a keyring
*/
static void act_keyctl_list(int argc, char *argv[])
{
key_serial_t keyring, key, *pk;
key_perm_t perm;
void *keylist;
char *buffer, pretty_mask[9];
uid_t uid;
gid_t gid;
int count, tlen, dpos, n, ret;
if (argc != 2)
format();
keyring = get_key_id(argv[1]);
/* read the key payload data */
count = keyctl_read_alloc(keyring, &keylist);
if (count < 0)
error("keyctl_read_alloc");
count /= sizeof(key_serial_t);
if (count == 0) {
printf("keyring is empty\n");
exit(0);
}
/* list the keys in the keyring */
if (count == 1)
printf("1 key in keyring:\n");
else
printf("%u keys in keyring:\n", count);
pk = keylist;
do {
key = *pk++;
ret = keyctl_describe_alloc(key, &buffer);
if (ret < 0) {
printf("%9d: key inaccessible (%m)\n", key);
continue;
}
uid = 0;
gid = 0;
perm = 0;
tlen = -1;
dpos = -1;
n = sscanf((char *) buffer, "%*[^;]%n;%d;%d;%x;%n",
&tlen, &uid, &gid, &perm, &dpos);
if (n != 3) {
fprintf(stderr, "Unparsable description obtained for key %d\n", key);
exit(3);
}
calc_perms(pretty_mask, perm, uid, gid);
printf("%9d: %s %5d %5d %*.*s: %s\n",
key,
pretty_mask,
uid, gid,
tlen, tlen, buffer,
buffer + dpos);
free(buffer);
} while (--count);
exit(0);
} /* end act_keyctl_list() */
/*****************************************************************************/
/*
* produce a raw list of a keyring
*/
static void act_keyctl_rlist(int argc, char *argv[])
{
key_serial_t keyring, key, *pk;
void *keylist;
int count;
if (argc != 2)
format();
keyring = get_key_id(argv[1]);
/* read the key payload data */
count = keyctl_read_alloc(keyring, &keylist);
if (count < 0)
error("keyctl_read_alloc");
count /= sizeof(key_serial_t);
/* list the keys in the keyring */
if (count <= 0) {
printf("\n");
}
else {
pk = keylist;
for (; count > 0; count--) {
key = *pk++;
printf("%d%c", key, count == 1 ? '\n' : ' ');
}
}
exit(0);
} /* end act_keyctl_rlist() */
/*****************************************************************************/
/*
* describe a key
*/
static void act_keyctl_describe(int argc, char *argv[])
{
key_serial_t key;
key_perm_t perm;
char *buffer;
uid_t uid;
gid_t gid;
int tlen, dpos, n, ret;
if (argc != 2)
format();
key = get_key_id(argv[1]);
/* get key description */
ret = keyctl_describe_alloc(key, &buffer);
if (ret < 0)
error("keyctl_describe_alloc");
/* parse it */
uid = 0;
gid = 0;
perm = 0;
tlen = -1;
dpos = -1;
n = sscanf(buffer, "%*[^;]%n;%d;%d;%x;%n",
&tlen, &uid, &gid, &perm, &dpos);
if (n != 3) {
fprintf(stderr, "Unparsable description obtained for key %d\n", key);
exit(3);
}
/* display it */
printf("%9d:"
" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c"
" %5d %5d %*.*s: %s\n",
key,
perm & KEY_POS_SETATTR ? 'a' : '-',
perm & KEY_POS_LINK ? 'l' : '-',
perm & KEY_POS_SEARCH ? 's' : '-',
perm & KEY_POS_WRITE ? 'w' : '-',
perm & KEY_POS_READ ? 'r' : '-',
perm & KEY_POS_VIEW ? 'v' : '-',
perm & KEY_USR_SETATTR ? 'a' : '-',
perm & KEY_USR_LINK ? 'l' : '-',
perm & KEY_USR_SEARCH ? 's' : '-',
perm & KEY_USR_WRITE ? 'w' : '-',
perm & KEY_USR_READ ? 'r' : '-',
perm & KEY_USR_VIEW ? 'v' : '-',
perm & KEY_GRP_SETATTR ? 'a' : '-',
perm & KEY_GRP_LINK ? 'l' : '-',
perm & KEY_GRP_SEARCH ? 's' : '-',
perm & KEY_GRP_WRITE ? 'w' : '-',
perm & KEY_GRP_READ ? 'r' : '-',
perm & KEY_GRP_VIEW ? 'v' : '-',
perm & KEY_OTH_SETATTR ? 'a' : '-',
perm & KEY_OTH_LINK ? 'l' : '-',
perm & KEY_OTH_SEARCH ? 's' : '-',
perm & KEY_OTH_WRITE ? 'w' : '-',
perm & KEY_OTH_READ ? 'r' : '-',
perm & KEY_OTH_VIEW ? 'v' : '-',
uid, gid,
tlen, tlen, buffer,
buffer + dpos);
exit(0);
} /* end act_keyctl_describe() */
/*****************************************************************************/
/*
* get raw key description
*/
static void act_keyctl_rdescribe(int argc, char *argv[])
{
key_serial_t key;
char *buffer, *q;
int ret;
if (argc != 2 && argc != 3)
format();
if (argc == 3 && !argv[2][0])
format();
key = get_key_id(argv[1]);
/* get key description */
ret = keyctl_describe_alloc(key, &buffer);
if (ret < 0)
error("keyctl_describe");
/* replace semicolon separators with requested alternative */
if (argc == 3) {
for (q = buffer; *q; q++)
if (*q == ';')
*q = argv[2][0];
}
/* display raw description */
printf("%s\n", buffer);
exit(0);
} /* end act_keyctl_rdescribe() */
/*****************************************************************************/
/*
* change a key's ownership
*/
static void act_keyctl_chown(int argc, char *argv[])
{
key_serial_t key;
uid_t uid;
char *q;
if (argc != 3)
format();
key = get_key_id(argv[1]);
uid = strtoul(argv[2], &q, 0);
if (*q) {
fprintf(stderr, "Unparsable uid: '%s'\n", argv[2]);
exit(2);
}
if (keyctl_chown(key, uid, -1) < 0)
error("keyctl_chown");
exit(0);
} /* end act_keyctl_chown() */
/*****************************************************************************/
/*
* change a key's group ownership
*/
static void act_keyctl_chgrp(int argc, char *argv[])
{
key_serial_t key;
gid_t gid;
char *q;
if (argc != 3)
format();
key = get_key_id(argv[1]);
gid = strtoul(argv[2], &q, 0);
if (*q) {
fprintf(stderr, "Unparsable gid: '%s'\n", argv[2]);
exit(2);
}
if (keyctl_chown(key, -1, gid) < 0)
error("keyctl_chown");
exit(0);
} /* end act_keyctl_chgrp() */
/*****************************************************************************/
/*
* set the permissions on a key
*/
static void act_keyctl_setperm(int argc, char *argv[])
{
key_serial_t key;
key_perm_t perm;
char *q;
if (argc != 3)
format();
key = get_key_id(argv[1]);
perm = strtoul(argv[2], &q, 0);
if (*q) {
fprintf(stderr, "Unparsable permissions: '%s'\n", argv[2]);
exit(2);
}
if (keyctl_setperm(key, perm) < 0)
error("keyctl_setperm");
exit(0);
} /* end act_keyctl_setperm() */
/*****************************************************************************/
/*
* start a process in a new session
*/
static void act_keyctl_session(int argc, char *argv[])
{
char *p, *q;
int ret;
argv++;
argc--;
/* no extra arguments signifies a standard shell in an anonymous
* session */
p = NULL;
if (argc != 0) {
/* a dash signifies an anonymous session */
p = *argv;
if (strcmp(p, "-") == 0)
p = NULL;
argv++;
argc--;
}
/* create a new session keyring */
ret = keyctl_join_session_keyring(p);
if (ret < 0)
error("keyctl_join_session_keyring");
fprintf(stderr, "Joined session keyring: %d\n", ret);
/* run the standard shell if no arguments */
if (argc == 0) {
q = getenv("SHELL");
if (!q)
q = "/bin/sh";
execl(q, q, NULL);
error(q);
}
/* run the command specified */
execvp(argv[0], argv);
error(argv[0]);
} /* end act_keyctl_session() */
/*****************************************************************************/
/*
* instantiate a key that's under construction
*/
static void act_keyctl_instantiate(int argc, char *argv[])
{
key_serial_t key, dest;
size_t datalen;
void *data;
bool as_hex = false;
int ret;
if (argc > 1 && strcmp(argv[1], "-x") == 0) {
as_hex = true;
argc--;
argv++;
}
if (argc != 4)
format();
key = get_key_id(argv[1]);
dest = get_key_id(argv[3]);
data = argv[2];
datalen = strlen(argv[2]);
hex2bin(&data, &datalen, as_hex);
ret = keyctl_instantiate(key, data, datalen, dest);
try_wipe_memory(data, datalen);
if (ret < 0)
error("keyctl_instantiate");
exit(0);
} /* end act_keyctl_instantiate() */
/*****************************************************************************/
/*
* instantiate a key, reading from a pipe
*/
static void act_keyctl_pinstantiate(int argc, char *argv[])
{
key_serial_t key, dest;
size_t datalen;
void *data;
bool as_hex = false;
int ret;
if (argc > 1 && strcmp(argv[1], "-x") == 0) {
as_hex = true;
argc--;
argv++;
}
if (argc != 3)
format();
key = get_key_id(argv[1]);
dest = get_key_id(argv[2]);
data = grab_stdin(&datalen);
hex2bin(&data, &datalen, as_hex);
ret = keyctl_instantiate(key, data, datalen, dest);
try_wipe_memory(data, datalen);
if (ret < 0)
error("keyctl_instantiate");
exit(0);
} /* end act_keyctl_pinstantiate() */
/*****************************************************************************/
/*
* negate a key that's under construction
*/
static void act_keyctl_negate(int argc, char *argv[])
{
unsigned long timeout;
key_serial_t key, dest;
char *q;
if (argc != 4)
format();
key = get_key_id(argv[1]);
timeout = strtoul(argv[2], &q, 10);
if (*q) {
fprintf(stderr, "Unparsable timeout: '%s'\n", argv[2]);
exit(2);
}
dest = get_key_id(argv[3]);
if (keyctl_negate(key, timeout, dest) < 0)
error("keyctl_negate");
exit(0);
} /* end act_keyctl_negate() */
/*****************************************************************************/
/*
* set a key's timeout
*/
static void act_keyctl_timeout(int argc, char *argv[])
{
unsigned long timeout;
key_serial_t key;
char *q;
if (argc != 3)
format();
key = get_key_id(argv[1]);
timeout = strtoul(argv[2], &q, 10);
if (*q) {
fprintf(stderr, "Unparsable timeout: '%s'\n", argv[2]);
exit(2);
}
if (keyctl_set_timeout(key, timeout) < 0)
error("keyctl_set_timeout");
exit(0);
} /* end act_keyctl_timeout() */
/*****************************************************************************/
/*
* get a key's security label
*/
static void act_keyctl_security(int argc, char *argv[])
{
key_serial_t key;
char *buffer;
int ret;
if (argc != 2)
format();
key = get_key_id(argv[1]);
/* get key description */
ret = keyctl_get_security_alloc(key, &buffer);
if (ret < 0)
error("keyctl_getsecurity");
printf("%s\n", buffer);
exit(0);
}
/*****************************************************************************/
/*
* install a new session keyring on the parent process
*/
static void act_keyctl_new_session(int argc, char *argv[])
{
key_serial_t keyring;
if (argc != 1 && argc != 2)
format();
if (keyctl_join_session_keyring(argv[1]) < 0)
error("keyctl_join_session_keyring");
if (keyctl_session_to_parent() < 0)
error("keyctl_session_to_parent");
keyring = keyctl_get_keyring_ID(KEY_SPEC_SESSION_KEYRING, 0);
if (keyring < 0)
error("keyctl_get_keyring_ID");
/* print the resulting key ID */
printf("%d\n", keyring);
exit(0);
}
/*****************************************************************************/
/*
* reject a key that's under construction
*/
static void act_keyctl_reject(int argc, char *argv[])
{
unsigned long timeout;
key_serial_t key, dest;
unsigned long rejerr;
char *q;
if (argc != 5)
format();
key = get_key_id(argv[1]);
timeout = strtoul(argv[2], &q, 10);
if (*q) {
fprintf(stderr, "Unparsable timeout: '%s'\n", argv[2]);
exit(2);
}
if (strcmp(argv[3], "rejected") == 0) {
rejerr = EKEYREJECTED;
} else if (strcmp(argv[3], "revoked") == 0) {
rejerr = EKEYREVOKED;
} else if (strcmp(argv[3], "expired") == 0) {
rejerr = EKEYEXPIRED;
} else {
rejerr = strtoul(argv[3], &q, 10);
if (*q) {
fprintf(stderr, "Unparsable error: '%s'\n", argv[3]);
exit(2);
}
}
dest = get_key_id(argv[4]);
if (keyctl_reject(key, timeout, rejerr, dest) < 0)
error("keyctl_negate");
exit(0);
}
/*
* Attempt to unlink a key if we can't read it for reasons other than we don't
* have permission
*/
static int act_keyctl_reap_func(key_serial_t parent, key_serial_t key,
char *desc, int desc_len, void *data)
{
if (desc_len < 0 && errno != EACCES) {
if (verbose)
printf("Reap %d", key);
if (keyctl_unlink(key, parent) < 0) {
if (verbose)
printf("... failed %m\n");
return 0;
} else {
if (verbose)
printf("\n");
return 1;
};
}
return 0;
}
/*
* Reap the dead keys from the session keyring tree
*/
static void act_keyctl_reap(int argc, char *argv[])
{
int n;
if (argc > 1 && strcmp(argv[1], "-v") == 0) {
verbose = 1;
argc--;
argv++;
}
if (argc != 1)
format();
n = recursive_session_key_scan(act_keyctl_reap_func, NULL);
printf("%d keys reaped\n", n);
exit(0);
}
struct purge_data {
const char *type;
const char *desc;
size_t desc_len;
size_t type_len;
char prefix_match;
char case_indep;
};
/*
* Attempt to unlink a key matching the type
*/
static int act_keyctl_purge_type_func(key_serial_t parent, key_serial_t key,
char *raw, int raw_len, void *data)
{
const struct purge_data *purge = data;
char *p, *type;
if (parent == 0 || !raw)
return 0;
/* type is everything before the first semicolon */
type = raw;
p = memchr(raw, ';', raw_len);
if (!p)
return 0;
*p = 0;
if (strcmp(type, purge->type) != 0)
return 0;
return keyctl_unlink(key, parent) < 0 ? 0 : 1;
}
/*
* Attempt to unlink a key matching the type and description literally
*/
static int act_keyctl_purge_literal_func(key_serial_t parent, key_serial_t key,
char *raw, int raw_len, void *data)
{
const struct purge_data *purge = data;
size_t tlen;
char *p, *type, *desc;
if (parent == 0 || !raw)
return 0;
/* type is everything before the first semicolon */
type = raw;
p = memchr(type, ';', raw_len);
if (!p)
return 0;
tlen = p - type;
if (tlen != purge->type_len)
return 0;
if (memcmp(type, purge->type, tlen) != 0)
return 0;
/* description is everything after the last semicolon */
p++;
desc = memrchr(p, ';', raw + raw_len - p);
if (!desc)
return 0;
desc++;
if (purge->prefix_match) {
if (raw_len - (desc - raw) < purge->desc_len)
return 0;
} else {
if (raw_len - (desc - raw) != purge->desc_len)
return 0;
}
if (purge->case_indep) {
if (strncasecmp(purge->desc, desc, purge->desc_len) != 0)
return 0;
} else {
if (memcmp(purge->desc, desc, purge->desc_len) != 0)
return 0;
}
printf("%*.*s '%s'\n", (int)tlen, (int)tlen, type, desc);
return keyctl_unlink(key, parent) < 0 ? 0 : 1;
}
/*
* Attempt to unlink a key matching the type and description literally
*/
static int act_keyctl_purge_search_func(key_serial_t parent, key_serial_t keyring,
char *raw, int raw_len, void *data)
{
const struct purge_data *purge = data;
key_serial_t key;
int kcount = 0;
if (!raw || memcmp(raw, "keyring;", 8) != 0)
return 0;
for (;;) {
key = keyctl_search(keyring, purge->type, purge->desc, 0);
if (keyctl_unlink(key, keyring) < 0)
return kcount;
kcount++;
}
return kcount;
}
/*
* Purge matching keys from a keyring
*/
static void act_keyctl_purge(int argc, char *argv[])
{
recursive_key_scanner_t func;
struct purge_data purge = {
.prefix_match = 0,
.case_indep = 0,
};
int n = 0, search_mode = 0;
argc--;
argv++;
while (argc > 0 && argv[0][0] == '-') {
if (argv[0][1] == 's')
search_mode = 1;
else if (argv[0][1] == 'p')
purge.prefix_match = 1;
else if (argv[0][1] == 'i')
purge.case_indep = 1;
else
format();
argc--;
argv++;
}
if (argc < 1)
format();
purge.type = argv[0];
purge.desc = argv[1];
purge.type_len = strlen(purge.type);
purge.desc_len = purge.desc ? strlen(purge.desc) : 0;
if (search_mode == 1) {
if (argc != 2 || purge.prefix_match || purge.case_indep)
format();
/* purge all keys of a specific type and description, according
* to the kernel's comparator */
func = act_keyctl_purge_search_func;
} else if (argc == 1) {
if (purge.prefix_match || purge.case_indep)
format();
/* purge all keys of a specific type */
func = act_keyctl_purge_type_func;
} else if (argc == 2) {
/* purge all keys of a specific type with literally matching
* description */
func = act_keyctl_purge_literal_func;
} else {
format();
}
n = recursive_session_key_scan(func, &purge);
printf("purged %d keys\n", n);
exit(0);
}
/*****************************************************************************/
/*
* Invalidate a key
*/
static void act_keyctl_invalidate(int argc, char *argv[])
{
key_serial_t key;
if (argc != 2)
format();
key = get_key_id(argv[1]);
if (keyctl_invalidate(key) < 0)
error("keyctl_invalidate");
exit(0);
}
/*****************************************************************************/
/*
* Get the per-UID persistent keyring
*/
static void act_keyctl_get_persistent(int argc, char *argv[])
{
key_serial_t dest, ret;
uid_t uid = -1;
char *q;
if (argc != 2 && argc != 3)
format();
dest = get_key_id(argv[1]);
if (argc > 2) {
uid = strtoul(argv[2], &q, 0);
if (*q) {
fprintf(stderr, "Unparsable uid: '%s'\n", argv[2]);
exit(2);
}
}
ret = keyctl_get_persistent(uid, dest);
if (ret < 0)
error("keyctl_get_persistent");
/* print the resulting key ID */
printf("%d\n", ret);
exit(0);
}
/*****************************************************************************/
/*
* Perform Diffie-Hellman computation
*/
static void act_keyctl_dh_compute(int argc, char *argv[])
{
key_serial_t priv, prime, base;
void *buffer;
char *p;
int ret, sep, col;
if (argc != 4)
format();
priv = get_key_id(argv[1]);
prime = get_key_id(argv[2]);
base = get_key_id(argv[3]);
ret = keyctl_dh_compute_alloc(priv, prime, base, &buffer);
if (ret < 0)
error("keyctl_dh_compute_alloc");
/* hexdump the contents */
printf("%u bytes of data in result:\n", ret);
sep = 0;
col = 0;
p = buffer;
do {
if (sep) {
putchar(sep);
sep = 0;
}
printf("%02hhx", *p);
*p = 0x00; /* zeroize buffer */
p++;
col++;
if (col % 32 == 0)
sep = '\n';
else if (col % 4 == 0)
sep = ' ';
} while (--ret > 0);
printf("\n");
free(buffer);
exit(0);
}
static void act_keyctl_dh_compute_kdf(int argc, char *argv[])
{
key_serial_t private, prime, base;
char *buffer;
char *p;
int ret, sep, col;
unsigned long buflen = 0;
if (argc != 6)
format();
private = get_key_id(argv[1]);
prime = get_key_id(argv[2]);
base = get_key_id(argv[3]);
buflen = strtoul(argv[4], NULL, 10);
if (buflen == ULONG_MAX)
error("dh_compute: cannot convert generated length value");
buffer = malloc(buflen);
if (!buffer)
error("dh_compute: cannot allocate memory");
ret = keyctl_dh_compute_kdf(private, prime, base, argv[5], NULL, 0,
buffer, buflen);
if (ret < 0)
error("keyctl_dh_compute_kdf");
/* hexdump the contents */
printf("%u bytes of data in result:\n", ret);
sep = 0;
col = 0;
p = buffer;
do {
if (sep) {
putchar(sep);
sep = 0;
}
printf("%02hhx", *p);
*p = 0x00; /* zeroize buffer */
p++;
col++;
if (col % 32 == 0)
sep = '\n';
else if (col % 4 == 0)
sep = ' ';
} while (--ret > 0);
printf("\n");
free(buffer);
exit(0);
}
static void act_keyctl_dh_compute_kdf_oi(int argc, char *argv[])
{
key_serial_t private, prime, base;
char *buffer;
char *p;
int ret, sep, col;
unsigned long buflen = 0;
size_t oilen;
void *oi;
bool as_hex = false;
if (argc > 1 && strcmp(argv[1], "-x") == 0) {
as_hex = true;
argc--;
argv++;
}
if (argc != 6)
format();
private = get_key_id(argv[1]);
prime = get_key_id(argv[2]);
base = get_key_id(argv[3]);
buflen = strtoul(argv[4], NULL, 10);
if (buflen == ULONG_MAX)
error("dh_compute: cannot convert generated length value");
buffer = malloc(buflen);
if (!buffer)
error("dh_compute: cannot allocate memory");
oi = grab_stdin(&oilen);
hex2bin(&oi, &oilen, as_hex);
ret = keyctl_dh_compute_kdf(private, prime, base, argv[5], oi, oilen,
buffer, buflen);
try_wipe_memory(oi, oilen);
if (ret < 0)
error("keyctl_dh_compute_kdf");
/* hexdump the contents */
printf("%u bytes of data in result:\n", ret);
sep = 0;
col = 0;
p = buffer;
do {
if (sep) {
putchar(sep);
sep = 0;
}
printf("%02hhx", *p);
*p = 0x00; /* zeroize buffer */
p++;
col++;
if (col % 32 == 0)
sep = '\n';
else if (col % 4 == 0)
sep = ' ';
} while (--ret > 0);
printf("\n");
free(buffer);
exit(0);
}
/*****************************************************************************/
/*
* Restrict the keys that may be added to a keyring
*/
static void act_keyctl_restrict_keyring(int argc, char *argv[])
{
key_serial_t keyring;
char *type = NULL;
char *restriction = NULL;
long ret;
if (argc < 2 || argc > 4)
format();
keyring = get_key_id(argv[1]);
if (argc > 2)
type = argv[2];
if (argc == 4)
restriction = argv[3];
ret = keyctl_restrict_keyring(keyring, type, restriction);
if (ret < 0)
error("keyctl_restrict_keyring");
exit(0);
}
/*
* Parse public key operation info arguments.
*/
static void pkey_parse_info(char **argv, char info[4096])
{
int i_len = 0;
/* A number of key=val pairs can be provided after the main arguments
* to inform the kernel of things like encoding type and hash function.
*/
for (; *argv; argv++) {
int n = strlen(argv[0]);
if (!memchr(argv[0], '=', n)) {
fprintf(stderr, "Option not in key=val form\n");
exit(2);
}
if (n + 1 > 4096 - 1 - i_len) {
fprintf(stderr, "Too many info options\n");
exit(2);
}
if (i_len > 0)
info[i_len++] = ' ';
memcpy(info + i_len, argv[0], n);
i_len += n;
}
info[i_len] = 0;
}
/*
* Query a public key.
*/
static void act_keyctl_pkey_query(int argc, char *argv[])
{
struct keyctl_pkey_query result;
key_serial_t key;
char info[4096];
if (argc < 3)
format();
pkey_parse_info(argv + 3, info);
key = get_key_id(argv[1]);
if (strcmp(argv[2], "0") != 0) {
fprintf(stderr, "Password passing is not yet supported\n");
exit(2);
}
if (keyctl_pkey_query(key, info, &result) < 0)
error("keyctl_pkey_query");
printf("key_size=%u\n", result.key_size);
printf("max_data_size=%u\n", result.max_data_size);
printf("max_sig_size=%u\n", result.max_sig_size);
printf("max_enc_size=%u\n", result.max_enc_size);
printf("max_dec_size=%u\n", result.max_dec_size);
printf("encrypt=%c\n", result.supported_ops & KEYCTL_SUPPORTS_ENCRYPT ? 'y' : 'n');
printf("decrypt=%c\n", result.supported_ops & KEYCTL_SUPPORTS_DECRYPT ? 'y' : 'n');
printf("sign=%c\n", result.supported_ops & KEYCTL_SUPPORTS_SIGN ? 'y' : 'n');
printf("verify=%c\n", result.supported_ops & KEYCTL_SUPPORTS_VERIFY ? 'y' : 'n');
exit(0);
}
/*
* Encrypt a blob.
*/
static void act_keyctl_pkey_encrypt(int argc, char *argv[])
{
struct keyctl_pkey_query result;
key_serial_t key;
size_t in_len;
long out_len;
void *in, *out;
char info[4096];
if (argc < 4)
format();
pkey_parse_info(argv + 4, info);
key = get_key_id(argv[1]);
if (strcmp(argv[2], "0") != 0) {
fprintf(stderr, "Password passing is not yet supported\n");
exit(2);
}
in = read_file(argv[3], &in_len);
if (keyctl_pkey_query(key, info, &result) < 0)
error("keyctl_pkey_query");
out = malloc(result.max_dec_size);
if (!out)
error("malloc");
out_len = keyctl_pkey_encrypt(key, info,
in, in_len, out, result.max_dec_size);
if (out_len < 0)
error("keyctl_pkey_encrypt");
if (fwrite(out, out_len, 1, stdout) != 1)
error("stdout");
exit(0);
}
/*
* Decrypt a blob.
*/
static void act_keyctl_pkey_decrypt(int argc, char *argv[])
{
struct keyctl_pkey_query result;
key_serial_t key;
size_t in_len;
long out_len;
void *in, *out;
char info[4096];
if (argc < 4)
format();
pkey_parse_info(argv + 4, info);
key = get_key_id(argv[1]);
if (strcmp(argv[2], "0") != 0) {
fprintf(stderr, "Password passing is not yet supported\n");
exit(2);
}
in = read_file(argv[3], &in_len);
if (keyctl_pkey_query(key, info, &result) < 0)
error("keyctl_pkey_query");
out = malloc(result.max_enc_size);
if (!out)
error("malloc");
out_len = keyctl_pkey_decrypt(key, info,
in, in_len, out, result.max_enc_size);
if (out_len < 0)
error("keyctl_pkey_decrypt");
if (fwrite(out, out_len, 1, stdout) != 1)
error("stdout");
exit(0);
}
/*
* Create a signature
*/
static void act_keyctl_pkey_sign(int argc, char *argv[])
{
struct keyctl_pkey_query result;
key_serial_t key;
size_t in_len;
long out_len;
void *in, *out;
char info[4096];
if (argc < 4)
format();
pkey_parse_info(argv + 4, info);
key = get_key_id(argv[1]);
if (strcmp(argv[2], "0") != 0) {
fprintf(stderr, "Password passing is not yet supported\n");
exit(2);
}
in = read_file(argv[3], &in_len);
if (keyctl_pkey_query(key, info, &result) < 0)
error("keyctl_pkey_query");
out = malloc(result.max_sig_size);
if (!out)
error("malloc");
out_len = keyctl_pkey_sign(key, info,
in, in_len, out, result.max_sig_size);
if (out_len < 0)
error("keyctl_pkey_sign");
if (fwrite(out, out_len, 1, stdout) != 1)
error("stdout");
exit(0);
}
/*
* Verify a signature.
*/
static void act_keyctl_pkey_verify(int argc, char *argv[])
{
key_serial_t key;
size_t data_len, sig_len;
void *data, *sig;
char info[4096];
if (argc < 5)
format();
pkey_parse_info(argv + 5, info);
key = get_key_id(argv[1]);
if (strcmp(argv[2], "0") != 0) {
fprintf(stderr, "Password passing is not yet supported\n");
exit(2);
}
data = read_file(argv[3], &data_len);
sig = read_file(argv[4], &sig_len);
if (keyctl_pkey_verify(key, info,
data, data_len, sig, sig_len) < 0)
error("keyctl_pkey_verify");
exit(0);
}
/*
* Move a key between keyrings.
*/
static void act_keyctl_move(int argc, char *argv[])
{
key_serial_t key, from_keyring, to_keyring;
unsigned int flags = KEYCTL_MOVE_EXCL;
if (argc > 4) {
if (strcmp("-f", argv[1]) == 0) {
flags &= ~KEYCTL_MOVE_EXCL;
argc--;
argv++;
}
}
if (argc != 4)
format();
key = get_key_id(argv[1]);
from_keyring = get_key_id(argv[2]);
to_keyring = get_key_id(argv[3]);
if (keyctl_move(key, from_keyring, to_keyring, flags) < 0)
error("keyctl_move");
exit(0);
}
struct capability_def {
const char *name; /* Textual name of capability */
unsigned int index; /* Index in capabilities array */
unsigned char mask; /* Mask on capabilities array element */
};
static const struct capability_def capabilities[] = {
{ "capabilities", 0, KEYCTL_CAPS0_CAPABILITIES },
{ "persistent_keyrings", 0, KEYCTL_CAPS0_PERSISTENT_KEYRINGS },
{ "dh_compute", 0, KEYCTL_CAPS0_DIFFIE_HELLMAN },
{ "public_key", 0, KEYCTL_CAPS0_PUBLIC_KEY },
{ "big_key_type", 0, KEYCTL_CAPS0_BIG_KEY },
{ "key_invalidate", 0, KEYCTL_CAPS0_INVALIDATE },
{ "restrict_keyring", 0, KEYCTL_CAPS0_RESTRICT_KEYRING },
{ "move_key", 0, KEYCTL_CAPS0_MOVE },
{ "ns_keyring_name", 1, KEYCTL_CAPS1_NS_KEYRING_NAME },
{ "ns_key_tag", 1, KEYCTL_CAPS1_NS_KEY_TAG },
{ "notify", 1, KEYCTL_CAPS1_NOTIFICATIONS },
{}
};
/*
* Detect/list capabilities.
*/
static void act_keyctl_supports(int argc, char *argv[])
{
const struct capability_def *p;
unsigned char caps[256];
size_t len;
int i;
if (argc < 1 || argc > 2)
format();
len = keyctl_capabilities(caps, sizeof(caps));
if (len < 0)
error("keyctl_capabilities");
if (argc == 1) {
for (p = capabilities; p->name; p++)
printf("have_%s=%c\n",
p->name,
(caps[p->index] & p->mask) ? '1' : '0');
exit(0);
} else {
if (strcmp(argv[1], "--raw") == 0) {
for (i = 0; i < len; i++)
printf("%02x", caps[i]);
printf("\n");
}
for (p = capabilities; p->name; p++)
if (strcmp(argv[1], p->name) == 0)
exit((caps[p->index] & p->mask) ? 0 : 1);
exit(3);
}
}
/*****************************************************************************/
/*
* parse a key identifier
*/
key_serial_t get_key_id(char *arg)
{
key_serial_t id;
char *end;
/* handle a special keyring name */
if (arg[0] == '@') {
if (strcmp(arg, "@t" ) == 0) return KEY_SPEC_THREAD_KEYRING;
if (strcmp(arg, "@p" ) == 0) return KEY_SPEC_PROCESS_KEYRING;
if (strcmp(arg, "@s" ) == 0) return KEY_SPEC_SESSION_KEYRING;
if (strcmp(arg, "@u" ) == 0) return KEY_SPEC_USER_KEYRING;
if (strcmp(arg, "@us") == 0) return KEY_SPEC_USER_SESSION_KEYRING;
if (strcmp(arg, "@g" ) == 0) return KEY_SPEC_GROUP_KEYRING;
if (strcmp(arg, "@a" ) == 0) return KEY_SPEC_REQKEY_AUTH_KEY;
fprintf(stderr, "Unknown special key: '%s'\n", arg);
exit(2);
}
/* handle a lookup-by-name request "%:", eg: "%keyring:_ses" */
if (arg[0] == '%') {
char *type;
arg++;
if (!*arg)
goto incorrect_key_by_name_spec;
if (*arg == ':') {
type = "keyring";
arg++;
} else {
type = arg;
arg = strchr(arg, ':');
if (!arg)
goto incorrect_key_by_name_spec;
*(arg++) = '\0';
}
if (!*arg)
goto incorrect_key_by_name_spec;
id = find_key_by_type_and_desc(type, arg, 0);
if (id == -1) {
fprintf(stderr, "Can't find '%s:%s'\n", type, arg);
exit(1);
}
return id;
}
/* handle a numeric key ID */
id = strtoul(arg, &end, 0);
if (*end) {
fprintf(stderr, "Unparsable key: '%s'\n", arg);
exit(2);
}
return id;
incorrect_key_by_name_spec:
fprintf(stderr, "Incorrect key-by-name spec\n");
exit(2);
} /* end get_key_id() */
/*
* Read the contents of a file into a buffer and return it.
*/
static void *read_file(const char *name, size_t *_size)
{
struct stat st;
ssize_t r;
void *p;
int fd;
fd = open(name, O_RDONLY);
if (fd < 0)
error(name);
if (fstat(fd, &st) < 0)
error(name);
p = malloc(st.st_size);
if (!p)
error("malloc");
r = read(fd, p, st.st_size);
if (r == -1)
error(name);
if (r != st.st_size) {
fprintf(stderr, "%s: Short read\n", name);
exit(1);
}
if (close(fd) < 0)
error(name);
*_size = st.st_size;
return p;
}
/*****************************************************************************/
/*
* recursively display a key/keyring tree
*/
static int dump_key_tree_aux(key_serial_t key, int depth, int more, int hex_key_IDs)
{
static char dumpindent[64];
key_serial_t *pk;
key_perm_t perm;
size_t ringlen;
void *payload;
char *desc, type[255], pretty_mask[9];
int uid, gid, ret, n, dpos, rdepth, kcount = 0;
if (depth > 8 * 4)
return 0;
/* read the description */
ret = keyctl_describe_alloc(key, &desc);
if (ret < 0) {
printf("%d: key inaccessible (%m)\n", key);
return 0;
}
/* parse */
type[0] = 0;
uid = 0;
gid = 0;
perm = 0;
n = sscanf(desc, "%[^;];%d;%d;%x;%n",
type, &uid, &gid, &perm, &dpos);
if (n != 4) {
fprintf(stderr, "Unparsable description obtained for key %d\n", key);
exit(3);
}
/* and print */
calc_perms(pretty_mask, perm, uid, gid);
if (hex_key_IDs)
printf("0x%08x %s %5d %5d %s%s%s: %s\n",
key,
pretty_mask,
uid, gid,
dumpindent,
depth > 0 ? "\\_ " : "",
type, desc + dpos);
else
printf("%10d %s %5d %5d %s%s%s: %s\n",
key,
pretty_mask,
uid, gid,
dumpindent,
depth > 0 ? "\\_ " : "",
type, desc + dpos);
free(desc);
/* if it's a keyring then we're going to want to recursively
* display it if we can */
if (strcmp(type, "keyring") == 0) {
/* read its contents */
ret = keyctl_read_alloc(key, &payload);
if (ret < 0)
error("keyctl_read_alloc");
ringlen = ret;
kcount = ringlen / sizeof(key_serial_t);
/* walk the keyring */
pk = payload;
while (ringlen >= sizeof(key_serial_t)) {
key = *pk++;
/* recurse into next keyrings */
if (strcmp(type, "keyring") == 0) {
if (depth == 0) {
rdepth = depth;
dumpindent[rdepth++] = ' ';
dumpindent[rdepth] = 0;
}
else {
rdepth = depth;
dumpindent[rdepth++] = ' ';
dumpindent[rdepth++] = ' ';
dumpindent[rdepth++] = ' ';
dumpindent[rdepth++] = ' ';
dumpindent[rdepth] = 0;
}
if (more)
dumpindent[depth + 0] = '|';
kcount += dump_key_tree_aux(key,
rdepth,
ringlen - 4 >= sizeof(key_serial_t),
hex_key_IDs);
}
ringlen -= sizeof(key_serial_t);
}
free(payload);
}
return kcount;
} /* end dump_key_tree_aux() */
/*****************************************************************************/
/*
* recursively list a keyring's contents
*/
static int dump_key_tree(key_serial_t keyring, const char *name, int hex_key_IDs)
{
printf("%s\n", name);
keyring = keyctl_get_keyring_ID(keyring, 0);
if (keyring == -1)
error("Unable to dump key");
return dump_key_tree_aux(keyring, 0, 0, hex_key_IDs);
} /* end dump_key_tree() */
keyutils-1.6.3/keyctl.h 0000664 0000000 0000000 00000002243 13701116425 0015037 0 ustar 00root root 0000000 0000000 /* keyctl program definitions
*
* Copyright (C) 2019 Red Hat, Inc. All Rights Reserved.
* Written by David Howells (dhowells@redhat.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public Licence
* as published by the Free Software Foundation; either version
* 2 of the Licence, or (at your option) any later version.
*/
struct command {
void (*action)(int argc, char *argv[]) __attribute__((noreturn));
const char *name;
const char *format;
};
#define nr __attribute__((noreturn))
/*
* keyctl.c
*/
extern nr void do_command(int, char **, const struct command *, const char *);
extern nr void format(void) __attribute__((noreturn));
extern nr void error(const char *) __attribute__((noreturn));
extern key_serial_t get_key_id(char *);
/*
* keyctl_testing.c
*/
extern nr void act_keyctl_test(int, char *[]);
/*
* keyctl_watch.c
*/
extern nr void act_keyctl_watch(int , char *[]);
extern nr void act_keyctl_watch_add(int , char *[]);
extern nr void act_keyctl_watch_rm(int , char *[]);
extern nr void act_keyctl_watch_session(int , char *[]);
extern nr void act_keyctl_watch_sync(int , char *[]);
keyutils-1.6.3/keyctl_testing.c 0000664 0000000 0000000 00000012260 13701116425 0016567 0 ustar 00root root 0000000 0000000 /* Tests built into the keyctl program
*
* Copyright (C) 2019 Red Hat, Inc. All Rights Reserved.
* Written by David Howells (dhowells@redhat.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public Licence
* as published by the Free Software Foundation; either version
* 2 of the Licence, or (at your option) any later version.
*/
#define _GNU_SOURCE
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "keyutils.h"
#include
#include "keyctl.h"
static nr void act_keyctl_test_limits(int, char *[]);
static nr void act_keyctl_test_limits2(int, char *[]);
static const struct command test_commands[] = {
{ act_keyctl_test_limits, "limits", "" },
{ act_keyctl_test_limits2, "limits2", "" },
{ NULL, NULL, NULL }
};
static void test_format(void) __attribute__((noreturn));
static void test_format(void)
{
const struct command *cmd;
fprintf(stderr, "Format:\n");
for (cmd = test_commands; cmd->name; cmd++)
fprintf(stderr, " keyctl --test %s %s\n", cmd->name, cmd->format);
fprintf(stderr, "\n");
fprintf(stderr, "Key/keyring ID:\n");
fprintf(stderr, " numeric keyring ID\n");
fprintf(stderr, " @t thread keyring\n");
fprintf(stderr, " @p process keyring\n");
fprintf(stderr, " @s session keyring\n");
fprintf(stderr, " @u user keyring\n");
fprintf(stderr, " @us user default session keyring\n");
fprintf(stderr, " @g group keyring\n");
fprintf(stderr, " @a assumed request_key authorisation key\n");
fprintf(stderr, "\n");
fprintf(stderr, " can be \"user\" for a user-defined keyring\n");
fprintf(stderr, "If you do this, prefix the description with \":\"\n");
exit(2);
}
/*
* Provide some testing functions for "keyctl --test"
*/
void act_keyctl_test(int argc, char *argv[])
{
if (argc < 2)
test_format();
do_command(argc, argv, test_commands, "test ");
}
/*
* Test the limits of the type and description fields in add_user().
*/
static void act_keyctl_test_limits(int argc, char *argv[])
{
key_serial_t key;
char buf[8192];
int i, nr_fail = 0;
if (argc != 1)
test_format();
setvbuf(stdout, NULL, _IONBF, 0);
for (i = 0; i < sizeof(buf); i++) {
if (i % 32 == 0) {
if (i != 0)
putchar('\n');
printf("TEST SIZE %d", i);
}
buf[i] = 0;
putchar('.');
if (add_key(buf, "wibble", "a", 1, KEY_SPEC_THREAD_KEYRING) == -1) {
if (i == 0 || i >= 32) {
if (errno != EINVAL) {
putchar('\n');
fprintf(stderr, "%d type failed: %m\n", i);
nr_fail++;
}
} else {
if (errno != ENODEV) {
putchar('\n');
fprintf(stderr, "%d type failed: %m\n", i);
nr_fail++;
}
}
} else {
putchar('\n');
fprintf(stderr, "%d type unexpectedly succeeded\n", i);
nr_fail++;
}
putchar('_');
key = add_key("user", buf, "a", 1, KEY_SPEC_THREAD_KEYRING);
if (key == -1) {
if (i == 0 || i >= 4096) {
if (errno != EINVAL) {
putchar('\n');
fprintf(stderr, "%d desc failed: %m\n", i);
nr_fail++;
}
} else {
putchar('\n');
fprintf(stderr, "%d desc wrong error: %m\n", i);
nr_fail++;
}
} else {
if (i == 0 || i >= 4096) {
putchar('\n');
fprintf(stderr, "%d desc unexpectedly succeeded\n", i);
nr_fail++;
}
if (keyctl_unlink(key, KEY_SPEC_THREAD_KEYRING) == -1) {
putchar('\n');
fprintf(stderr, "Unlink failed: %m\n");
nr_fail++;
}
}
buf[i] = 'a';
if (nr_fail > 20) {
fprintf(stderr, "Aborting with too many failures\n");
exit(1);
}
}
putchar('\n');
exit(nr_fail ? 1 : 0);
}
/*
* Test the limits of the payload field in add_user(). The user-type will only
* accept sizes in the range 1-32767 bytes, though add_key() will accept up to
* just shy of 1MiB.
*/
static void act_keyctl_test_limits2(int argc, char *argv[])
{
key_serial_t key;
char buf[1030 * 1024];
int i, nr_fail = 0;
if (argc != 1)
test_format();
setvbuf(stdout, NULL, _IONBF, 0);
memset(buf, 'a', sizeof(buf));
for (i = 0; i < sizeof(buf); i++) {
if (i % 2048 == 0) {
if (i != 0)
putchar('\n');
printf("TEST SIZE %7d ", i);
}
if (i % (2048 / 32) == 0)
putchar('.');
key = add_key("user", "a", buf, i, KEY_SPEC_THREAD_KEYRING);
if (key == -1) {
if (i == 0 || i > 32767) {
if (errno != EINVAL) {
putchar('\n');
fprintf(stderr, "%d desc failed: %m\n", i);
nr_fail++;
}
} else if (errno == EDQUOT) {
/* This might happen due to us creating keys
* really fast.
*/
} else {
putchar('\n');
fprintf(stderr, "%d desc wrong error: %m\n", i);
nr_fail++;
}
} else {
if (i == 0 || i > 32767) {
putchar('\n');
fprintf(stderr, "%d desc unexpectedly succeeded\n", i);
nr_fail++;
}
if (keyctl_unlink(key, KEY_SPEC_THREAD_KEYRING) == -1) {
putchar('\n');
fprintf(stderr, "Unlink failed: %m\n");
nr_fail++;
}
}
if (nr_fail > 20) {
fprintf(stderr, "Aborting with too many failures\n");
exit(1);
}
}
putchar('\n');
exit(nr_fail ? 1 : 0);
}
keyutils-1.6.3/keyctl_watch.c 0000664 0000000 0000000 00000026763 13701116425 0016235 0 ustar 00root root 0000000 0000000 /* Key watching facility.
*
* Copyright (C) 2019 Red Hat, Inc. All Rights Reserved.
* Written by David Howells (dhowells@redhat.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public Licence
* as published by the Free Software Foundation; either version
* 2 of the Licence, or (at your option) any later version.
*/
#define _GNU_SOURCE
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "keyutils.h"
#include
#include "keyctl.h"
#include "watch_queue.h"
#define MAX_MESSAGE_COUNT 256
static int consumer_stop;
static pid_t pid_con = -1, pid_cmd = -1;
static key_serial_t session;
static int watch_fd;
static int debug;
static struct watch_notification_filter filter = {
.nr_filters = 0,
.filters = {
/* Reserve a slot */
[0] = {
.type = WATCH_TYPE_KEY_NOTIFY,
},
},
};
static inline bool after_eq(unsigned int a, unsigned int b)
{
return (signed int)(a - b) >= 0;
}
static void consumer_term(int sig)
{
consumer_stop = 1;
}
static void saw_key_change(FILE *log, struct watch_notification *n,
unsigned int len)
{
struct key_notification *k = (struct key_notification *)n;
if (len != sizeof(struct key_notification))
return;
switch (n->subtype) {
case NOTIFY_KEY_INSTANTIATED:
fprintf(log, "%u inst\n", k->key_id);
break;
case NOTIFY_KEY_UPDATED:
fprintf(log, "%u upd\n", k->key_id);
break;
case NOTIFY_KEY_LINKED:
fprintf(log, "%u link %u\n", k->key_id, k->aux);
break;
case NOTIFY_KEY_UNLINKED:
fprintf(log, "%u unlk %u\n", k->key_id, k->aux);
break;
case NOTIFY_KEY_CLEARED:
fprintf(log, "%u clr\n", k->key_id);
break;
case NOTIFY_KEY_REVOKED:
fprintf(log, "%u rev\n", k->key_id);
break;
case NOTIFY_KEY_INVALIDATED:
fprintf(log, "%u inv\n", k->key_id);
break;
case NOTIFY_KEY_SETATTR:
fprintf(log, "%u attr\n", k->key_id);
break;
}
}
/*
* Handle removal notification.
*/
static void saw_removal_notification(FILE *gc, struct watch_notification *n,
unsigned int len)
{
key_serial_t key = 0;
unsigned int wp;
wp = (n->info & WATCH_INFO_ID) >> WATCH_INFO_ID__SHIFT;
if (len >= sizeof(struct watch_notification_removal)) {
struct watch_notification_removal *r = (void *)n;
key = r->id;
}
fprintf(gc, "%u gc\n", key);
if (wp == 1)
exit(0);
}
/*
* Consume and display events.
*/
static __attribute__((noreturn))
int consumer(FILE *log, FILE *gc, int fd)
{
unsigned char buffer[433], *p, *end;
union {
struct watch_notification n;
unsigned char buf1[128];
} n;
ssize_t buf_len;
setlinebuf(log);
setlinebuf(gc);
signal(SIGTERM, consumer_term);
do {
if (!consumer_stop) {
struct pollfd pf[1];
pf[0].fd = fd;
pf[0].events = POLLIN;
pf[0].revents = 0;
if (poll(pf, 1, -1) == -1) {
if (errno == EINTR)
continue;
error("poll");
}
}
buf_len = read(fd, buffer, sizeof(buffer));
if (buf_len == -1) {
perror("read");
exit(1);
}
if (buf_len == 0) {
printf("-- END --\n");
exit(0);
}
if (buf_len > sizeof(buffer)) {
fprintf(stderr, "Read buffer overrun: %zd\n", buf_len);
exit(4);
}
if (debug)
fprintf(stderr, "read() = %zd\n", buf_len);
p = buffer;
end = buffer + buf_len;
while (p < end) {
size_t largest, len;
largest = end - p;
if (largest > 128)
largest = 128;
if (largest < sizeof(struct watch_notification)) {
fprintf(stderr, "Short message header: %zu\n", largest);
exit(4);
}
memcpy(&n, p, largest);
if (debug)
fprintf(stderr, "NOTIFY[%03zx]: ty=%06x sy=%02x i=%08x\n",
p - buffer, n.n.type, n.n.subtype, n.n.info);
len = n.n.info & WATCH_INFO_LENGTH;
if (len < sizeof(n.n) || len > largest) {
fprintf(stderr, "Bad message length: %zu/%zu\n", len, largest);
exit(1);
}
switch (n.n.type) {
case WATCH_TYPE_META:
switch (n.n.subtype) {
case WATCH_META_REMOVAL_NOTIFICATION:
saw_removal_notification(gc, &n.n, len);
break;
case WATCH_META_LOSS_NOTIFICATION:
fprintf(log, "-- LOSS --\n");
break;
default:
if (debug)
fprintf(stderr, "other meta record\n");
break;
}
break;
case WATCH_TYPE_KEY_NOTIFY:
saw_key_change(log, &n.n, len);
break;
default:
if (debug)
fprintf(stderr, "other type\n");
break;
}
p += len;
}
} while (!consumer_stop);
fprintf(log, "Monitoring terminated\n");
if (gc != log)
fprintf(gc, "Monitoring terminated\n");
exit(0);
}
/*
* Open the watch device and allocate a buffer.
*/
static int open_watch(void)
{
int pipefd[2], fd;
if (pipe2(pipefd, O_NOTIFICATION_PIPE | O_NONBLOCK) == -1)
error("pipe2");
fd = pipefd[0];
if (ioctl(fd, IOC_WATCH_QUEUE_SET_SIZE, MAX_MESSAGE_COUNT) == -1)
error("/dev/watch_queue(size)");
if (filter.nr_filters &&
ioctl(fd, IOC_WATCH_QUEUE_SET_FILTER, &filter) == -1)
error("/dev/watch_queue(filter)");
return fd;
}
/*
* Parse a filter character representation into a subtype number.
*/
static bool parse_subtype(struct watch_notification_type_filter *t, char filter)
{
static const char filter_mapping[] =
"i" /* 0 NOTIFY_KEY_INSTANTIATED */
"p" /* 1 NOTIFY_KEY_UPDATED */
"l" /* 2 NOTIFY_KEY_LINKED */
"n" /* 3 NOTIFY_KEY_UNLINKED */
"c" /* 4 NOTIFY_KEY_CLEARED */
"r" /* 5 NOTIFY_KEY_REVOKED */
"v" /* 6 NOTIFY_KEY_INVALIDATED */
"s" /* 7 NOTIFY_KEY_SETATTR */
;
const char *p;
unsigned int st_bits;
unsigned int st_index;
unsigned int st_bit;
int subtype;
p = strchr(filter_mapping, filter);
if (!p)
return false;
subtype = p - filter_mapping;
st_bits = sizeof(t->subtype_filter[0]) * 8;
st_index = subtype / st_bits;
st_bit = 1U << (subtype % st_bits);
t->subtype_filter[st_index] |= st_bit;
return true;
}
/*
* Parse filters.
*/
static void parse_watch_filter(char *str)
{
struct watch_notification_filter *f = &filter;
struct watch_notification_type_filter *t0 = &f->filters[0];
f->nr_filters = 1;
t0->type = WATCH_TYPE_KEY_NOTIFY;
for (; *str; str++) {
if (parse_subtype(t0, *str))
continue;
fprintf(stderr, "Unknown filter character '%c'\n", *str);
exit(2);
}
}
/*
* Watch a key or keyring for changes.
*/
void act_keyctl_watch(int argc, char *argv[])
{
key_serial_t key;
int wfd, opt;
while (opt = getopt(argc, argv, "f:"),
opt != -1) {
switch (opt) {
case 'f':
parse_watch_filter(optarg);
break;
default:
fprintf(stderr, "Unknown option\n");
exit(2);
}
}
argv += optind;
argc -= optind;
if (argc != 1)
format();
key = get_key_id(argv[0]);
wfd = open_watch();
if (keyctl_watch_key(key, wfd, 0x01) == -1)
error("keyctl_watch_key");
consumer(stdout, stdout, wfd);
}
/*
* Add a watch on a key to the monitor created by watch_session.
*/
void act_keyctl_watch_add(int argc, char *argv[])
{
key_serial_t key;
int fd;
if (argc != 3)
format();
fd = atoi(argv[1]);
key = get_key_id(argv[2]);
if (keyctl_watch_key(key, fd, 0x02) == -1)
error("keyctl_watch_key");
exit(0);
}
/*
* Remove a watch on a key from the monitor created by watch_session.
*/
void act_keyctl_watch_rm(int argc, char *argv[])
{
key_serial_t key;
int fd;
if (argc != 3)
format();
fd = atoi(argv[1]);
key = get_key_id(argv[2]);
if (keyctl_watch_key(key, fd, -1) == -1)
error("keyctl_watch_key");
exit(0);
}
static void exit_cleanup(void)
{
pid_t me = getpid();
int w;
if (me != pid_cmd && me != pid_con) {
keyctl_watch_key(session, watch_fd, -1);
if (pid_cmd != -1) {
kill(pid_cmd, SIGTERM);
waitpid(pid_cmd, &w, 0);
}
if (pid_con != -1) {
kill(pid_con, SIGTERM);
waitpid(pid_con, &w, 0);
}
}
}
static void run_command(int argc, char *argv[], int wfd)
{
char buf[16];
pid_cmd = fork();
if (pid_cmd == -1)
error("fork");
if (pid_cmd != 0)
return;
pid_cmd = -1;
pid_con = -1;
sprintf(buf, "%u", wfd);
setenv("KEYCTL_WATCH_FD", buf, true);
/* run the standard shell if no arguments */
if (argc == 0) {
const char *q = getenv("SHELL");
if (!q)
q = "/bin/sh";
execl(q, q, NULL);
error(q);
}
/* run the command specified */
execvp(argv[0], argv);
error(argv[0]);
}
/*
* Open a logfiles.
*/
static FILE *open_logfile(const char *logfile)
{
unsigned int flags;
FILE *log;
int lfd;
log = fopen(logfile, "a");
if (!log)
error(logfile);
lfd = fileno(log);
flags = fcntl(lfd, F_GETFD);
if (flags == -1)
error("F_GETFD");
if (fcntl(lfd, F_SETFD, flags | FD_CLOEXEC) == -1)
error("F_SETFD");
return log;
}
/*
* Set up a new session keyring with a monitor that is exposed on an explicit
* file descriptor in the program that it starts.
*/
void act_keyctl_watch_session(int argc, char *argv[])
{
const char *session_name = NULL;
const char *logfile, *gcfile, *target_fd;
unsigned int flags;
pid_t pid;
FILE *log, *gc;
int wfd, tfd, opt, w, e = 0, e2 = 0;
while (opt = getopt(argc, argv, "+df:n:"),
opt != -1) {
switch (opt) {
case 'd':
debug = 1;
break;
case 'f':
parse_watch_filter(optarg);
break;
case 'n':
session_name = optarg;
break;
default:
fprintf(stderr, "Unknown option\n");
exit(2);
}
}
argv += optind;
argc -= optind;
if (argc < 4)
format();
logfile = argv[0];
gcfile = argv[1];
target_fd = argv[2];
tfd = atoi(target_fd);
if (tfd < 3 || tfd > 9) {
fprintf(stderr, "The target fd must be between 3 and 9\n");
exit(2);
}
wfd = open_watch();
if (wfd != tfd) {
if (dup2(wfd, tfd) == -1)
error("dup2");
close(wfd);
wfd = tfd;
}
watch_fd = wfd;
atexit(exit_cleanup);
/* We want the fd to be inherited across a fork. */
flags = fcntl(wfd, F_GETFD);
if (flags == -1)
error("F_GETFD");
if (fcntl(wfd, F_SETFD, flags & ~FD_CLOEXEC) == -1)
error("F_SETFD");
log = open_logfile(logfile);
gc = open_logfile(gcfile);
pid_con = fork();
if (pid_con == -1)
error("fork");
if (pid_con == 0) {
pid_cmd = -1;
pid_con = -1;
consumer(log, gc, wfd);
}
/* Create a new session keyring and watch it. */
session = keyctl_join_session_keyring(session_name);
if (session == -1)
error("keyctl_join_session_keyring");
if (keyctl_watch_key(session, wfd, 0x01) == -1)
error("keyctl_watch_key/session");
fprintf(stderr, "Joined session keyring: %d\n", session);
/* Start the command and then wait for it to finish and the
* notification consumer to clean up.
*/
run_command(argc - 3, argv + 3, wfd);
close(wfd);
wfd = -1;
while (pid = wait(&w),
pid != -1) {
if (pid == pid_cmd) {
if (pid_con != -1)
kill(pid_con, SIGTERM);
if (WIFEXITED(w)) {
e2 = WEXITSTATUS(w);
pid_cmd = -1;
} else if (WIFSIGNALED(w)) {
e2 = WTERMSIG(w) + 128;
pid_cmd = -1;
} else if (WIFSTOPPED(w)) {
raise(WSTOPSIG(w));
}
} else if (pid == pid_con) {
if (pid_cmd != -1)
kill(pid_cmd, SIGTERM);
if (WIFEXITED(w)) {
e = WEXITSTATUS(w);
pid_con = -1;
} else if (WIFSIGNALED(w)) {
e = WTERMSIG(w) + 128;
pid_con = -1;
}
}
}
if (e == 0)
e = e2;
exit(e);
}
/*
* Wait for monitoring to synchronise.
*/
void act_keyctl_watch_sync(int argc, char *argv[])
{
long ret;
int wfd, count;
if (argc != 2)
format();
wfd = atoi(argv[1]);
ret = ioctl(wfd, PIPE_IOC_SYNC);
if (ret == 0)
exit(0);
if (ret == -1 && errno != ENOTTY)
error("ioctl(PIPE_IOC_SYNC)");
for (;;) {
ret = ioctl(wfd, FIONREAD, &count);
if (ret == -1)
error("ioctl(FIONREAD)");
if (count == 0)
break;
usleep(200 * 1000);
}
exit(0);
}
keyutils-1.6.3/keyutils.c 0000664 0000000 0000000 00000045265 13701116425 0015423 0 ustar 00root root 0000000 0000000 /* keyutils.c: key utility library
*
* Copyright (C) 2005,2011 Red Hat, Inc. All Rights Reserved.
* Written by David Howells (dhowells@redhat.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "keyutils.h"
const char keyutils_version_string[] = PKGVERSION;
const char keyutils_build_string[] = PKGBUILD;
#ifdef NO_GLIBC_KEYERR
static int error_inited;
static void (*libc_perror)(const char *msg);
static char *(*libc_strerror_r)(int errnum, char *buf, size_t n);
//static int (*libc_xpg_strerror_r)(int errnum, char *buf, size_t n);
#define RTLD_NEXT ((void *) -1L)
#endif
#define __weak __attribute__((weak))
key_serial_t __weak add_key(const char *type,
const char *description,
const void *payload,
size_t plen,
key_serial_t ringid)
{
return syscall(__NR_add_key,
type, description, payload, plen, ringid);
}
key_serial_t __weak request_key(const char *type,
const char *description,
const char * callout_info,
key_serial_t destringid)
{
return syscall(__NR_request_key,
type, description, callout_info, destringid);
}
static inline long __keyctl(int cmd,
unsigned long arg2,
unsigned long arg3,
unsigned long arg4,
unsigned long arg5)
{
return syscall(__NR_keyctl,
cmd, arg2, arg3, arg4, arg5);
}
long __weak keyctl(int cmd, ...)
{
va_list va;
unsigned long arg2, arg3, arg4, arg5;
va_start(va, cmd);
arg2 = va_arg(va, unsigned long);
arg3 = va_arg(va, unsigned long);
arg4 = va_arg(va, unsigned long);
arg5 = va_arg(va, unsigned long);
va_end(va);
return __keyctl(cmd, arg2, arg3, arg4, arg5);
}
key_serial_t keyctl_get_keyring_ID(key_serial_t id, int create)
{
return keyctl(KEYCTL_GET_KEYRING_ID, id, create);
}
key_serial_t keyctl_join_session_keyring(const char *name)
{
return keyctl(KEYCTL_JOIN_SESSION_KEYRING, name);
}
long keyctl_update(key_serial_t id, const void *payload, size_t plen)
{
return keyctl(KEYCTL_UPDATE, id, payload, plen);
}
long keyctl_revoke(key_serial_t id)
{
return keyctl(KEYCTL_REVOKE, id);
}
long keyctl_chown(key_serial_t id, uid_t uid, gid_t gid)
{
return keyctl(KEYCTL_CHOWN, id, uid, gid);
}
long keyctl_setperm(key_serial_t id, key_perm_t perm)
{
return keyctl(KEYCTL_SETPERM, id, perm);
}
long keyctl_describe(key_serial_t id, char *buffer, size_t buflen)
{
return keyctl(KEYCTL_DESCRIBE, id, buffer, buflen);
}
long keyctl_clear(key_serial_t ringid)
{
return keyctl(KEYCTL_CLEAR, ringid);
}
long keyctl_link(key_serial_t id, key_serial_t ringid)
{
return keyctl(KEYCTL_LINK, id, ringid);
}
long keyctl_unlink(key_serial_t id, key_serial_t ringid)
{
return keyctl(KEYCTL_UNLINK, id, ringid);
}
long keyctl_search(key_serial_t ringid,
const char *type,
const char *description,
key_serial_t destringid)
{
return keyctl(KEYCTL_SEARCH, ringid, type, description, destringid);
}
long keyctl_read(key_serial_t id, char *buffer, size_t buflen)
{
return keyctl(KEYCTL_READ, id, buffer, buflen);
}
long keyctl_instantiate(key_serial_t id,
const void *payload,
size_t plen,
key_serial_t ringid)
{
return keyctl(KEYCTL_INSTANTIATE, id, payload, plen, ringid);
}
long keyctl_negate(key_serial_t id, unsigned timeout, key_serial_t ringid)
{
return keyctl(KEYCTL_NEGATE, id, timeout, ringid);
}
long keyctl_set_reqkey_keyring(int reqkey_defl)
{
return keyctl(KEYCTL_SET_REQKEY_KEYRING, reqkey_defl);
}
long keyctl_set_timeout(key_serial_t id, unsigned timeout)
{
return keyctl(KEYCTL_SET_TIMEOUT, id, timeout);
}
long keyctl_assume_authority(key_serial_t id)
{
return keyctl(KEYCTL_ASSUME_AUTHORITY, id);
}
long keyctl_get_security(key_serial_t id, char *buffer, size_t buflen)
{
return keyctl(KEYCTL_GET_SECURITY, id, buffer, buflen);
}
long keyctl_session_to_parent(void)
{
return keyctl(KEYCTL_SESSION_TO_PARENT);
}
long keyctl_reject(key_serial_t id, unsigned timeout, unsigned error,
key_serial_t ringid)
{
long ret = keyctl(KEYCTL_REJECT, id, timeout, error, ringid);
/* fall back to keyctl_negate() if this op is not supported by this
* kernel version */
if (ret == -1 && errno == EOPNOTSUPP)
return keyctl_negate(id, timeout, ringid);
return ret;
}
long keyctl_instantiate_iov(key_serial_t id,
const struct iovec *payload_iov,
unsigned ioc,
key_serial_t ringid)
{
long ret = keyctl(KEYCTL_INSTANTIATE_IOV, id, payload_iov, ioc, ringid);
/* fall back to keyctl_instantiate() if this op is not supported by
* this kernel version */
if (ret == -1 && errno == EOPNOTSUPP) {
unsigned loop;
size_t bsize = 0, seg;
void *buf, *p;
if (!payload_iov || !ioc)
return keyctl_instantiate(id, NULL, 0, ringid);
for (loop = 0; loop < ioc; loop++)
bsize += payload_iov[loop].iov_len;
if (bsize == 0)
return keyctl_instantiate(id, NULL, 0, ringid);
p = buf = malloc(bsize);
if (!buf)
return -1;
for (loop = 0; loop < ioc; loop++) {
seg = payload_iov[loop].iov_len;
p = memcpy(p, payload_iov[loop].iov_base, seg) + seg;
}
ret = keyctl_instantiate(id, buf, bsize, ringid);
free(buf);
}
return ret;
}
long keyctl_invalidate(key_serial_t id)
{
return keyctl(KEYCTL_INVALIDATE, id);
}
long keyctl_get_persistent(uid_t uid, key_serial_t id)
{
return keyctl(KEYCTL_GET_PERSISTENT, uid, id);
}
long keyctl_dh_compute(key_serial_t priv, key_serial_t prime,
key_serial_t base, char *buffer, size_t buflen)
{
struct keyctl_dh_params params = { .priv = priv,
.prime = prime,
.base = base };
return keyctl(KEYCTL_DH_COMPUTE, ¶ms, buffer, buflen, 0);
}
long keyctl_dh_compute_kdf(key_serial_t priv, key_serial_t prime,
key_serial_t base, char *hashname, char *otherinfo,
size_t otherinfolen, char *buffer, size_t buflen)
{
struct keyctl_dh_params params = { .priv = priv,
.prime = prime,
.base = base };
struct keyctl_kdf_params kdfparams = { .hashname = hashname,
.otherinfo = otherinfo,
.otherinfolen = otherinfolen };
return keyctl(KEYCTL_DH_COMPUTE, ¶ms, buffer, buflen, &kdfparams);
}
long keyctl_restrict_keyring(key_serial_t keyring, const char *type,
const char *restriction)
{
return keyctl(KEYCTL_RESTRICT_KEYRING, keyring, type, restriction);
}
long keyctl_pkey_query(key_serial_t key_id,
const char *info,
struct keyctl_pkey_query *result)
{
return keyctl(KEYCTL_PKEY_QUERY, key_id, NULL, info, result);
}
long keyctl_pkey_encrypt(key_serial_t key_id,
const char *info,
const void *data, size_t data_len,
void *enc, size_t enc_len)
{
struct keyctl_pkey_params params = {
.key_id = key_id,
.in_len = data_len,
.out_len = enc_len,
};
return keyctl(KEYCTL_PKEY_ENCRYPT, ¶ms, info, data, enc);
}
long keyctl_pkey_decrypt(key_serial_t key_id,
const char *info,
const void *enc, size_t enc_len,
void *data, size_t data_len)
{
struct keyctl_pkey_params params = {
.key_id = key_id,
.in_len = enc_len,
.out_len = data_len,
};
return keyctl(KEYCTL_PKEY_DECRYPT, ¶ms, info, enc, data);
}
long keyctl_pkey_sign(key_serial_t key_id,
const char *info,
const void *data, size_t data_len,
void *sig, size_t sig_len)
{
struct keyctl_pkey_params params = {
.key_id = key_id,
.in_len = data_len,
.out_len = sig_len,
};
return keyctl(KEYCTL_PKEY_SIGN, ¶ms, info, data, sig);
}
long keyctl_pkey_verify(key_serial_t key_id,
const char *info,
const void *data, size_t data_len,
const void *sig, size_t sig_len)
{
struct keyctl_pkey_params params = {
.key_id = key_id,
.in_len = data_len,
.in2_len = sig_len,
};
return keyctl(KEYCTL_PKEY_VERIFY, ¶ms, info, data, sig);
}
long keyctl_move(key_serial_t id,
key_serial_t from_ringid,
key_serial_t to_ringid,
unsigned int flags)
{
return keyctl(KEYCTL_MOVE, id, from_ringid, to_ringid, flags);
}
long keyctl_capabilities(unsigned char *buffer, size_t buflen)
{
long n;
n = keyctl(KEYCTL_CAPABILITIES, buffer, buflen);
if (n != -1 || errno != EOPNOTSUPP)
return n;
/* Emulate the operation */
if (buflen > 0) {
memset(buffer, 0, buflen);
errno = 0;
keyctl_get_persistent(-1, 0);
if (errno != EOPNOTSUPP)
buffer[0] |= KEYCTL_CAPS0_PERSISTENT_KEYRINGS;
errno = 0;
keyctl_dh_compute(0, 0, 0, NULL, 0);
if (errno != EOPNOTSUPP)
buffer[0] |= KEYCTL_CAPS0_DIFFIE_HELLMAN;
errno = 0;
keyctl_pkey_query(0, NULL, NULL);
if (errno != EOPNOTSUPP)
buffer[0] |= KEYCTL_CAPS0_PUBLIC_KEY;
/* Can't emulate KEYCTL_CAPS0_BIG_KEY without a valid
* destination keyring.
*/
errno = 0;
keyctl_invalidate(0);
if (errno != EOPNOTSUPP)
buffer[0] |= KEYCTL_CAPS0_INVALIDATE;
errno = 0;
keyctl_restrict_keyring(0, NULL, NULL);
if (errno != EOPNOTSUPP)
buffer[0] |= KEYCTL_CAPS0_RESTRICT_KEYRING;
errno = 0;
keyctl_move(0, 0, 0, 0);
if (errno != EOPNOTSUPP)
buffer[0] |= KEYCTL_CAPS0_MOVE;
}
return sizeof(unsigned char);
}
long keyctl_watch_key(key_serial_t id, int watch_queue_fd, int watch_id)
{
return keyctl(KEYCTL_WATCH_KEY, id, watch_queue_fd, watch_id);
}
/*****************************************************************************/
/*
* fetch key description into an allocated buffer
* - resulting string is NUL terminated
* - returns count not including NUL
*/
int keyctl_describe_alloc(key_serial_t id, char **_buffer)
{
char *buf;
long buflen, ret;
ret = keyctl_describe(id, NULL, 0);
if (ret < 0)
return -1;
for (;;) {
buflen = ret;
buf = malloc(buflen);
if (!buf)
return -1;
ret = keyctl_describe(id, buf, buflen);
if (ret < 0) {
free(buf);
return -1;
}
if (buflen >= ret)
break;
free(buf);
}
*_buffer = buf;
return ret - 1;
}
/*****************************************************************************/
/*
* fetch key contents into an allocated buffer
* - resulting buffer has an extra NUL added to the end
* - returns count (not including extraneous NUL)
*/
int keyctl_read_alloc(key_serial_t id, void **_buffer)
{
char *buf;
long buflen, ret;
ret = keyctl_read(id, NULL, 0);
if (ret < 0)
return -1;
for (;;) {
buflen = ret;
buf = malloc(buflen + 1);
if (!buf)
return -1;
ret = keyctl_read(id, buf, buflen);
if (ret < 0) {
free(buf);
return -1;
}
if (buflen >= ret)
break;
free(buf);
}
buf[ret] = 0;
*_buffer = buf;
return ret;
}
/*****************************************************************************/
/*
* fetch key security label into an allocated buffer
* - resulting string is NUL terminated
* - returns count not including NUL
*/
int keyctl_get_security_alloc(key_serial_t id, char **_buffer)
{
char *buf;
long buflen, ret;
ret = keyctl_get_security(id, NULL, 0);
if (ret < 0)
return -1;
for (;;) {
buflen = ret;
buf = malloc(buflen);
if (!buf)
return -1;
ret = keyctl_get_security(id, buf, buflen);
if (ret < 0) {
free(buf);
return -1;
}
if (buflen >= ret)
break;
free(buf);
}
*_buffer = buf;
return ret - 1;
}
/*****************************************************************************/
/*
* fetch DH computation results into an allocated buffer
* - resulting buffer has an extra NUL added to the end
* - returns count (not including extraneous NUL)
*/
int keyctl_dh_compute_alloc(key_serial_t priv, key_serial_t prime,
key_serial_t base, void **_buffer)
{
char *buf;
long buflen, ret;
ret = keyctl_dh_compute(priv, prime, base, NULL, 0);
if (ret < 0)
return -1;
buflen = ret;
buf = malloc(buflen + 1);
if (!buf)
return -1;
ret = keyctl_dh_compute(priv, prime, base, buf, buflen);
if (ret < 0) {
free(buf);
return -1;
}
buf[ret] = 0;
*_buffer = buf;
return ret;
}
/*
* Depth-first recursively apply a function over a keyring tree
*/
static int recursive_key_scan_aux(key_serial_t parent, key_serial_t key,
int depth, recursive_key_scanner_t func,
void *data)
{
key_serial_t *pk;
key_perm_t perm;
size_t ringlen;
void *ring;
char *desc, type[255];
int desc_len, uid, gid, ret, n, kcount = 0;
if (depth > 800)
return 0;
/* read the key description */
desc = NULL;
desc_len = keyctl_describe_alloc(key, &desc);
if (desc_len < 0)
goto do_this_key;
/* parse */
type[0] = 0;
n = sscanf(desc, "%[^;];%d;%d;%x;", type, &uid, &gid, &perm);
if (n != 4) {
free(desc);
desc = NULL;
errno = -EINVAL;
desc_len = -1;
goto do_this_key;
}
/* if it's a keyring then we're going to want to recursively search it
* if we can */
if (strcmp(type, "keyring") == 0) {
/* read the keyring's contents */
ret = keyctl_read_alloc(key, &ring);
if (ret < 0)
goto do_this_key;
ringlen = ret;
/* walk the keyring */
pk = ring;
for (ringlen = ret;
ringlen >= sizeof(key_serial_t);
ringlen -= sizeof(key_serial_t)
)
kcount += recursive_key_scan_aux(key, *pk++, depth + 1,
func, data);
free(ring);
}
do_this_key:
kcount += func(parent, key, desc, desc_len, data);
free(desc);
return kcount;
}
/*
* Depth-first apply a function over a keyring tree
*/
int recursive_key_scan(key_serial_t key, recursive_key_scanner_t func, void *data)
{
return recursive_key_scan_aux(0, key, 0, func, data);
}
/*
* Depth-first apply a function over session keyring tree
*/
int recursive_session_key_scan(recursive_key_scanner_t func, void *data)
{
key_serial_t session =
keyctl_get_keyring_ID(KEY_SPEC_SESSION_KEYRING, 0);
if (session > 0)
return recursive_key_scan(session, func, data);
return 0;
}
/*
* Find a key by type and description
*/
key_serial_t find_key_by_type_and_desc(const char *type, const char *desc,
key_serial_t destringid)
{
key_serial_t id, error;
FILE *f;
char buf[1024], typebuf[40], rdesc[1024], *kdesc, *cp;
int n, ndesc, dlen;
error = ENOKEY;
id = request_key(type, desc, NULL, destringid);
if (id >= 0 || errno == ENOMEM)
return id;
if (errno != ENOKEY)
error = errno;
dlen = strlen(desc);
f = fopen("/proc/keys", "r");
if (!f) {
fprintf(stderr, "libkeyutils: Can't open /proc/keys: %m\n");
return -1;
}
while (fgets(buf, sizeof(buf), f)) {
cp = strchr(buf, '\n');
if (*cp)
*cp = '\0';
ndesc = 0;
n = sscanf(buf, "%x %*s %*u %*s %*x %*d %*d %s %n",
&id, typebuf, &ndesc);
if (n == 2 && ndesc > 0 && ndesc <= cp - buf) {
if (strcmp(typebuf, type) != 0)
continue;
kdesc = buf + ndesc;
if (memcmp(kdesc, desc, dlen) != 0)
continue;
if (kdesc[dlen] != ':' &&
kdesc[dlen] != '\0' &&
kdesc[dlen] != ' ')
continue;
kdesc[dlen] = '\0';
/* The key type appends extra stuff to the end of the
* description after a colon in /proc/keys. Colons,
* however, are allowed in descriptions, so we need to
* make a further check. */
n = keyctl_describe(id, rdesc, sizeof(rdesc) - 1);
if (n == -1) {
if (errno != ENOKEY)
error = errno;
if (errno == ENOMEM)
break;
}
if (n >= sizeof(rdesc) - 1)
continue;
rdesc[n] = '\0';
cp = strrchr(rdesc, ';');
if (!cp)
continue;
cp++;
if (strcmp(cp, desc) != 0)
continue;
fclose(f);
if (destringid &&
keyctl_link(id, destringid) == -1)
return -1;
return id;
}
}
fclose(f);
errno = error;
return -1;
}
#ifdef NO_GLIBC_KEYERR
/*****************************************************************************/
/*
* initialise error handling
*/
static void error_init(void)
{
char *err;
error_inited = 1;
dlerror();
libc_perror = dlsym(RTLD_NEXT,"perror");
if (!libc_perror) {
fprintf(stderr, "Failed to look up next perror\n");
err = dlerror();
if (err)
fprintf(stderr, "%s\n", err);
abort();
}
//fprintf(stderr, "next perror at %p\n", libc_perror);
libc_strerror_r = dlsym(RTLD_NEXT,"strerror_r");
if (!libc_strerror_r) {
fprintf(stderr, "Failed to look up next strerror_r\n");
err = dlerror();
if (err)
fprintf(stderr, "%s\n", err);
abort();
}
//fprintf(stderr, "next strerror_r at %p\n", libc_strerror_r);
#if 0
libc_xpg_strerror_r = dlsym(RTLD_NEXT,"xpg_strerror_r");
if (!libc_xpg_strerror_r) {
fprintf(stderr, "Failed to look up next xpg_strerror_r\n");
err = dlerror();
if (err)
fprintf(stderr, "%s\n", err);
abort();
}
//fprintf(stderr, "next xpg_strerror_r at %p\n", libc_xpg_strerror_r);
#endif
} /* end error_init() */
/*****************************************************************************/
/*
* overload glibc's strerror_r() with a version that knows about key errors
*/
char *strerror_r(int errnum, char *buf, size_t n)
{
const char *errstr;
int len;
printf("hello\n");
if (!error_inited)
error_init();
switch (errnum) {
case ENOKEY:
errstr = "Requested key not available";
break;
case EKEYEXPIRED:
errstr = "Key has expired";
break;
case EKEYREVOKED:
errstr = "Key has been revoked";
break;
case EKEYREJECTED:
errstr = "Key was rejected by service";
break;
default:
return libc_strerror_r(errnum, buf, n);
}
len = strlen(errstr) + 1;
if (n > len) {
errno = ERANGE;
if (n > 0) {
memcpy(buf, errstr, n - 1);
buf[n - 1] = 0;
}
return NULL;
}
else {
memcpy(buf, errstr, len);
return buf;
}
} /* end strerror_r() */
#if 0
/*****************************************************************************/
/*
* overload glibc's strerror_r() with a version that knows about key errors
*/
int xpg_strerror_r(int errnum, char *buf, size_t n)
{
const char *errstr;
int len;
if (!error_inited)
error_init();
switch (errnum) {
case ENOKEY:
errstr = "Requested key not available";
break;
case EKEYEXPIRED:
errstr = "Key has expired";
break;
case EKEYREVOKED:
errstr = "Key has been revoked";
break;
case EKEYREJECTED:
errstr = "Key was rejected by service";
break;
default:
return libc_xpg_strerror_r(errnum, buf, n);
}
len = strlen(errstr) + 1;
if (n > len) {
errno = ERANGE;
if (n > 0) {
memcpy(buf, errstr, n - 1);
buf[n - 1] = 0;
}
return -1;
}
else {
memcpy(buf, errstr, len);
return 0;
}
} /* end xpg_strerror_r() */
#endif
/*****************************************************************************/
/*
*
*/
void perror(const char *msg)
{
if (!error_inited)
error_init();
switch (errno) {
case ENOKEY:
fprintf(stderr, "%s: Requested key not available\n", msg);
return;
case EKEYEXPIRED:
fprintf(stderr, "%s: Key has expired\n", msg);
return;
case EKEYREVOKED:
fprintf(stderr, "%s: Key has been revoked\n", msg);
return;
case EKEYREJECTED:
fprintf(stderr, "%s: Key was rejected by service\n", msg);
return;
default:
libc_perror(msg);
return;
}
} /* end perror() */
#endif
keyutils-1.6.3/keyutils.h 0000664 0000000 0000000 00000027024 13701116425 0015421 0 ustar 00root root 0000000 0000000 /* keyutils.h: key utility library interface
*
* Copyright (C) 2005,2011 Red Hat, Inc. All Rights Reserved.
* Written by David Howells (dhowells@redhat.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#ifndef KEYUTILS_H
#define KEYUTILS_H
#include
#include
#ifdef __cplusplus
extern "C" {
#endif
extern const char keyutils_version_string[];
extern const char keyutils_build_string[];
/* key serial number */
typedef int32_t key_serial_t;
/* special process keyring shortcut IDs */
#define KEY_SPEC_THREAD_KEYRING -1 /* - key ID for thread-specific keyring */
#define KEY_SPEC_PROCESS_KEYRING -2 /* - key ID for process-specific keyring */
#define KEY_SPEC_SESSION_KEYRING -3 /* - key ID for session-specific keyring */
#define KEY_SPEC_USER_KEYRING -4 /* - key ID for UID-specific keyring */
#define KEY_SPEC_USER_SESSION_KEYRING -5 /* - key ID for UID-session keyring */
#define KEY_SPEC_GROUP_KEYRING -6 /* - key ID for GID-specific keyring */
#define KEY_SPEC_REQKEY_AUTH_KEY -7 /* - key ID for assumed request_key auth key */
/* request-key default keyrings */
#define KEY_REQKEY_DEFL_NO_CHANGE -1
#define KEY_REQKEY_DEFL_DEFAULT 0
#define KEY_REQKEY_DEFL_THREAD_KEYRING 1
#define KEY_REQKEY_DEFL_PROCESS_KEYRING 2
#define KEY_REQKEY_DEFL_SESSION_KEYRING 3
#define KEY_REQKEY_DEFL_USER_KEYRING 4
#define KEY_REQKEY_DEFL_USER_SESSION_KEYRING 5
#define KEY_REQKEY_DEFL_GROUP_KEYRING 6
/* key handle permissions mask */
typedef uint32_t key_perm_t;
#define KEY_POS_VIEW 0x01000000 /* possessor can view a key's attributes */
#define KEY_POS_READ 0x02000000 /* possessor can read key payload / view keyring */
#define KEY_POS_WRITE 0x04000000 /* possessor can update key payload / add link to keyring */
#define KEY_POS_SEARCH 0x08000000 /* possessor can find a key in search / search a keyring */
#define KEY_POS_LINK 0x10000000 /* possessor can create a link to a key/keyring */
#define KEY_POS_SETATTR 0x20000000 /* possessor can set key attributes */
#define KEY_POS_ALL 0x3f000000
#define KEY_USR_VIEW 0x00010000 /* user permissions... */
#define KEY_USR_READ 0x00020000
#define KEY_USR_WRITE 0x00040000
#define KEY_USR_SEARCH 0x00080000
#define KEY_USR_LINK 0x00100000
#define KEY_USR_SETATTR 0x00200000
#define KEY_USR_ALL 0x003f0000
#define KEY_GRP_VIEW 0x00000100 /* group permissions... */
#define KEY_GRP_READ 0x00000200
#define KEY_GRP_WRITE 0x00000400
#define KEY_GRP_SEARCH 0x00000800
#define KEY_GRP_LINK 0x00001000
#define KEY_GRP_SETATTR 0x00002000
#define KEY_GRP_ALL 0x00003f00
#define KEY_OTH_VIEW 0x00000001 /* third party permissions... */
#define KEY_OTH_READ 0x00000002
#define KEY_OTH_WRITE 0x00000004
#define KEY_OTH_SEARCH 0x00000008
#define KEY_OTH_LINK 0x00000010
#define KEY_OTH_SETATTR 0x00000020
#define KEY_OTH_ALL 0x0000003f
/* keyctl commands */
#define KEYCTL_GET_KEYRING_ID 0 /* ask for a keyring's ID */
#define KEYCTL_JOIN_SESSION_KEYRING 1 /* join or start named session keyring */
#define KEYCTL_UPDATE 2 /* update a key */
#define KEYCTL_REVOKE 3 /* revoke a key */
#define KEYCTL_CHOWN 4 /* set ownership of a key */
#define KEYCTL_SETPERM 5 /* set perms on a key */
#define KEYCTL_DESCRIBE 6 /* describe a key */
#define KEYCTL_CLEAR 7 /* clear contents of a keyring */
#define KEYCTL_LINK 8 /* link a key into a keyring */
#define KEYCTL_UNLINK 9 /* unlink a key from a keyring */
#define KEYCTL_SEARCH 10 /* search for a key in a keyring */
#define KEYCTL_READ 11 /* read a key or keyring's contents */
#define KEYCTL_INSTANTIATE 12 /* instantiate a partially constructed key */
#define KEYCTL_NEGATE 13 /* negate a partially constructed key */
#define KEYCTL_SET_REQKEY_KEYRING 14 /* set default request-key keyring */
#define KEYCTL_SET_TIMEOUT 15 /* set timeout on a key */
#define KEYCTL_ASSUME_AUTHORITY 16 /* assume authority to instantiate key */
#define KEYCTL_GET_SECURITY 17 /* get key security label */
#define KEYCTL_SESSION_TO_PARENT 18 /* set my session keyring on my parent process */
#define KEYCTL_REJECT 19 /* reject a partially constructed key */
#define KEYCTL_INSTANTIATE_IOV 20 /* instantiate a partially constructed key */
#define KEYCTL_INVALIDATE 21 /* invalidate a key */
#define KEYCTL_GET_PERSISTENT 22 /* get a user's persistent keyring */
#define KEYCTL_DH_COMPUTE 23 /* Compute Diffie-Hellman values */
#define KEYCTL_PKEY_QUERY 24 /* Query public key parameters */
#define KEYCTL_PKEY_ENCRYPT 25 /* Encrypt a blob using a public key */
#define KEYCTL_PKEY_DECRYPT 26 /* Decrypt a blob using a public key */
#define KEYCTL_PKEY_SIGN 27 /* Create a public key signature */
#define KEYCTL_PKEY_VERIFY 28 /* Verify a public key signature */
#define KEYCTL_RESTRICT_KEYRING 29 /* Restrict keys allowed to link to a keyring */
#define KEYCTL_MOVE 30 /* Move keys between keyrings */
#define KEYCTL_CAPABILITIES 31 /* Find capabilities of keyrings subsystem */
#define KEYCTL_WATCH_KEY 32 /* Watch a key or ring of keys for changes */
/* keyctl structures */
struct keyctl_dh_params {
key_serial_t priv;
key_serial_t prime;
key_serial_t base;
};
struct keyctl_kdf_params {
char *hashname;
char *otherinfo;
uint32_t otherinfolen;
uint32_t __spare[8];
};
#define KEYCTL_SUPPORTS_ENCRYPT 0x01
#define KEYCTL_SUPPORTS_DECRYPT 0x02
#define KEYCTL_SUPPORTS_SIGN 0x04
#define KEYCTL_SUPPORTS_VERIFY 0x08
struct keyctl_pkey_query {
unsigned int supported_ops; /* Which ops are supported */
unsigned int key_size; /* Size of the key in bits */
unsigned short max_data_size; /* Maximum size of raw data to sign in bytes */
unsigned short max_sig_size; /* Maximum size of signature in bytes */
unsigned short max_enc_size; /* Maximum size of encrypted blob in bytes */
unsigned short max_dec_size; /* Maximum size of decrypted blob in bytes */
unsigned int __spare[10];
};
struct keyctl_pkey_params {
key_serial_t key_id; /* Serial no. of public key to use */
unsigned int in_len; /* Input data size */
union {
unsigned int out_len; /* Output buffer size (encrypt/decrypt/sign) */
unsigned int in2_len; /* Second input data size (verify) */
};
unsigned int __spare[7];
};
#define KEYCTL_MOVE_EXCL 0x00000001 /* Do not displace from the to-keyring */
/*
* Capabilities flags. The capabilities list is an array of 8-bit integers;
* each integer can carry up to 8 flags.
*/
#define KEYCTL_CAPS0_CAPABILITIES 0x01 /* KEYCTL_CAPABILITIES supported */
#define KEYCTL_CAPS0_PERSISTENT_KEYRINGS 0x02 /* Persistent keyrings enabled */
#define KEYCTL_CAPS0_DIFFIE_HELLMAN 0x04 /* Diffie-Hellman ops enabled */
#define KEYCTL_CAPS0_PUBLIC_KEY 0x08 /* Public key ops enabled */
#define KEYCTL_CAPS0_BIG_KEY 0x10 /* big_key-type enabled */
#define KEYCTL_CAPS0_INVALIDATE 0x20 /* KEYCTL_INVALIDATE supported */
#define KEYCTL_CAPS0_RESTRICT_KEYRING 0x40 /* KEYCTL_RESTRICT_KEYRING supported */
#define KEYCTL_CAPS0_MOVE 0x80 /* KEYCTL_MOVE supported */
#define KEYCTL_CAPS1_NS_KEYRING_NAME 0x01 /* Keyring names are per-user_namespace */
#define KEYCTL_CAPS1_NS_KEY_TAG 0x02 /* Key indexing can include a namespace tag */
#define KEYCTL_CAPS1_NOTIFICATIONS 0x04 /* Keys generate watchable notifications */
/*
* syscall wrappers
*/
extern key_serial_t add_key(const char *type,
const char *description,
const void *payload,
size_t plen,
key_serial_t ringid);
extern key_serial_t request_key(const char *type,
const char *description,
const char *callout_info,
key_serial_t destringid);
extern long keyctl(int cmd, ...);
/*
* keyctl function wrappers
*/
extern key_serial_t keyctl_get_keyring_ID(key_serial_t id, int create);
extern key_serial_t keyctl_join_session_keyring(const char *name);
extern long keyctl_update(key_serial_t id, const void *payload, size_t plen);
extern long keyctl_revoke(key_serial_t id);
extern long keyctl_chown(key_serial_t id, uid_t uid, gid_t gid);
extern long keyctl_setperm(key_serial_t id, key_perm_t perm);
extern long keyctl_describe(key_serial_t id, char *buffer, size_t buflen);
extern long keyctl_clear(key_serial_t ringid);
extern long keyctl_link(key_serial_t id, key_serial_t ringid);
extern long keyctl_unlink(key_serial_t id, key_serial_t ringid);
extern long keyctl_search(key_serial_t ringid,
const char *type,
const char *description,
key_serial_t destringid);
extern long keyctl_read(key_serial_t id, char *buffer, size_t buflen);
extern long keyctl_instantiate(key_serial_t id,
const void *payload,
size_t plen,
key_serial_t ringid);
extern long keyctl_negate(key_serial_t id, unsigned timeout, key_serial_t ringid);
extern long keyctl_set_reqkey_keyring(int reqkey_defl);
extern long keyctl_set_timeout(key_serial_t key, unsigned timeout);
extern long keyctl_assume_authority(key_serial_t key);
extern long keyctl_get_security(key_serial_t key, char *buffer, size_t buflen);
extern long keyctl_session_to_parent(void);
extern long keyctl_reject(key_serial_t id, unsigned timeout, unsigned error,
key_serial_t ringid);
struct iovec;
extern long keyctl_instantiate_iov(key_serial_t id,
const struct iovec *payload_iov,
unsigned ioc,
key_serial_t ringid);
extern long keyctl_invalidate(key_serial_t id);
extern long keyctl_get_persistent(uid_t uid, key_serial_t id);
extern long keyctl_dh_compute(key_serial_t priv, key_serial_t prime,
key_serial_t base, char *buffer, size_t buflen);
extern long keyctl_dh_compute_kdf(key_serial_t priv, key_serial_t prime,
key_serial_t base, char *hashname,
char *otherinfo, size_t otherinfolen,
char *buffer, size_t buflen);
extern long keyctl_restrict_keyring(key_serial_t keyring, const char *type,
const char *restriction);
extern long keyctl_pkey_query(key_serial_t key_id,
const char *info,
struct keyctl_pkey_query *result);
extern long keyctl_pkey_encrypt(key_serial_t key_id,
const char *info,
const void *data, size_t data_len,
void *enc, size_t enc_len);
extern long keyctl_pkey_decrypt(key_serial_t key_id,
const char *info,
const void *enc, size_t enc_len,
void *data, size_t data_len);
extern long keyctl_pkey_sign(key_serial_t key_id,
const char *info,
const void *data, size_t data_len,
void *sig, size_t sig_len);
extern long keyctl_pkey_verify(key_serial_t key_id,
const char *info,
const void *data, size_t data_len,
const void *sig, size_t sig_len);
extern long keyctl_move(key_serial_t id,
key_serial_t from_ringid,
key_serial_t to_ringid,
unsigned int flags);
extern long keyctl_capabilities(unsigned char *buffer, size_t buflen);
extern long keyctl_watch_key(key_serial_t id, int watch_queue_fd, int watch_id);
/*
* utilities
*/
extern int keyctl_describe_alloc(key_serial_t id, char **_buffer);
extern int keyctl_read_alloc(key_serial_t id, void **_buffer);
extern int keyctl_get_security_alloc(key_serial_t id, char **_buffer);
extern int keyctl_dh_compute_alloc(key_serial_t priv, key_serial_t prime,
key_serial_t base, void **_buffer);
typedef int (*recursive_key_scanner_t)(key_serial_t parent, key_serial_t key,
char *desc, int desc_len, void *data);
extern int recursive_key_scan(key_serial_t key, recursive_key_scanner_t func, void *data);
extern int recursive_session_key_scan(recursive_key_scanner_t func, void *data);
extern key_serial_t find_key_by_type_and_desc(const char *type, const char *desc,
key_serial_t destringid);
#ifdef __cplusplus
}
#endif
#endif /* KEYUTILS_H */
keyutils-1.6.3/keyutils.spec 0000664 0000000 0000000 00000026533 13701116425 0016130 0 ustar 00root root 0000000 0000000 %define vermajor 1
%define verminor 6.3
%define version %{vermajor}.%{verminor}
%define libapivermajor 1
%define libapiversion %{libapivermajor}.10
# % define buildid .local
Name: keyutils
Version: %{version}
Release: 1%{?buildid}%{?dist}
Summary: Linux Key Management Utilities
License: GPLv2+ and LGPLv2+
Url: http://people.redhat.com/~dhowells/keyutils/
Source0: http://people.redhat.com/~dhowells/keyutils/keyutils-%{version}.tar.bz2
BuildRequires: gcc
BuildRequires: glibc-kernheaders >= 2.4-9.1.92
Requires: %{name}-libs%{?_isa} = %{version}-%{release}
%description
Utilities to control the kernel key management facility and to provide
a mechanism by which the kernel call back to user space to get a key
instantiated.
%package libs
Summary: Key utilities library
%description libs
This package provides a wrapper library for the key management facility system
calls.
%package libs-devel
Summary: Development package for building Linux key management utilities
Requires: %{name}-libs%{?_isa} = %{version}-%{release}
%description libs-devel
This package provides headers and libraries for building key utilities.
%prep
%setup -q
%define datadir %{_datarootdir}/keyutils
%build
make \
NO_ARLIB=1 \
ETCDIR=%{_sysconfdir} \
LIBDIR=%{_libdir} \
USRLIBDIR=%{_libdir} \
BINDIR=%{_bindir} \
SBINDIR=%{_sbindir} \
MANDIR=%{_mandir} \
INCLUDEDIR=%{_includedir} \
SHAREDIR=%{datadir} \
RELEASE=.%{release} \
NO_GLIBC_KEYERR=1 \
CFLAGS="-Wall $RPM_OPT_FLAGS -Werror" \
LDFLAGS="%{?__global_ldflags}"
%install
make \
NO_ARLIB=1 \
DESTDIR=$RPM_BUILD_ROOT \
ETCDIR=%{_sysconfdir} \
LIBDIR=%{_libdir} \
USRLIBDIR=%{_libdir} \
BINDIR=%{_bindir} \
SBINDIR=%{_sbindir} \
MANDIR=%{_mandir} \
INCLUDEDIR=%{_includedir} \
SHAREDIR=%{datadir} \
install
%ldconfig_scriptlets libs
%files
%doc README
%license LICENCE.GPL
%{_sbindir}/*
%{_bindir}/*
%{datadir}
%{_mandir}/man1/*
%{_mandir}/man5/*
%{_mandir}/man8/*
%config(noreplace) %{_sysconfdir}/*
%files libs
%license LICENCE.LGPL
%{_mandir}/man7/*
%{_libdir}/libkeyutils.so.%{libapiversion}
%{_libdir}/libkeyutils.so.%{libapivermajor}
%files libs-devel
%{_libdir}/libkeyutils.so
%{_includedir}/*
%{_mandir}/man3/*
%{_libdir}/pkgconfig/libkeyutils.pc
%changelog
* Tue Jul 7 2020 David Howells - 1.6.3-1
- Revert the change notifications that were using /dev/watch_queue.
- Apply the change notifications that use pipe2(O_NOTIFICATION_PIPE).
* Mon Jul 6 2020 David Howells - 1.6.2-1
- Allow "keyctl supports" to retrieve raw capability data.
- Allow "keyctl id" to turn a symbolic key ID into a numeric ID.
- Allow "keyctl new_session" to name the keyring.
- Allow "keyctl add/padd/etc." to take hex-encoded data.
- Add "keyctl watch*" to expose kernel change notifications on keys.
- Add caps for namespacing and notifications.
- Set a default TTL on keys that upcall for name resolution.
- Explicitly clear memory after it's held sensitive information.
- Various manual page fixes.
- Fix C++-related errors.
* Fri Aug 2 2019 David Howells - 1.6.1-1
- Add support for keyctl_move().
- Add support for keyctl_capabilities().
- Make key=val list optional for various public-key ops.
- Fix system call signature for KEYCTL_PKEY_QUERY.
- Fix 'keyctl pkey_query' argument passing.
- Use keyctl_read_alloc() in dump_key_tree_aux().
- Various manual page fixes.
* Tue Nov 13 2018 David Howells - 1.6-1
- Apply various specfile cleanups from Fedora.
- request-key: Provide a command line option to suppress helper execution.
- request-key: Find least-wildcard match rather than first match.
- Remove the dependency on MIT Kerberos.
- Fix some error messages
- keyctl_dh_compute.3: Suggest /proc/crypto for list of available hashes.
- Fix doc and comment typos.
- Add public key ops for encrypt, decrypt, sign and verify (needs linux-4.20).
- Add pkg-config support for finding libkeyutils.
* Wed May 9 2018 David Howells - 1.5.11-1
- Add keyring restriction support.
- Add KDF support to the Diffie-Helman function.
- DNS: Add support for AFS config files and SRV records
* Wed Mar 15 2017 David Howells - 1.5.10-1
- Include sys/types.h in keyutils.h.
- The dns resolver needs limits.h.
- Overhaul of all manual pages.
- Some manual pages moved to Linux man-pages project.
- Add Diffie-Helman keyctl function.
* Fri Feb 21 2014 David Howells - 1.5.9-1
- Add manpages for get_persistent.
- Fix memory leaks in keyctl_describe/read/get_security_alloc().
- Use keyctl_describe_alloc in dump_key_tree_aux rather than open coding it.
- Exit rather than returning from act_xxx() functions.
- Fix memory leak in dump_key_tree_aux.
- Only get the groups list if we need it.
- Don't trust sscanf's %%n argument.
- Use the correct path macros in the specfile.
- Avoid use realloc when the memory has no content.
- Fix a bunch of issues in key.dns_resolver.
- Fix command table searching in keyctl utility.
- Fix a typo in the permissions mask constants.
- Improve the keyctl_read manpage.
- Add man7 pages describing various keyrings concepts.
* Fri Oct 4 2013 David Howells - 1.5.8-1
- New lib symbols should go in a new library minor version.
* Wed Oct 2 2013 David Howells - 1.5.7-1
- Provide a utility function to find a key by type and name.
- Allow keyctl commands to take a type+name arg instead of a key-id arg.
- Add per-UID get_persistent keyring function.
* Thu Aug 29 2013 David Howells - 1.5.6-1
- Fix the request-key.conf.5 manpage.
- Fix the max depth of key tree dump (keyctl show).
- The input buffer size for keyctl padd and pinstantiate should be larger.
- Add keyctl_invalidate.3 manpage.
* Wed Nov 30 2011 David Howells - 1.5.5-1
- Fix a Makefile error.
* Wed Nov 30 2011 David Howells - 1.5.4-1
- Fix the keyctl padd command and similar to handle binary input.
- Make keyctl show able to take a keyring to dump.
- Make keyctl show able to take a flag to request hex key IDs.
- Make keyctl show print the real ID of the root keyring.
* Tue Nov 15 2011 David Howells
- Allow /sbin/request-key to have multiple config files.
* Wed Aug 31 2011 David Howells
- Adjust the manual page for 'keyctl unlink' to show keyring is optional.
- Add --version support for the keyutils version and build date.
* Thu Aug 11 2011 David Howells - 1.5.3-1
- Make the keyutils rpm depend on the same keyutils-libs rpm version.
* Tue Jul 26 2011 David Howells - 1.5.2-1
- Use correct format spec for printing pointer subtraction results.
* Tue Jul 19 2011 David Howells - 1.5.1-1
- Fix unread variables.
- Licence file update.
* Thu Mar 10 2011 David Howells - 1.5-1
- Disable RPATH setting in Makefile.
- Add -I. to build to get this keyutils.h.
- Make CFLAGS override on make command line work right.
- Make specfile UTF-8.
- Support KEYCTL_REJECT.
- Support KEYCTL_INSTANTIATE_IOV.
- Add AFSDB DNS lookup program from Wang Lei.
- Generalise DNS lookup program.
- Add recursive scan utility function.
- Add bad key reap command to keyctl.
- Add multi-unlink variant to keyctl unlink command.
- Add multi key purge command to keyctl.
- Handle multi-line commands in keyctl command table.
- Move the package to version to 1.5.
* Tue Mar 1 2011 David Howells - 1.4-4
- Make build guess at default libdirs and word size.
- Make program build depend on library in Makefile.
- Don't include $(DESTDIR) in MAN* macros.
- Remove NO_GLIBC_KEYSYS as it is obsolete.
- Have Makefile extract version info from specfile and version script.
- Provide RPM build rule in Makefile.
- Provide distclean rule in Makefile.
* Fri Dec 17 2010 Diego Elio Pettenò - 1.4-3
- Fix local linking and RPATH.
* Thu Jun 10 2010 David Howells - 1.4-2
- Fix prototypes in manual pages (some char* should be void*).
- Rename the keyctl_security.3 manpage to keyctl_get_security.3.
* Fri Mar 19 2010 David Howells - 1.4-1
- Fix the library naming wrt the version.
- Move the package to version to 1.4.
* Fri Mar 19 2010 David Howells - 1.3-3
- Fix spelling mistakes in manpages.
- Add an index manpage for all the keyctl functions.
* Thu Mar 11 2010 David Howells - 1.3-2
- Fix rpmlint warnings.
* Fri Feb 26 2010 David Howells - 1.3-1
- Fix compiler warnings in request-key.
- Expose the kernel function to get a key's security context.
- Expose the kernel function to set a processes keyring onto its parent.
- Move libkeyutils library version to 1.3.
* Tue Aug 22 2006 David Howells - 1.2-1
- Remove syscall manual pages (section 2) to man-pages package [BZ 203582]
- Don't write to serial port in debugging script
* Mon Jun 5 2006 David Howells - 1.1-4
- Call ldconfig during (un)installation.
* Fri May 5 2006 David Howells - 1.1-3
- Don't include the release number in the shared library filename
- Don't build static library
* Fri May 5 2006 David Howells - 1.1-2
- More bug fixes from Fedora reviewer.
* Thu May 4 2006 David Howells - 1.1-1
- Fix rpmlint errors
* Mon Dec 5 2005 David Howells - 1.0-2
- Add build dependency on glibc-kernheaders with key management syscall numbers
* Tue Nov 29 2005 David Howells - 1.0-1
- Add data pipe-in facility for keyctl request2
* Mon Nov 28 2005 David Howells - 1.0-1
- Rename library and header file "keyutil" -> "keyutils" for consistency
- Fix shared library version naming to same way as glibc.
- Add versioning for shared library symbols
- Create new keyutils-libs package and install library and main symlink there
- Install base library symlink in /usr/lib and place in devel package
- Added a keyutils archive library
- Shorten displayed key permissions list to just those we actually have
* Thu Nov 24 2005 David Howells - 0.3-4
- Add data pipe-in facilities for keyctl add, update and instantiate
* Fri Nov 18 2005 David Howells - 0.3-3
- Added stdint.h inclusion in keyutils.h
- Made request-key.c use request_key() rather than keyctl_search()
- Added piping facility to request-key
* Thu Nov 17 2005 David Howells