Compare commits
10 Commits
08affd7d36
...
eebf004291
| Author | SHA1 | Date | |
|---|---|---|---|
| eebf004291 | |||
| d4a222ef6d | |||
| f7f02899b3 | |||
| 986af66adb | |||
| 598fd7aa74 | |||
| 0c5cfbe2cb | |||
| 85c0e8db3d | |||
| 3afbf4d0cb | |||
| bed5d4d5c5 | |||
| 9578c429be |
339
LICENSE
339
LICENSE
@@ -1,339 +0,0 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, 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 Lesser 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
|
||||
|
||||
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.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
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.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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) year 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.
|
||||
|
||||
<signature of Ty Coon>, 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 Lesser General
|
||||
Public License instead of this License.
|
||||
@@ -1,24 +1,3 @@
|
||||
/*
|
||||
* agent.c
|
||||
*
|
||||
* Copyright (C) 2018 by Bogomil Vasilev <b.vasilev@smirky.net>
|
||||
*
|
||||
* This file is part of Remote Management and Provisioning System (RMPS).
|
||||
*
|
||||
* RMPS 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.
|
||||
*
|
||||
* RMPS 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 RMPS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
@@ -83,10 +62,12 @@ static void signal_handler(int sig)
|
||||
static void agent_shutdown(void)
|
||||
{
|
||||
printf("Shutting down agent...\n");
|
||||
if (ssl && !SSL_get_shutdown(ssl))
|
||||
SSL_shutdown(ssl);
|
||||
SSL_free(ssl);
|
||||
SSL_CTX_free(ctx); /* release context */
|
||||
if (ssl) SSL_free(ssl);
|
||||
if (ctx) SSL_CTX_free(ctx); /* release context */
|
||||
close(server); /* close socket */
|
||||
_exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static void set_env(void)
|
||||
@@ -116,7 +97,7 @@ static void set_env(void)
|
||||
|
||||
int main(int count, char *strings[])
|
||||
{
|
||||
int bytes, i;
|
||||
int bytes, i, err;
|
||||
char *hostname, *portnum;
|
||||
|
||||
if (count != 6) {
|
||||
@@ -127,10 +108,14 @@ int main(int count, char *strings[])
|
||||
portnum=strings[2];
|
||||
if ((ctx = init_ctx()) == NULL)
|
||||
_exit(EXIT_FAILURE);
|
||||
|
||||
while (1) {
|
||||
server = connect_to_rmps(hostname, atoi(portnum));
|
||||
if (!server) {
|
||||
fprintf(stderr, "Failed to connect to RMPS: %s:%d\n", hostname, atoi(portnum));
|
||||
_exit(EXIT_FAILURE);
|
||||
fprintf(stderr, "Failed to connect to RMPS on %s:%d - %s\n", hostname, atoi(portnum), strerror(errno));
|
||||
printf("Retrying...\n");
|
||||
sleep(5);
|
||||
continue;
|
||||
}
|
||||
load_certs(ctx, strings[3], strings[4], strings[5]);
|
||||
ssl = SSL_new(ctx); /* create new SSL connection state */
|
||||
@@ -181,7 +166,8 @@ int main(int count, char *strings[])
|
||||
if (bytes != sizeof(struct msg_t)) {
|
||||
fprintf( stderr,
|
||||
"Received non-standard data from server!\n" );
|
||||
continue;
|
||||
//conntinue;
|
||||
return 1;
|
||||
}
|
||||
if (buf.chunk.id == 0) {
|
||||
if ((index = get_job_slot()) == FAIL) {
|
||||
@@ -277,8 +263,31 @@ int main(int count, char *strings[])
|
||||
memcpy(&args[index].buf, &buf, sizeof(struct msg_t));
|
||||
}
|
||||
}
|
||||
|
||||
SSL_shutdown(ssl);
|
||||
SSL_free(ssl); /* release connection state */
|
||||
} while (bytes);
|
||||
if (SSL_get_shutdown(ssl)) {
|
||||
printf("RMPS server has shutdown, trying to reconnect...\n");
|
||||
sleep(5);
|
||||
} else {
|
||||
err = SSL_get_error(ssl, bytes);
|
||||
switch (err) {
|
||||
case SSL_ERROR_WANT_WRITE:
|
||||
printf("want_write\n");
|
||||
return 0;
|
||||
case SSL_ERROR_WANT_READ:
|
||||
printf("want_read\n");
|
||||
return 0;
|
||||
case SSL_ERROR_ZERO_RETURN:
|
||||
printf("zero_return\n");
|
||||
return -1;
|
||||
case SSL_ERROR_SYSCALL:
|
||||
printf("syscall\n");
|
||||
return -1;
|
||||
case SSL_ERROR_SSL:
|
||||
printf("ssl\n");
|
||||
return -1;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,3 @@
|
||||
/*
|
||||
* agent_ssl.c
|
||||
*
|
||||
* Copyright (C) 2018 by Bogomil Vasilev <b.vasilev@smirky.net>
|
||||
*
|
||||
* This file is part of Remote Management and Provisioning System (RMPS).
|
||||
*
|
||||
* RMPS 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.
|
||||
*
|
||||
* RMPS 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 RMPS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <string.h>
|
||||
@@ -49,7 +28,6 @@ int connect_to_rmps(const char *hostname, int port)
|
||||
addr.sin_addr.s_addr = *(long*)(host->h_addr);
|
||||
if (connect(sd, (struct sockaddr*)&addr, sizeof(addr)) == FAIL) {
|
||||
close(sd);
|
||||
perror(hostname);
|
||||
return 0;
|
||||
}
|
||||
return sd;
|
||||
|
||||
@@ -1,24 +1,3 @@
|
||||
/*
|
||||
* agent_ssl.h
|
||||
*
|
||||
* Copyright (C) 2018 by Bogomil Vasilev <b.vasilev@smirky.net>
|
||||
*
|
||||
* This file is part of Remote Management and Provisioning System (RMPS).
|
||||
*
|
||||
* RMPS 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.
|
||||
*
|
||||
* RMPS 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 RMPS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef AGENT_SSL
|
||||
#define AGENT_SSL
|
||||
|
||||
|
||||
21
agent/job.c
21
agent/job.c
@@ -1,24 +1,3 @@
|
||||
/*
|
||||
* job.c
|
||||
*
|
||||
* Copyright (C) 2018 by Bogomil Vasilev <b.vasilev@smirky.net>
|
||||
*
|
||||
* This file is part of Remote Management and Provisioning System (RMPS).
|
||||
*
|
||||
* RMPS 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.
|
||||
*
|
||||
* RMPS 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 RMPS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
21
agent/job.h
21
agent/job.h
@@ -1,24 +1,3 @@
|
||||
/*
|
||||
* job.h
|
||||
*
|
||||
* Copyright (C) 2018 by Bogomil Vasilev <b.vasilev@smirky.net>
|
||||
*
|
||||
* This file is part of Remote Management and Provisioning System (RMPS).
|
||||
*
|
||||
* RMPS 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.
|
||||
*
|
||||
* RMPS 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 RMPS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef JOB_H
|
||||
#define JOB_H
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# Just build via makepkg
|
||||
|
||||
pkgname=rmps
|
||||
pkgver=20180704.81f454a
|
||||
pkgver=20190107.63e2cfa
|
||||
pkgrel=1
|
||||
pkgdesc='Remote Management and Provisioning System'
|
||||
url='https://git.smirky.net/smirky/rmps.git/'
|
||||
@@ -11,7 +11,6 @@ depends=('libmariadbclient')
|
||||
validpgpkeys=('8C4D267F4977BFFEF23121E8646F3ABF6E457336')
|
||||
source=("${pkgname}::git+https://git.smirky.net/smirky/${pkgname}.git")
|
||||
sha256sums=('SKIP')
|
||||
license=('GPL2')
|
||||
backup=(
|
||||
etc/rmps/rmps.conf
|
||||
)
|
||||
|
||||
@@ -1,24 +1,3 @@
|
||||
/*
|
||||
* agent_pool.c
|
||||
*
|
||||
* Copyright (C) 2018 by Bogomil Vasilev <b.vasilev@smirky.net>
|
||||
*
|
||||
* This file is part of Remote Management and Provisioning System (RMPS).
|
||||
*
|
||||
* RMPS 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.
|
||||
*
|
||||
* RMPS 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 RMPS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "agent_pool.h"
|
||||
#include "log.h"
|
||||
#include "protocol.h"
|
||||
@@ -38,6 +17,23 @@ struct agent_args {
|
||||
static void show_certs(SSL *ssl);
|
||||
static void *servlet(void *args);
|
||||
static void send_reject_msg(SSL *ssl);
|
||||
void shutdown_pool(void *args);
|
||||
|
||||
void shutdown_pool(void *args)
|
||||
{
|
||||
struct agent_args *agents = args;
|
||||
int i = 0;
|
||||
log(VERBOSE, "Shutting down agent pool...");
|
||||
while (i < conf.rmps.agent_poolsize) {
|
||||
if (!agents[i].busy && ++i)
|
||||
continue;
|
||||
log(VERBOSE, "Shutting down agent thread: %d", i);
|
||||
SSL_shutdown(agents[i].ssl);
|
||||
i++;
|
||||
}
|
||||
if (agents)
|
||||
free(agents);
|
||||
}
|
||||
|
||||
static void show_certs(SSL *ssl)
|
||||
{
|
||||
@@ -120,8 +116,10 @@ static void *servlet(void *args) /* Serve the connection -- threadable */
|
||||
static void send_reject_msg(SSL *ssl)
|
||||
{
|
||||
char *reply = "FAILURE - The connection queue is full!\n";
|
||||
struct msg_t buf = {0};
|
||||
sprintf((char *)buf.chunk.data, "%s", reply);
|
||||
|
||||
SSL_write(ssl, reply, strlen(reply));
|
||||
SSL_write(ssl, &buf, sizeof(struct msg_t));
|
||||
}
|
||||
|
||||
void *agent_pool(void *args)
|
||||
@@ -129,11 +127,12 @@ void *agent_pool(void *args)
|
||||
struct pool_data *pool = args;
|
||||
pthread_mutex_t mutex;
|
||||
pthread_attr_t attr;
|
||||
pthread_t *agent_thread = malloc(pool->size * sizeof(*agent_thread));
|
||||
pthread_t *agent_thread = calloc(pool->size, sizeof(*agent_thread));
|
||||
struct agent_args *agent_struct =
|
||||
malloc(pool->size * sizeof(*agent_struct));
|
||||
calloc(pool->size, sizeof(*agent_struct));
|
||||
int i;
|
||||
|
||||
pthread_cleanup_push(shutdown_pool, agent_struct);
|
||||
memset(agent_thread, 0, sizeof(pthread_t) * pool->size);
|
||||
memset(agent_struct, 0, sizeof(struct agent_args) * pool->size);
|
||||
|
||||
@@ -192,5 +191,6 @@ void *agent_pool(void *args)
|
||||
pthread_attr_destroy(&attr);
|
||||
pthread_mutex_destroy(&mutex);
|
||||
pthread_detach(pthread_self());
|
||||
pthread_cleanup_pop(1);
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
@@ -1,24 +1,3 @@
|
||||
/*
|
||||
* agent_pool.h
|
||||
*
|
||||
* Copyright (C) 2018 by Bogomil Vasilev <b.vasilev@smirky.net>
|
||||
*
|
||||
* This file is part of Remote Management and Provisioning System (RMPS).
|
||||
*
|
||||
* RMPS 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.
|
||||
*
|
||||
* RMPS 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 RMPS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef AGENT_POOL_H
|
||||
#define AGENT_POOL_H
|
||||
|
||||
|
||||
@@ -1,24 +1,3 @@
|
||||
/*
|
||||
* client_pool.c
|
||||
*
|
||||
* Copyright (C) 2018 by Bogomil Vasilev <b.vasilev@smirky.net>
|
||||
*
|
||||
* This file is part of Remote Management and Provisioning System (RMPS).
|
||||
*
|
||||
* RMPS 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.
|
||||
*
|
||||
* RMPS 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 RMPS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "client_pool.h"
|
||||
#include "log.h"
|
||||
#include "job_queue.h"
|
||||
|
||||
@@ -1,24 +1,3 @@
|
||||
/*
|
||||
* client_pool.h
|
||||
*
|
||||
* Copyright (C) 2018 by Bogomil Vasilev <b.vasilev@smirky.net>
|
||||
*
|
||||
* This file is part of Remote Management and Provisioning System (RMPS).
|
||||
*
|
||||
* RMPS 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.
|
||||
*
|
||||
* RMPS 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 RMPS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef CLIENT_POOL_H
|
||||
#define CLIENT_POOL_H
|
||||
|
||||
|
||||
535
src/confparser.c
535
src/confparser.c
@@ -1,24 +1,4 @@
|
||||
/*
|
||||
* confparser.c
|
||||
*
|
||||
* Copyright (C) 2018 by Bogomil Vasilev <b.vasilev@smirky.net>
|
||||
*
|
||||
* This file is part of Remote Management and Provisioning System (RMPS).
|
||||
*
|
||||
* RMPS 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.
|
||||
*
|
||||
* RMPS 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 RMPS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
@@ -30,39 +10,11 @@
|
||||
#include "confparser.h"
|
||||
#include "enum_functions.h"
|
||||
|
||||
static int test_conf_perms(char *config);
|
||||
static int test_conf_syntax(char *config);
|
||||
static bool test_conf_perms(char *config);
|
||||
static bool test_conf_syntax(char *config);
|
||||
static bool test_conf_required(void);
|
||||
|
||||
struct conf_table conf = {
|
||||
0, /* isvalid initial state */
|
||||
{
|
||||
"", /* db.type */
|
||||
"", /* db.hostname */
|
||||
"", /* db.port */
|
||||
"" /* db.pass */
|
||||
},
|
||||
{
|
||||
"127.0.0.1", /* rmps.agent_ip */
|
||||
"7000", /* rmps.agent_port */
|
||||
"127.0.0.1", /* rmps.client_ip */
|
||||
"7001", /* rmps.client_port */
|
||||
"/var/log/rmps/rmpsd.log",
|
||||
"/var/log/rmps/rmpsd.err",
|
||||
'2', /* rmps.loglevel */
|
||||
"/run/rmps/rmpsd.pid",
|
||||
"/etc/rmps/agent.crt",
|
||||
"/etc/rmps/agent.key",
|
||||
"/etc/rmps/ca.crt",
|
||||
"", /* rmps.cipherlist */
|
||||
2, /* rmps.agent_poolsize */
|
||||
"/etc/rmps/client.crt",
|
||||
"/etc/rmps/client.key",
|
||||
2 /* rmps.client_poolsize */
|
||||
},
|
||||
{
|
||||
0 /* nfs -> TODO */
|
||||
}
|
||||
};
|
||||
struct conf_table conf;
|
||||
|
||||
const char *conf_db_pass(void)
|
||||
{
|
||||
@@ -142,63 +94,82 @@ static int fopen_and_mkdir(const char *dir)
|
||||
log(ERROR,
|
||||
"Permission denied to create dir: %s",
|
||||
tmp);
|
||||
return 1;
|
||||
return false;
|
||||
}
|
||||
*p = '/';
|
||||
}
|
||||
fp = fopen(dir, "a");
|
||||
if (!fp) {
|
||||
log(ERROR, "Permission denied to write into: %s", dir);
|
||||
return 1;
|
||||
return false;
|
||||
}
|
||||
fclose(fp);
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
static int test_conf_perms(char *config)
|
||||
static void init_conf(void)
|
||||
{
|
||||
conf.isvalid = 0; /* initial state */
|
||||
asprintf(&conf.db.type, "mysql");
|
||||
conf.db.hostname[0] = '\0';
|
||||
conf.db.port = NULL;
|
||||
conf.db.pass = NULL;
|
||||
asprintf(&conf.rmps.agent_ip, "any");
|
||||
asprintf(&conf.rmps.agent_port, "7000");
|
||||
asprintf(&conf.rmps.client_ip, "any");
|
||||
asprintf(&conf.rmps.client_port, "7001");
|
||||
asprintf(&conf.rmps.logfile, "/var/log/rmps/rmpsd.log");
|
||||
asprintf(&conf.rmps.errlog, "/var/log/rmps/rmpsd.err");
|
||||
conf.rmps.loglevel = 2; /* WARNING == 2 */
|
||||
asprintf(&conf.rmps.pidfile, "/run/rmps/rmpsd.pid");
|
||||
asprintf(&conf.rmps.agent_tls_crt, "/etc/rmps/certs/server.crt");
|
||||
asprintf(&conf.rmps.agent_tls_key, "/etc/rmps/certs/server.key");
|
||||
asprintf(&conf.rmps.cafile, "/etc/rmps/certs/ca.crt");
|
||||
conf.rmps.cipherlist = NULL;
|
||||
conf.rmps.agent_poolsize = 2;
|
||||
asprintf(&conf.rmps.client_tls_crt, "/etc/rmps/certs/server.crt");
|
||||
asprintf(&conf.rmps.client_tls_key, "/etc/rmps/certs/server.key");
|
||||
conf.rmps.client_poolsize = 2;
|
||||
//conf.nfs = {0}; /* TODO */
|
||||
}
|
||||
|
||||
static void log_and_free(char **msg, const char *config, char *mem)
|
||||
{
|
||||
log(ERROR, *msg, config);
|
||||
if (*msg) /* in case enumtostr() fails */
|
||||
free(*msg);
|
||||
free(mem);
|
||||
}
|
||||
|
||||
static bool test_conf_perms(char *config)
|
||||
{
|
||||
struct stat s;
|
||||
char confresult[128];
|
||||
char *confresult;
|
||||
char *config_copy = strdup(config);
|
||||
int err = stat(config, &s);
|
||||
|
||||
if (err == -1) {
|
||||
if (errno == ENOENT) {
|
||||
enumtostr(confresult, CONF_MISSING);
|
||||
log(ERROR, confresult, config);
|
||||
free(config_copy);
|
||||
return 1;
|
||||
enumtostr(&confresult, CONF_MISSING);
|
||||
log_and_free(&confresult, config, config_copy);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!S_ISREG(s.st_mode)) {
|
||||
enumtostr(confresult, CONF_NOTFILE);
|
||||
log(ERROR, confresult, config);
|
||||
free(config_copy);
|
||||
return 1;
|
||||
enumtostr(&confresult, CONF_NOTFILE);
|
||||
log_and_free(&confresult, config, config_copy);
|
||||
return false;
|
||||
}
|
||||
if (!(0400 & s.st_mode)) {
|
||||
enumtostr(confresult, CONF_PERM);
|
||||
log(ERROR, confresult, config);
|
||||
free(config_copy);
|
||||
return 1;
|
||||
enumtostr(&confresult, CONF_PERM);
|
||||
log_and_free(&confresult, config, config_copy);
|
||||
return false;
|
||||
}
|
||||
if (access(config, R_OK) != 0) {
|
||||
enumtostr(confresult, CONF_NOT_READABLE);
|
||||
log(ERROR, confresult, config);
|
||||
free(config_copy);
|
||||
return 1;
|
||||
}
|
||||
if (s.st_uid != 0) {
|
||||
enumtostr(confresult, CONF_FILE_UID_INSECURE);
|
||||
log(WARNING, confresult, config);
|
||||
} else if (s.st_gid != 0) {
|
||||
enumtostr(confresult, CONF_FILE_GID_INSECURE);
|
||||
log(WARNING, confresult, config);
|
||||
} else if ((0004 & s.st_mode) ||
|
||||
(0002 & s.st_mode)) {
|
||||
enumtostr(confresult, CONF_FILE_PERM_INSECURE);
|
||||
log(WARNING, confresult, config);
|
||||
enumtostr(&confresult, CONF_NOT_READABLE);
|
||||
log_and_free(&confresult, config, config_copy);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,271 +177,289 @@ static int test_conf_perms(char *config)
|
||||
|
||||
if (err == -1) {
|
||||
if (errno == ENOENT) {
|
||||
enumtostr(confresult, CONF_DIR_MISSING);
|
||||
log(ERROR, confresult, config_copy);
|
||||
free(config_copy);
|
||||
return 1;
|
||||
enumtostr(&confresult, CONF_DIR_MISSING);
|
||||
log_and_free(&confresult, config, config_copy);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!S_ISDIR(s.st_mode)) {
|
||||
enumtostr(confresult, CONF_DIR_NOTDIR);
|
||||
log(ERROR, confresult, config_copy);
|
||||
free(config_copy);
|
||||
return 1;
|
||||
enumtostr(&confresult, CONF_DIR_NOTDIR);
|
||||
log_and_free(&confresult, config, config_copy);
|
||||
return false;
|
||||
}
|
||||
if (!(0400 & s.st_mode) ||
|
||||
!(0100 & s.st_mode)) {
|
||||
enumtostr(confresult, CONF_DIR_PERM);
|
||||
log(ERROR, confresult, config_copy);
|
||||
free(config_copy);
|
||||
return 1;
|
||||
}
|
||||
if (s.st_uid != 0) {
|
||||
enumtostr(confresult, CONF_DIR_UID_INSECURE);
|
||||
log(WARNING, confresult, config_copy);
|
||||
} else if (s.st_gid != 0) {
|
||||
enumtostr(confresult, CONF_DIR_GID_INSECURE);
|
||||
log(WARNING, confresult, config_copy);
|
||||
} else if ((0004 & s.st_mode) ||
|
||||
(0002 & s.st_mode)) {
|
||||
enumtostr(confresult, CONF_DIR_PERM_INSECURE);
|
||||
log(WARNING, confresult, config_copy);
|
||||
enumtostr(&confresult, CONF_DIR_PERM);
|
||||
log_and_free(&confresult, config, config_copy);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
free(config_copy);
|
||||
|
||||
return 0; /* conf is readable */
|
||||
return true; /* conf is readable */
|
||||
}
|
||||
|
||||
static int test_conf_syntax(char *config)
|
||||
/* Import the config and test the syntax */
|
||||
static bool test_conf_syntax(char *config)
|
||||
{
|
||||
int i, j = 0, ok = 1, failed = 0;
|
||||
char buf[CFGLINESIZE], *tmp;
|
||||
int i, line_itr = 0;
|
||||
bool failed = false, val_ok = true;
|
||||
char *line = NULL, *val_ptr;
|
||||
size_t len = 0;
|
||||
FILE *fp = fopen(config, "r");
|
||||
|
||||
if (fp == NULL) {
|
||||
log(ERROR, "Failed to read %s", config);
|
||||
return 1;
|
||||
return false;
|
||||
}
|
||||
|
||||
while (fgets(buf, CFGLINESIZE, fp) != NULL) {
|
||||
j++;
|
||||
while (getline(&line, &len, fp) != -1) {
|
||||
line_itr++;
|
||||
/* kill comments and ignore BLANK lines */
|
||||
tmp = strstr(buf, "#");
|
||||
if (tmp)
|
||||
*tmp = '\0';
|
||||
if (buf[strspn(buf, " \t\v\r\n")] == '\0')
|
||||
val_ptr = strstr(line, "#");
|
||||
if (val_ptr)
|
||||
*val_ptr = '\0';
|
||||
if (line[strspn(line, " \t\v\r\n")] == '\0')
|
||||
continue;
|
||||
|
||||
/* If we have "=", it's a possible var */
|
||||
tmp = strstr(buf, "=");
|
||||
if (tmp)
|
||||
*tmp = '\0';
|
||||
val_ptr = strstr(line, "=");
|
||||
if (val_ptr)
|
||||
*val_ptr = '\0';
|
||||
else {
|
||||
log(ERROR,
|
||||
"Bad entry in %s, line %d: %s", config, j, buf);
|
||||
ok = 0;
|
||||
failed = 1;
|
||||
"Bad entry in %s, line %d: %s", config, line_itr, line);
|
||||
val_ok = false;
|
||||
failed = true;
|
||||
continue;
|
||||
}
|
||||
/* Check if there actually is a value after '=' */
|
||||
i = strlen(tmp + 1);
|
||||
if (tmp[i] == '\n')
|
||||
tmp[i] = '\0';
|
||||
if (tmp[strspn(tmp + 1, " \t\v\r\n") + 1] == '\0') {
|
||||
i = strlen(val_ptr + 1);
|
||||
if (val_ptr[i] == '\n') {
|
||||
val_ptr[i] = '\0';
|
||||
/* move ptr to beginning of the value str */
|
||||
val_ptr = val_ptr + 1;
|
||||
}
|
||||
if (val_ptr[strspn(val_ptr, " \t\v\r\n")] == '\0') {
|
||||
log(ERROR,
|
||||
"Specified entry without value, line %d: %s",
|
||||
j, buf);
|
||||
failed = 1;
|
||||
line_itr, line);
|
||||
failed = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Here we check every single conf entry manually */
|
||||
if (!strcmp(buf, "db.type")) {
|
||||
if (!strcmp(tmp + 1, "mysql")) {
|
||||
/* || !strcmp(tmp[1], "postgresql") */
|
||||
/* || !strcmp(tmp[1], "oracle") */
|
||||
strncpy(conf.db.type, tmp + 1,
|
||||
sizeof(conf.db.type) - 1);
|
||||
if (conf.db.port[0] == '\0')
|
||||
strncpy(conf.db.port, "3306",
|
||||
sizeof(conf.db.port) - 1);
|
||||
if (!strcmp(line, "db.type")) {
|
||||
if (!strcmp(val_ptr, "mysql")) {
|
||||
/* || !strcmp(val_ptr[1], "postgresql") */
|
||||
/* || !strcmp(val_ptr[1], "oracle") */
|
||||
asprintf(&conf.db.type, "%s", val_ptr);
|
||||
if (!conf.db.port)
|
||||
asprintf(&conf.db.port, "%s", val_ptr);
|
||||
} else {
|
||||
ok = 0;
|
||||
log(ERROR, "Invalid db.type: %s", tmp + 1);
|
||||
failed = 1;
|
||||
val_ok = false;
|
||||
log(ERROR, "Invalid db.type: %s", "%s", val_ptr);
|
||||
failed = true;
|
||||
}
|
||||
} else if (!strcmp(buf, "db.hostname"))
|
||||
} else if (!strcmp(line, "db.hostname"))
|
||||
/* Just save it, launch_rmps will check it */
|
||||
strncpy(conf.db.hostname, tmp + 1,
|
||||
sizeof(conf.db.hostname) - 1);
|
||||
else if (!strcmp(buf, "db.port")) {
|
||||
i = strlen(tmp + 1);
|
||||
strncpy(conf.db.hostname, val_ptr, HOSTNAMESIZE - 1);
|
||||
else if (!strcmp(line, "db.port")) {
|
||||
i = strlen(val_ptr);
|
||||
if (i < 6) { /* max 5 digits for network port */
|
||||
if ((signed int)strspn(tmp + 1,
|
||||
"1234567890") == i) {
|
||||
i = atoi(tmp + 1);
|
||||
if ((signed int)strspn(val_ptr, "1234567890") == i) {
|
||||
i = atoi(val_ptr);
|
||||
if (i > 0 && i < 65536) {
|
||||
strncpy(conf.db.port, tmp + 1,
|
||||
sizeof(conf.db.port)-1);
|
||||
asprintf(&conf.db.port, "%s", val_ptr);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
log(ERROR, "Invalid db.port value: %s", tmp + 1);
|
||||
ok = 0;
|
||||
failed = 1;
|
||||
} else if (!strcmp(buf, "db.pass"))
|
||||
strncpy(conf.db.pass, tmp + 1,
|
||||
sizeof(conf.db.pass) - 1);
|
||||
else if (!strcmp(buf, "rmps.agent_ip")) {
|
||||
/* TODO */
|
||||
} else if (!strcmp(buf, "rmps.agent_port")) {
|
||||
i = strlen(tmp + 1);
|
||||
log(ERROR, "Invalid db.port value: %s", val_ptr);
|
||||
val_ok = false;
|
||||
failed = true;
|
||||
} else if (!strcmp(line, "db.pass"))
|
||||
asprintf(&conf.db.pass, "%s", val_ptr);
|
||||
else if (!strcmp(line, "rmps.agent_ip")) {
|
||||
asprintf(&conf.rmps.agent_ip, "%s", val_ptr);
|
||||
} else if (!strcmp(line, "rmps.agent_port")) {
|
||||
i = strlen(val_ptr);
|
||||
if (i < 6) { /* max 5 digits for network port */
|
||||
if ((signed int)strspn(tmp + 1,
|
||||
"1234567890") == i) {
|
||||
i = atoi(tmp + 1);
|
||||
if ((signed int)strspn(val_ptr, "1234567890") == i) {
|
||||
i = atoi(val_ptr);
|
||||
if (i > 0 && i < 65536) {
|
||||
strncpy(conf.rmps.agent_port,
|
||||
tmp + 1,
|
||||
sizeof(conf.rmps.agent_port) - 1);
|
||||
asprintf(&conf.rmps.agent_port, "%s", val_ptr);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
log(ERROR, "Invalid rmps.agent_port value: %s", tmp + 1);
|
||||
ok = 0;
|
||||
failed = 1;
|
||||
} else if (!strcmp(buf, "rmps.client_ip")) {
|
||||
/* TODO */
|
||||
} else if (!strcmp(buf, "rmps.client_port")) {
|
||||
i = strlen(tmp + 1);
|
||||
log(ERROR, "Invalid rmps.agent_port value: %s", val_ptr);
|
||||
val_ok = false;
|
||||
failed = true;
|
||||
} else if (!strcmp(line, "rmps.agent_poolsize")) {
|
||||
i = strlen(val_ptr);
|
||||
if ((signed int)strspn(val_ptr, "1234567890") == i) {
|
||||
i = atoi(val_ptr);
|
||||
if (i >= 0) {
|
||||
conf.rmps.agent_poolsize = i;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
log(ERROR, "Invalid rmps.agent_poolsize value: %s", val_ptr);
|
||||
val_ok = false;
|
||||
failed = true;
|
||||
} else if (!strcmp(line, "rmps.client_ip")) {
|
||||
asprintf(&conf.rmps.client_ip, "%s", val_ptr);
|
||||
} else if (!strcmp(line, "rmps.client_port")) {
|
||||
i = strlen(val_ptr);
|
||||
if (i < 6) { /* max 5 digits for network port */
|
||||
if ((signed int)strspn(tmp + 1,
|
||||
"1234567890") == i) {
|
||||
i = atoi(tmp + 1);
|
||||
if ((signed int)strspn(val_ptr, "1234567890") == i) {
|
||||
i = atoi(val_ptr);
|
||||
if (i > 0 && i < 65536) {
|
||||
strncpy(conf.rmps.client_port,
|
||||
tmp + 1,
|
||||
sizeof(conf.rmps.client_port) - 1);
|
||||
asprintf(&conf.rmps.client_port, "%s", val_ptr);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
log(ERROR, "Invalid rmps.client_port value: %s", tmp + 1);
|
||||
ok = 0;
|
||||
failed = 1;
|
||||
} else if (!strcmp(buf, "rmps.logfile")) {
|
||||
strncpy(conf.rmps.logfile, tmp + 1,
|
||||
sizeof(conf.rmps.logfile) - 1);
|
||||
log(ERROR, "Invalid rmps.client_port value: %s", val_ptr);
|
||||
val_ok = false;
|
||||
failed = true;
|
||||
} else if (!strcmp(line, "rmps.client_poolsize")) {
|
||||
i = strlen(val_ptr);
|
||||
if ((signed int)strspn(val_ptr, "1234567890") == i) {
|
||||
i = atoi(val_ptr);
|
||||
if (i >= 0) {
|
||||
conf.rmps.client_poolsize = i;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
log(ERROR, "Invalid rmps.client_poolsize value: %s", val_ptr);
|
||||
val_ok = false;
|
||||
failed = true;
|
||||
} else if (!strcmp(line, "rmps.logfile")) {
|
||||
asprintf(&conf.rmps.logfile, "%s", val_ptr);
|
||||
/*if (fopen_and_mkdir(conf.rmps.logfile) != 0)
|
||||
failed = 1;*/
|
||||
} else if (!strcmp(buf, "rmps.errlog")) {
|
||||
strncpy(conf.rmps.errlog, tmp + 1,
|
||||
sizeof(conf.rmps.errlog) - 1);
|
||||
failed = true;*/
|
||||
} else if (!strcmp(line, "rmps.errlog")) {
|
||||
asprintf(&conf.rmps.errlog, "%s", val_ptr);
|
||||
/*if (fopen_and_mkdir(conf.rmps.errlog) != 0)
|
||||
failed = 1;*/
|
||||
} else if (!strcmp(buf, "rmps.pidfile")) {
|
||||
strncpy(conf.rmps.pidfile, tmp + 1,
|
||||
sizeof(conf.rmps.pidfile) - 1);
|
||||
failed = true;*/
|
||||
} else if (!strcmp(line, "rmps.pidfile")) {
|
||||
asprintf(&conf.rmps.pidfile, "%s", val_ptr);
|
||||
/*if (fopen_and_mkdir(conf.rmps.pidfile) != 0)
|
||||
failed = 1;*/
|
||||
} else if (!strcmp(buf, "rmps.loglevel")) {
|
||||
if (strlen(tmp + 1) == 1 &&
|
||||
(tmp[1] > '0' && tmp[1] < '5'))
|
||||
conf.rmps.loglevel = tmp[1] - '0';
|
||||
failed = true;*/
|
||||
} else if (!strcmp(line, "rmps.loglevel")) {
|
||||
if (strlen(val_ptr) == 1 &&
|
||||
(val_ptr[0] > '0' && val_ptr[0] < '5'))
|
||||
conf.rmps.loglevel = val_ptr[0] - '0';
|
||||
else {
|
||||
log(ERROR, "Invalid loglevel: %s", tmp + 1);
|
||||
failed = 1;
|
||||
log(ERROR, "Invalid rmps.loglevel: %s", val_ptr);
|
||||
failed = true;
|
||||
}
|
||||
} else if (!strcmp(buf, "rmps.agent_tls_crt")) {
|
||||
if (access(tmp + 1, F_OK) == -1) {
|
||||
log(ERROR, "%s is missing", tmp + 1);
|
||||
failed = 1;
|
||||
} else if (access(tmp + 1, R_OK) == -1) {
|
||||
log(ERROR, "%s is not readable", tmp + 1);
|
||||
failed = 1;
|
||||
} else if (!strcmp(line, "rmps.agent_tls_crt")) {
|
||||
if (access(val_ptr, F_OK) == -1) {
|
||||
log(ERROR, "%s is missing", val_ptr);
|
||||
failed = true;
|
||||
} else if (access(val_ptr, R_OK) == -1) {
|
||||
log(ERROR, "%s is not readable", val_ptr);
|
||||
failed = true;
|
||||
} else
|
||||
strncpy(conf.rmps.agent_tls_crt,
|
||||
tmp + 1,
|
||||
sizeof(conf.rmps.agent_tls_crt) - 1);
|
||||
} else if (!strcmp(buf, "rmps.agent_tls_key")) {
|
||||
if (access(tmp + 1, F_OK) == -1) {
|
||||
log(ERROR, "%s is missing", tmp + 1);
|
||||
failed = 1;
|
||||
} else if (access(tmp + 1, R_OK) == -1) {
|
||||
log(ERROR, "%s is not readable", tmp + 1);
|
||||
failed = 1;
|
||||
asprintf(&conf.rmps.agent_tls_crt, "%s", val_ptr);
|
||||
} else if (!strcmp(line, "rmps.agent_tls_key")) {
|
||||
if (access(val_ptr, F_OK) == -1) {
|
||||
log(ERROR, "%s is missing", val_ptr);
|
||||
failed = true;
|
||||
} else if (access(val_ptr, R_OK) == -1) {
|
||||
log(ERROR, "%s is not readable", val_ptr);
|
||||
failed = true;
|
||||
} else
|
||||
strncpy(conf.rmps.agent_tls_key,
|
||||
tmp + 1,
|
||||
sizeof(conf.rmps.agent_tls_key) - 1);
|
||||
} else if (!strcmp(buf, "rmps.cipherlist")) {
|
||||
strncpy(conf.rmps.cipherlist,
|
||||
tmp + 1, sizeof(conf.rmps.cipherlist) - 1);
|
||||
} else if (!strcmp(buf, "rmps.cafile")) {
|
||||
if (access(tmp + 1, F_OK) == -1) {
|
||||
log(ERROR, "%s is missing", tmp + 1);
|
||||
failed = 1;
|
||||
} else if (access(tmp + 1, R_OK) == -1) {
|
||||
log(ERROR, "%s is not readable\n", tmp + 1);
|
||||
failed = 1;
|
||||
asprintf(&conf.rmps.agent_tls_key, "%s", val_ptr);
|
||||
} else if (!strcmp(line, "rmps.cipherlist")) {
|
||||
asprintf(&conf.rmps.cipherlist, "%s", val_ptr);
|
||||
} else if (!strcmp(line, "rmps.cafile")) {
|
||||
if (access(val_ptr, F_OK) == -1) {
|
||||
log(ERROR, "%s is missing", val_ptr);
|
||||
failed = true;
|
||||
} else if (access(val_ptr, R_OK) == -1) {
|
||||
log(ERROR, "%s is not readable\n", val_ptr);
|
||||
failed = true;
|
||||
} else
|
||||
strncpy(conf.rmps.cafile,
|
||||
tmp + 1, sizeof(conf.rmps.cafile) - 1);
|
||||
} else if (!strcmp(buf, "rmps.client_tls_crt")) {
|
||||
if (access(tmp + 1, F_OK) == -1) {
|
||||
log(ERROR, "%s is missing", tmp + 1);
|
||||
failed = 1;
|
||||
} else if (access(tmp + 1, R_OK) == -1) {
|
||||
log(ERROR, "%s is not readable", tmp + 1);
|
||||
failed = 1;
|
||||
asprintf(&conf.rmps.cafile, "%s", val_ptr);
|
||||
} else if (!strcmp(line, "rmps.client_tls_crt")) {
|
||||
if (access(val_ptr, F_OK) == -1) {
|
||||
log(ERROR, "%s is missing", val_ptr);
|
||||
failed = true;
|
||||
} else if (access(val_ptr, R_OK) == -1) {
|
||||
log(ERROR, "%s is not readable", val_ptr);
|
||||
failed = true;
|
||||
} else
|
||||
strncpy(conf.rmps.client_tls_crt,
|
||||
tmp + 1,
|
||||
sizeof(conf.rmps.client_tls_crt) - 1);
|
||||
} else if (!strcmp(buf, "rmps.client_tls_key")) {
|
||||
if (access(tmp + 1, F_OK) == -1) {
|
||||
log(ERROR, "%s is missing", tmp + 1);
|
||||
failed = 1;
|
||||
} else if (access(tmp + 1, R_OK) == -1) {
|
||||
log(ERROR, "%s is not readable", tmp + 1);
|
||||
failed = 1;
|
||||
asprintf(&conf.rmps.client_tls_crt, "%s", val_ptr);
|
||||
} else if (!strcmp(line, "rmps.client_tls_key")) {
|
||||
if (access(val_ptr, F_OK) == -1) {
|
||||
log(ERROR, "%s is missing", val_ptr);
|
||||
failed = true;
|
||||
} else if (access(val_ptr, R_OK) == -1) {
|
||||
log(ERROR, "%s is not readable", val_ptr);
|
||||
failed = true;
|
||||
} else
|
||||
strncpy(conf.rmps.client_tls_key,
|
||||
tmp + 1,
|
||||
sizeof(conf.rmps.client_tls_key) - 1);
|
||||
asprintf(&conf.rmps.client_tls_key, "%s", val_ptr);
|
||||
} else {
|
||||
log(ERROR, "Unknown config entry on line %d: %s",
|
||||
j, buf);
|
||||
failed = 1;
|
||||
line_itr, line);
|
||||
failed = true;
|
||||
}
|
||||
if (!ok) {
|
||||
if (!val_ok) {
|
||||
log(ERROR,
|
||||
"Invalid value for \"%s\", line %d: \"%s\"",
|
||||
buf, j, tmp + 1);
|
||||
ok = !ok;
|
||||
line, line_itr, val_ptr);
|
||||
val_ok = !val_ok;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
if (errno)
|
||||
log(ERROR, "confparse - getline() - %s", strerror(errno));
|
||||
free(line);
|
||||
|
||||
if (failed)
|
||||
return 1;
|
||||
conf.isvalid = 1;
|
||||
return 0;
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
int confparse(char *config)
|
||||
static bool test_conf_required(void)
|
||||
{
|
||||
int result;
|
||||
bool failed = false;
|
||||
|
||||
result = test_conf_perms(config);
|
||||
if (result)
|
||||
return 1; /* Bad conf perms */
|
||||
if (conf.db.hostname[0] == '\0') {
|
||||
log(ERROR, "cond.db.hostname - not set!");
|
||||
failed = true;
|
||||
}
|
||||
if (!conf.db.type) {
|
||||
log(ERROR, "cond.db.type - not set!");
|
||||
failed = true;
|
||||
}
|
||||
if (!conf.db.pass) {
|
||||
log(ERROR, "cond.db.pass - not set!");
|
||||
failed = true;
|
||||
}
|
||||
if (!conf.db.port) {
|
||||
log(ERROR, "cond.db.port - not set!");
|
||||
failed = true;
|
||||
}
|
||||
if (!conf.rmps.cipherlist) {
|
||||
log(ERROR, "conf.rmps.cipherlist - not set!");
|
||||
failed = true;
|
||||
}
|
||||
|
||||
result = test_conf_syntax(config);
|
||||
if (result != 0)
|
||||
return 1; /* Bad conf syntax */
|
||||
return 0; /* seems legit */
|
||||
if (failed)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool confparse(char *config)
|
||||
{
|
||||
init_conf();
|
||||
if (test_conf_perms(config) &&
|
||||
test_conf_syntax(config) &&
|
||||
test_conf_required())
|
||||
conf.isvalid = true;
|
||||
return conf.isvalid; /* seems legit */
|
||||
}
|
||||
|
||||
@@ -1,56 +1,35 @@
|
||||
/*
|
||||
* confparser.h
|
||||
*
|
||||
* Copyright (C) 2018 by Bogomil Vasilev <b.vasilev@smirky.net>
|
||||
*
|
||||
* This file is part of Remote Management and Provisioning System (RMPS).
|
||||
*
|
||||
* RMPS 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.
|
||||
*
|
||||
* RMPS 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 RMPS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef CONFPARSER_H
|
||||
#define CONFPARSER_H
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
#include "log.h"
|
||||
|
||||
#define HOSTNAMESIZE 128
|
||||
#define CFGLINESIZE (PATH_MAX + NAME_MAX + 30) /* 30 is pretty random */
|
||||
#define HOSTNAMESIZE 256 /* according to RFC 1035 */
|
||||
|
||||
struct conf_db {
|
||||
char type[15];
|
||||
char *type;
|
||||
char hostname[HOSTNAMESIZE];
|
||||
char port[6];
|
||||
char pass[60]; /* random decision */
|
||||
char *port;
|
||||
char *pass; /* random decision */
|
||||
};
|
||||
|
||||
struct conf_rmps {
|
||||
char agent_ip[13];
|
||||
char agent_port[6];
|
||||
char client_ip[13];
|
||||
char client_port[6];
|
||||
char logfile[PATH_MAX+NAME_MAX];
|
||||
char errlog[PATH_MAX+NAME_MAX];
|
||||
char *agent_ip;
|
||||
char *agent_port;
|
||||
char *client_ip;
|
||||
char *client_port;
|
||||
char *logfile;
|
||||
char *errlog;
|
||||
enum LOG_LEVEL loglevel;
|
||||
char pidfile[PATH_MAX+NAME_MAX];
|
||||
char agent_tls_crt[PATH_MAX+NAME_MAX];
|
||||
char agent_tls_key[PATH_MAX+NAME_MAX];
|
||||
char cafile[PATH_MAX+NAME_MAX];
|
||||
char cipherlist[1024];
|
||||
char *pidfile;
|
||||
char *agent_tls_crt;
|
||||
char *agent_tls_key;
|
||||
char *cafile;
|
||||
char *cipherlist;
|
||||
int agent_poolsize;
|
||||
char client_tls_crt[PATH_MAX+NAME_MAX];
|
||||
char client_tls_key[PATH_MAX+NAME_MAX];
|
||||
char *client_tls_crt;
|
||||
char *client_tls_key;
|
||||
int client_poolsize;
|
||||
};
|
||||
|
||||
@@ -59,14 +38,14 @@ struct conf_nfs {
|
||||
};
|
||||
|
||||
struct conf_table {
|
||||
int isvalid;
|
||||
bool isvalid;
|
||||
struct conf_db db;
|
||||
struct conf_rmps rmps;
|
||||
struct conf_nfs nfs;
|
||||
};
|
||||
|
||||
extern struct conf_table conf;
|
||||
extern int confparse(char *config);
|
||||
extern bool confparse(char *config);
|
||||
extern void confexport(void);
|
||||
extern const char *conf_db_pass(void);
|
||||
extern const char *conf_db_hostname(void);
|
||||
|
||||
@@ -1,53 +1,45 @@
|
||||
/*
|
||||
* enum_functions.c
|
||||
*
|
||||
* Copyright (C) 2018 by Bogomil Vasilev <b.vasilev@smirky.net>
|
||||
*
|
||||
* This file is part of Remote Management and Provisioning System (RMPS).
|
||||
*
|
||||
* RMPS 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.
|
||||
*
|
||||
* RMPS 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 RMPS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include "enum_functions.h"
|
||||
#include "log.h"
|
||||
|
||||
void enumtostr(char *scode, int code)
|
||||
void enumtostr(char **meaning, int code)
|
||||
{
|
||||
char line[128];
|
||||
char *line = NULL, *val_ptr;
|
||||
size_t len = 0;
|
||||
ssize_t line_len;
|
||||
FILE *fp;
|
||||
int bytes = 0;
|
||||
bool found = false;
|
||||
|
||||
snprintf(scode, 10, "%d", code);
|
||||
if (asprintf(meaning, "%d", code) == -1) {
|
||||
log(ERROR, "asprintf() in enumtostr() OOM!");
|
||||
free(*meaning);
|
||||
return;
|
||||
}
|
||||
|
||||
fp = fopen("/usr/lib/rmps/resources/enum_codes", "r");
|
||||
if (fp == NULL) {
|
||||
log(ERROR, "Failed to fetch error enum code!");
|
||||
return;
|
||||
}
|
||||
while (fgets(line, sizeof(line), fp) != NULL)
|
||||
if (strstr(line, scode) != NULL) {
|
||||
char *byte;
|
||||
|
||||
bytes = sprintf(scode, "%s", line);
|
||||
byte = memchr(scode, '\n', bytes);
|
||||
byte[-1] = '\0';
|
||||
while ((line_len = getline(&line, &len, fp)) != -1) {
|
||||
if (line[line_len-2] == '"')
|
||||
line[line_len-2] = '\0';
|
||||
if ((val_ptr = strstr(line, *meaning)) != NULL) {
|
||||
found = true;
|
||||
val_ptr = strchr(line, '"') + 1;
|
||||
asprintf(meaning, "%s", val_ptr);
|
||||
break;
|
||||
}
|
||||
strncpy(scode, (char *)memchr(scode, '\"', bytes) + 1, bytes);
|
||||
}
|
||||
|
||||
if (!found)
|
||||
asprintf(meaning, "Unknown enum_code: %d", code);
|
||||
if (line)
|
||||
free(line);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,24 +1,3 @@
|
||||
/*
|
||||
* enum_functions.h
|
||||
*
|
||||
* Copyright (C) 2018 by Bogomil Vasilev <b.vasilev@smirky.net>
|
||||
*
|
||||
* This file is part of Remote Management and Provisioning System (RMPS).
|
||||
*
|
||||
* RMPS 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.
|
||||
*
|
||||
* RMPS 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 RMPS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef ENUM_FUNCTIONS_H
|
||||
#define ENUM_FUNCTIONS_H
|
||||
|
||||
@@ -41,6 +20,6 @@ enum WARN_CODES {
|
||||
CONF_FILE_PERM_INSECURE,
|
||||
};
|
||||
|
||||
extern void enumtostr(char *scode, int code);
|
||||
extern void enumtostr(char **meaning, int code);
|
||||
|
||||
#endif /* ENUM_FUNCTIONS_H */
|
||||
|
||||
@@ -1,24 +1,3 @@
|
||||
/*
|
||||
* job_queue.c
|
||||
*
|
||||
* Copyright (C) 2018 by Bogomil Vasilev <b.vasilev@smirky.net>
|
||||
*
|
||||
* This file is part of Remote Management and Provisioning System (RMPS).
|
||||
*
|
||||
* RMPS 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.
|
||||
*
|
||||
* RMPS 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 RMPS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "sql.h"
|
||||
|
||||
@@ -1,24 +1,3 @@
|
||||
/*
|
||||
* job_queue.h
|
||||
*
|
||||
* Copyright (C) 2018 by Bogomil Vasilev <b.vasilev@smirky.net>
|
||||
*
|
||||
* This file is part of Remote Management and Provisioning System (RMPS).
|
||||
*
|
||||
* RMPS 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.
|
||||
*
|
||||
* RMPS 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 RMPS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef JOB_QUEUE_H
|
||||
#define JOB_QUEUE_H
|
||||
|
||||
|
||||
21
src/log.c
21
src/log.c
@@ -1,24 +1,3 @@
|
||||
/*
|
||||
* log.c
|
||||
*
|
||||
* Copyright (C) 2018 by Bogomil Vasilev <b.vasilev@smirky.net>
|
||||
*
|
||||
* This file is part of Remote Management and Provisioning System (RMPS).
|
||||
*
|
||||
* RMPS 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.
|
||||
*
|
||||
* RMPS 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 RMPS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
21
src/log.h
21
src/log.h
@@ -1,24 +1,3 @@
|
||||
/*
|
||||
* log.h
|
||||
*
|
||||
* Copyright (C) 2018 by Bogomil Vasilev <b.vasilev@smirky.net>
|
||||
*
|
||||
* This file is part of Remote Management and Provisioning System (RMPS).
|
||||
*
|
||||
* RMPS 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.
|
||||
*
|
||||
* RMPS 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 RMPS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LOGGING
|
||||
#define LOGGING
|
||||
|
||||
|
||||
29
src/main.c
29
src/main.c
@@ -1,24 +1,3 @@
|
||||
/*
|
||||
* main.c
|
||||
*
|
||||
* Copyright (C) 2018 by Bogomil Vasilev <b.vasilev@smirky.net>
|
||||
*
|
||||
* This file is part of Remote Management and Provisioning System (RMPS).
|
||||
*
|
||||
* RMPS 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.
|
||||
*
|
||||
* RMPS 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 RMPS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
#include "confparser.h"
|
||||
@@ -106,14 +85,14 @@ int main(int argc, char *argv[])
|
||||
|
||||
config = calloc(sizeof(char), path_size);
|
||||
if (config == NULL) {
|
||||
log(ERROR, "malloc() failed for config");
|
||||
fprintf(stderr, "calloc() failed for config\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
memcpy(config, path, path_size);
|
||||
}
|
||||
|
||||
if (confparse(config) != 0) {
|
||||
log(ERROR, "Failed to parse the conf!");
|
||||
if (!confparse(config)) {
|
||||
fprintf(stderr, "Failed to parse the conf!\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
log(VERBOSE, "Conf parser finished successfully");
|
||||
@@ -131,7 +110,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
if (task == START || task == RESTART)
|
||||
rmps_launch(&conf, fork_flag);
|
||||
rmps_launch(fork_flag);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,24 +1,3 @@
|
||||
/*
|
||||
* protocol.c
|
||||
*
|
||||
* Copyright (C) 2018 by Bogomil Vasilev <b.vasilev@smirky.net>
|
||||
*
|
||||
* This file is part of Remote Management and Provisioning System (RMPS).
|
||||
*
|
||||
* RMPS 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.
|
||||
*
|
||||
* RMPS 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 RMPS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "protocol.h"
|
||||
|
||||
|
||||
|
||||
@@ -1,24 +1,3 @@
|
||||
/*
|
||||
* protocol.h
|
||||
*
|
||||
* Copyright (C) 2018 by Bogomil Vasilev <b.vasilev@smirky.net>
|
||||
*
|
||||
* This file is part of Remote Management and Provisioning System (RMPS).
|
||||
*
|
||||
* RMPS 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.
|
||||
*
|
||||
* RMPS 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 RMPS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROTOCOL_H
|
||||
#define PROTOCOL_H
|
||||
|
||||
|
||||
83
src/rmps.c
83
src/rmps.c
@@ -1,24 +1,3 @@
|
||||
/*
|
||||
* rmps.c
|
||||
*
|
||||
* Copyright (C) 2018 by Bogomil Vasilev <b.vasilev@smirky.net>
|
||||
*
|
||||
* This file is part of Remote Management and Provisioning System (RMPS).
|
||||
*
|
||||
* RMPS 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.
|
||||
*
|
||||
* RMPS 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 RMPS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "log.h"
|
||||
#include "confparser.h"
|
||||
#include "agent_pool.h"
|
||||
@@ -42,13 +21,16 @@ static void set_env(void);
|
||||
static void daemonize(const char *rundir);
|
||||
static void spawn_pidfile(const char *pidfile);
|
||||
static inline int set_reuse_addr(int sockfd);
|
||||
static int open_listener(int port);
|
||||
static int open_listener(char *ip, int port);
|
||||
static void cleanup(void);
|
||||
static void signal_handler(int sig);
|
||||
static void load_certificates(SSL_CTX *ctx, const char *certfile,
|
||||
const char *keyfile, const char *cafile);
|
||||
static SSL_CTX *init_server_ctx(const char *cipherlist, int mode);
|
||||
|
||||
pthread_t agent_pool_thread;
|
||||
pthread_t client_pool_thread;
|
||||
|
||||
static int pid_file_handle;
|
||||
|
||||
static void cleanup(void)
|
||||
@@ -86,6 +68,10 @@ static void signal_handler(int sig)
|
||||
|
||||
static void rmps_shutdown(void)
|
||||
{
|
||||
pthread_cancel(agent_pool_thread);
|
||||
pthread_join(agent_pool_thread, NULL);
|
||||
pthread_cancel(client_pool_thread);
|
||||
pthread_join(client_pool_thread, NULL);
|
||||
close(pid_file_handle);
|
||||
cleanup();
|
||||
}
|
||||
@@ -160,6 +146,11 @@ static void daemonize(const char *rundir)
|
||||
static void spawn_pidfile(const char *pidfile)
|
||||
{
|
||||
char str[10];
|
||||
|
||||
if (access(pidfile, F_OK) != -1) {
|
||||
log(ERROR, "PID file %s exists. RMPS is already running!", pidfile);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
/* Ensure only one copy */
|
||||
pid_file_handle = open(pidfile, O_RDWR|O_CREAT, 0600);
|
||||
if (pid_file_handle == -1) {
|
||||
@@ -190,7 +181,7 @@ static inline int set_reuse_addr(int sockfd)
|
||||
&yes, sizeof(yes));
|
||||
}
|
||||
|
||||
static int open_listener(int port)
|
||||
static int open_listener(char *ip, int port)
|
||||
{
|
||||
int sd;
|
||||
struct sockaddr_in addr;
|
||||
@@ -198,7 +189,14 @@ static int open_listener(int port)
|
||||
bzero(&addr, sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(port);
|
||||
unsigned long tmp;
|
||||
if (strncmp(ip, "any", strlen(ip)) == 0)
|
||||
addr.sin_addr.s_addr = INADDR_ANY;
|
||||
else if (!inet_pton(AF_INET, ip, &tmp)) {
|
||||
log(ERROR, "Invalid IP address: %s", ip);
|
||||
exit(EXIT_FAILURE);
|
||||
} else
|
||||
addr.sin_addr.s_addr = inet_addr(ip);
|
||||
sd = socket(addr.sin_family, SOCK_STREAM, 0);
|
||||
if (sd < 0) {
|
||||
log(ERROR, "Failed to create socket - Aborting RMPS...");
|
||||
@@ -331,9 +329,8 @@ int rmps_die(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void rmps_launch(struct conf_table *conf, int fork_flag)
|
||||
void rmps_launch(int fork_flag)
|
||||
{
|
||||
pthread_t pool[2];
|
||||
struct pool_data pool_args[2];
|
||||
|
||||
log(INFO, "Starting up RMPS...");
|
||||
@@ -343,42 +340,42 @@ void rmps_launch(struct conf_table *conf, int fork_flag)
|
||||
if (fork_flag)
|
||||
daemonize("/tmp/");
|
||||
/* Spawn & lock pidfile */
|
||||
spawn_pidfile(conf->rmps.pidfile);
|
||||
spawn_pidfile(conf.rmps.pidfile);
|
||||
|
||||
/* openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days XXX -nodes
|
||||
* -nodes is for not protecing with a passphrase
|
||||
* http://stackoverflow.com/questions/10175812/how-to-create-a-self-signed-certificate-with-openssl
|
||||
*/
|
||||
pool_args[0].ctx = init_server_ctx(conf->rmps.cipherlist,
|
||||
pool_args[0].ctx = init_server_ctx(conf.rmps.cipherlist,
|
||||
SSL_VERIFY_PEER |
|
||||
SSL_VERIFY_CLIENT_ONCE |
|
||||
SSL_VERIFY_FAIL_IF_NO_PEER_CERT);
|
||||
log(VERBOSE, "Loading agent certs and keys.");
|
||||
load_certificates(pool_args[0].ctx, conf->rmps.agent_tls_crt,
|
||||
conf->rmps.agent_tls_key, conf->rmps.cafile);
|
||||
load_certificates(pool_args[0].ctx, conf.rmps.agent_tls_crt,
|
||||
conf.rmps.agent_tls_key, conf.rmps.cafile);
|
||||
log(VERBOSE, "Starting agent listener on port: %d",
|
||||
atoi(conf->rmps.agent_port));
|
||||
pool_args[0].srv = open_listener(atoi(conf->rmps.agent_port));
|
||||
pool_args[0].size = conf->rmps.agent_poolsize;
|
||||
atoi(conf.rmps.agent_port));
|
||||
pool_args[0].srv = open_listener(conf.rmps.agent_ip, atoi(conf.rmps.agent_port));
|
||||
pool_args[0].size = conf.rmps.agent_poolsize;
|
||||
log(VERBOSE, "Creating agent thread pool (mutex).");
|
||||
pthread_create(&pool[0], NULL, agent_pool, &pool_args[0]);
|
||||
pthread_create(&agent_pool_thread, NULL, agent_pool, &pool_args[0]);
|
||||
|
||||
pool_args[1].ctx = init_server_ctx(conf->rmps.cipherlist,
|
||||
pool_args[1].ctx = init_server_ctx(conf.rmps.cipherlist,
|
||||
SSL_VERIFY_NONE);
|
||||
log(VERBOSE, "Loading client certs and keys.");
|
||||
load_certificates(pool_args[1].ctx, conf->rmps.client_tls_crt,
|
||||
conf->rmps.client_tls_key, conf->rmps.cafile);
|
||||
load_certificates(pool_args[1].ctx, conf.rmps.client_tls_crt,
|
||||
conf.rmps.client_tls_key, conf.rmps.cafile);
|
||||
log(VERBOSE, "Starting client listener on port: %d",
|
||||
atoi(conf->rmps.client_port));
|
||||
pool_args[1].srv = open_listener(atoi(conf->rmps.client_port));
|
||||
pool_args[1].size = conf->rmps.client_poolsize;
|
||||
atoi(conf.rmps.client_port));
|
||||
pool_args[1].srv = open_listener(conf.rmps.client_ip, atoi(conf.rmps.client_port));
|
||||
pool_args[1].size = conf.rmps.client_poolsize;
|
||||
log(VERBOSE, "Creating client thread pool (mutex).");
|
||||
pthread_create(&pool[1], NULL, client_pool, &pool_args[1]);
|
||||
if (start_job_queue(conf->rmps.agent_poolsize) == FAIL) {
|
||||
pthread_create(&client_pool_thread, NULL, client_pool, &pool_args[1]);
|
||||
if (start_job_queue(conf.rmps.agent_poolsize) == FAIL) {
|
||||
log(ERROR,
|
||||
"On start_job_queue(), RMPS failed to start, shutting down...");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
pthread_join(pool[0], NULL);
|
||||
pthread_join(pool[1], NULL);
|
||||
pthread_join(agent_pool_thread, NULL);
|
||||
pthread_join(client_pool_thread , NULL);
|
||||
}
|
||||
|
||||
23
src/rmps.h
23
src/rmps.h
@@ -1,24 +1,3 @@
|
||||
/*
|
||||
* rmps.h
|
||||
*
|
||||
* Copyright (C) 2018 by Bogomil Vasilev <b.vasilev@smirky.net>
|
||||
*
|
||||
* This file is part of Remote Management and Provisioning System (RMPS).
|
||||
*
|
||||
* RMPS 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.
|
||||
*
|
||||
* RMPS 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 RMPS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef RMPS_H
|
||||
#define RMPS_H
|
||||
|
||||
@@ -31,7 +10,7 @@ struct pool_data {
|
||||
int size;
|
||||
};
|
||||
|
||||
extern void rmps_launch(struct conf_table *conf, int fork_flag);
|
||||
extern void rmps_launch(int fork_flag);
|
||||
extern int rmps_die(void);
|
||||
|
||||
#endif /* RMPS_H */
|
||||
|
||||
21
src/sql.c
21
src/sql.c
@@ -1,24 +1,3 @@
|
||||
/*
|
||||
* sql.c
|
||||
*
|
||||
* Copyright (C) 2018 by Bogomil Vasilev <b.vasilev@smirky.net>
|
||||
*
|
||||
* This file is part of Remote Management and Provisioning System (RMPS).
|
||||
*
|
||||
* RMPS 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.
|
||||
*
|
||||
* RMPS 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 RMPS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <mysql.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
21
src/sql.h
21
src/sql.h
@@ -1,24 +1,3 @@
|
||||
/*
|
||||
* sql.h
|
||||
*
|
||||
* Copyright (C) 2018 by Bogomil Vasilev <b.vasilev@smirky.net>
|
||||
*
|
||||
* This file is part of Remote Management and Provisioning System (RMPS).
|
||||
*
|
||||
* RMPS 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.
|
||||
*
|
||||
* RMPS 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 RMPS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SQL_H
|
||||
#define SQL_H
|
||||
|
||||
|
||||
Reference in New Issue
Block a user