7ce16504ea4e738705069ad00540472ba7d59e14
[pti/rtp.git] / meta-stx / recipes-core / stx-integ / files / base / 0001-cgcs-users-with-patch-ibsh-patches.patch
1 From b62415943878891ce000b9e0b414354b60047876 Mon Sep 17 00:00:00 2001
2 From: babak sarashki <babak.sarashki@windriver.com>
3 Date: Tue, 2 Jul 2019 14:09:28 -0700
4 Subject: [PATCH 1/2] cgcs-users with patch ibsh patches
5
6 Applied ibsh-0.3e-cgcs.patch and copyright patch.
7 ---
8  base/cgcs-users/cgcs-users-1.0/BUGS           |  19 +
9  base/cgcs-users/cgcs-users-1.0/CONTRIBUTORS   |   7 +
10  base/cgcs-users/cgcs-users-1.0/COPYING        | 340 ++++++++++++++++++
11  base/cgcs-users/cgcs-users-1.0/COPYRIGHT      |  17 +
12  base/cgcs-users/cgcs-users-1.0/INSTALL        |  23 ++
13  base/cgcs-users/cgcs-users-1.0/Makefile       |  56 +++
14  base/cgcs-users/cgcs-users-1.0/README         |  29 ++
15  base/cgcs-users/cgcs-users-1.0/Release        |  17 +
16  base/cgcs-users/cgcs-users-1.0/TODO           |  10 +
17  base/cgcs-users/cgcs-users-1.0/VERSION        |   1 +
18  base/cgcs-users/cgcs-users-1.0/antixploit.c   | 131 +++++++
19  base/cgcs-users/cgcs-users-1.0/command.c      | 209 +++++++++++
20  base/cgcs-users/cgcs-users-1.0/config.c       | 179 +++++++++
21  base/cgcs-users/cgcs-users-1.0/delbadfiles.c  | 239 ++++++++++++
22  .../cgcs-users-1.0/example.allowall.xtns      |  28 ++
23  .../cgcs-users-1.0/example.denyall.xtns       |   2 +
24  base/cgcs-users/cgcs-users-1.0/execute.c      | 159 ++++++++
25  base/cgcs-users/cgcs-users-1.0/globals.cmds   |   8 +
26  base/cgcs-users/cgcs-users-1.0/globals.xtns   |   3 +
27  base/cgcs-users/cgcs-users-1.0/ibsh.h         | 126 +++++++
28  base/cgcs-users/cgcs-users-1.0/jail.c         | 101 ++++++
29  base/cgcs-users/cgcs-users-1.0/main.c         | 239 ++++++++++++
30  base/cgcs-users/cgcs-users-1.0/misc.c         |  52 +++
31  23 files changed, 1995 insertions(+)
32  create mode 100644 base/cgcs-users/cgcs-users-1.0/BUGS
33  create mode 100644 base/cgcs-users/cgcs-users-1.0/CONTRIBUTORS
34  create mode 100644 base/cgcs-users/cgcs-users-1.0/COPYING
35  create mode 100644 base/cgcs-users/cgcs-users-1.0/COPYRIGHT
36  create mode 100644 base/cgcs-users/cgcs-users-1.0/INSTALL
37  create mode 100644 base/cgcs-users/cgcs-users-1.0/Makefile
38  create mode 100644 base/cgcs-users/cgcs-users-1.0/README
39  create mode 100644 base/cgcs-users/cgcs-users-1.0/Release
40  create mode 100644 base/cgcs-users/cgcs-users-1.0/TODO
41  create mode 100644 base/cgcs-users/cgcs-users-1.0/VERSION
42  create mode 100644 base/cgcs-users/cgcs-users-1.0/antixploit.c
43  create mode 100644 base/cgcs-users/cgcs-users-1.0/command.c
44  create mode 100644 base/cgcs-users/cgcs-users-1.0/config.c
45  create mode 100644 base/cgcs-users/cgcs-users-1.0/delbadfiles.c
46  create mode 100644 base/cgcs-users/cgcs-users-1.0/example.allowall.xtns
47  create mode 100644 base/cgcs-users/cgcs-users-1.0/example.denyall.xtns
48  create mode 100644 base/cgcs-users/cgcs-users-1.0/execute.c
49  create mode 100644 base/cgcs-users/cgcs-users-1.0/globals.cmds
50  create mode 100644 base/cgcs-users/cgcs-users-1.0/globals.xtns
51  create mode 100644 base/cgcs-users/cgcs-users-1.0/ibsh.h
52  create mode 100644 base/cgcs-users/cgcs-users-1.0/jail.c
53  create mode 100644 base/cgcs-users/cgcs-users-1.0/main.c
54  create mode 100644 base/cgcs-users/cgcs-users-1.0/misc.c
55
56 diff --git a/base/cgcs-users/cgcs-users-1.0/BUGS b/base/cgcs-users/cgcs-users-1.0/BUGS
57 new file mode 100644
58 index 0000000..7dacaab
59 --- /dev/null
60 +++ b/base/cgcs-users/cgcs-users-1.0/BUGS
61 @@ -0,0 +1,19 @@
62 +** Open BUGS **
63 +None, so far.
64 +
65 +** Fixed BUGS **
66 +- Input length checking on all inputs, string copies, etc. is fixed.
67 +- The myscanf function will no longer accept more then 80 chars at once,
68 +so ibsh hopefully wont crash on a too long input.
69 +- Added signal.h in the header file, the lack of it caused compilation
70 +problems on some systems.
71 +- Fixed the infinite loop in DelBadFiles. This function is temporarily 
72 +taken out of the project
73 +- Removed the involvment of /bin/sh from system. Added path checking.
74 +- In jail root, not only ../ is not allowed, but .. too.
75 +- Fixed a bug, that happened on bsd, when the user pressed ^D.
76 +- Fixed a bug with opendir
77 +- Fixed a format string vulnerability in logprintbadfile(). Thanks to
78 +Kim Streich for the report.
79 +
80 +2005.05.23
81 diff --git a/base/cgcs-users/cgcs-users-1.0/CONTRIBUTORS b/base/cgcs-users/cgcs-users-1.0/CONTRIBUTORS
82 new file mode 100644
83 index 0000000..35ca436
84 --- /dev/null
85 +++ b/base/cgcs-users/cgcs-users-1.0/CONTRIBUTORS
86 @@ -0,0 +1,7 @@
87 +CONTRIBUTORS TO PROJECT IBSH
88 +
89 +Kim Streich <kstreich at gmail.com>
90 +       * bug finder, debugger, tester.
91 +
92 +RazoR (Nikolay Alexandrov) <Nikolay@Alexandrov.ws>
93 +       * bug finder, debugger, tester.
94 diff --git a/base/cgcs-users/cgcs-users-1.0/COPYING b/base/cgcs-users/cgcs-users-1.0/COPYING
95 new file mode 100644
96 index 0000000..d60c31a
97 --- /dev/null
98 +++ b/base/cgcs-users/cgcs-users-1.0/COPYING
99 @@ -0,0 +1,340 @@
100 +                   GNU GENERAL PUBLIC LICENSE
101 +                      Version 2, June 1991
102 +
103 + Copyright (C) 1989, 1991 Free Software Foundation, Inc.
104 +     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
105 + Everyone is permitted to copy and distribute verbatim copies
106 + of this license document, but changing it is not allowed.
107 +
108 +                           Preamble
109 +
110 +  The licenses for most software are designed to take away your
111 +freedom to share and change it.  By contrast, the GNU General Public
112 +License is intended to guarantee your freedom to share and change free
113 +software--to make sure the software is free for all its users.  This
114 +General Public License applies to most of the Free Software
115 +Foundation's software and to any other program whose authors commit to
116 +using it.  (Some other Free Software Foundation software is covered by
117 +the GNU Library General Public License instead.)  You can apply it to
118 +your programs, too.
119 +
120 +  When we speak of free software, we are referring to freedom, not
121 +price.  Our General Public Licenses are designed to make sure that you
122 +have the freedom to distribute copies of free software (and charge for
123 +this service if you wish), that you receive source code or can get it
124 +if you want it, that you can change the software or use pieces of it
125 +in new free programs; and that you know you can do these things.
126 +
127 +  To protect your rights, we need to make restrictions that forbid
128 +anyone to deny you these rights or to ask you to surrender the rights.
129 +These restrictions translate to certain responsibilities for you if you
130 +distribute copies of the software, or if you modify it.
131 +
132 +  For example, if you distribute copies of such a program, whether
133 +gratis or for a fee, you must give the recipients all the rights that
134 +you have.  You must make sure that they, too, receive or can get the
135 +source code.  And you must show them these terms so they know their
136 +rights.
137 +
138 +  We protect your rights with two steps: (1) copyright the software, and
139 +(2) offer you this license which gives you legal permission to copy,
140 +distribute and/or modify the software.
141 +
142 +  Also, for each author's protection and ours, we want to make certain
143 +that everyone understands that there is no warranty for this free
144 +software.  If the software is modified by someone else and passed on, we
145 +want its recipients to know that what they have is not the original, so
146 +that any problems introduced by others will not reflect on the original
147 +authors' reputations.
148 +
149 +  Finally, any free program is threatened constantly by software
150 +patents.  We wish to avoid the danger that redistributors of a free
151 +program will individually obtain patent licenses, in effect making the
152 +program proprietary.  To prevent this, we have made it clear that any
153 +patent must be licensed for everyone's free use or not licensed at all.
154 +
155 +  The precise terms and conditions for copying, distribution and
156 +modification follow.
157 +\f
158 +                   GNU GENERAL PUBLIC LICENSE
159 +   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
160 +
161 +  0. This License applies to any program or other work which contains
162 +a notice placed by the copyright holder saying it may be distributed
163 +under the terms of this General Public License.  The "Program", below,
164 +refers to any such program or work, and a "work based on the Program"
165 +means either the Program or any derivative work under copyright law:
166 +that is to say, a work containing the Program or a portion of it,
167 +either verbatim or with modifications and/or translated into another
168 +language.  (Hereinafter, translation is included without limitation in
169 +the term "modification".)  Each licensee is addressed as "you".
170 +
171 +Activities other than copying, distribution and modification are not
172 +covered by this License; they are outside its scope.  The act of
173 +running the Program is not restricted, and the output from the Program
174 +is covered only if its contents constitute a work based on the
175 +Program (independent of having been made by running the Program).
176 +Whether that is true depends on what the Program does.
177 +
178 +  1. You may copy and distribute verbatim copies of the Program's
179 +source code as you receive it, in any medium, provided that you
180 +conspicuously and appropriately publish on each copy an appropriate
181 +copyright notice and disclaimer of warranty; keep intact all the
182 +notices that refer to this License and to the absence of any warranty;
183 +and give any other recipients of the Program a copy of this License
184 +along with the Program.
185 +
186 +You may charge a fee for the physical act of transferring a copy, and
187 +you may at your option offer warranty protection in exchange for a fee.
188 +
189 +  2. You may modify your copy or copies of the Program or any portion
190 +of it, thus forming a work based on the Program, and copy and
191 +distribute such modifications or work under the terms of Section 1
192 +above, provided that you also meet all of these conditions:
193 +
194 +    a) You must cause the modified files to carry prominent notices
195 +    stating that you changed the files and the date of any change.
196 +
197 +    b) You must cause any work that you distribute or publish, that in
198 +    whole or in part contains or is derived from the Program or any
199 +    part thereof, to be licensed as a whole at no charge to all third
200 +    parties under the terms of this License.
201 +
202 +    c) If the modified program normally reads commands interactively
203 +    when run, you must cause it, when started running for such
204 +    interactive use in the most ordinary way, to print or display an
205 +    announcement including an appropriate copyright notice and a
206 +    notice that there is no warranty (or else, saying that you provide
207 +    a warranty) and that users may redistribute the program under
208 +    these conditions, and telling the user how to view a copy of this
209 +    License.  (Exception: if the Program itself is interactive but
210 +    does not normally print such an announcement, your work based on
211 +    the Program is not required to print an announcement.)
212 +\f
213 +These requirements apply to the modified work as a whole.  If
214 +identifiable sections of that work are not derived from the Program,
215 +and can be reasonably considered independent and separate works in
216 +themselves, then this License, and its terms, do not apply to those
217 +sections when you distribute them as separate works.  But when you
218 +distribute the same sections as part of a whole which is a work based
219 +on the Program, the distribution of the whole must be on the terms of
220 +this License, whose permissions for other licensees extend to the
221 +entire whole, and thus to each and every part regardless of who wrote it.
222 +
223 +Thus, it is not the intent of this section to claim rights or contest
224 +your rights to work written entirely by you; rather, the intent is to
225 +exercise the right to control the distribution of derivative or
226 +collective works based on the Program.
227 +
228 +In addition, mere aggregation of another work not based on the Program
229 +with the Program (or with a work based on the Program) on a volume of
230 +a storage or distribution medium does not bring the other work under
231 +the scope of this License.
232 +
233 +  3. You may copy and distribute the Program (or a work based on it,
234 +under Section 2) in object code or executable form under the terms of
235 +Sections 1 and 2 above provided that you also do one of the following:
236 +
237 +    a) Accompany it with the complete corresponding machine-readable
238 +    source code, which must be distributed under the terms of Sections
239 +    1 and 2 above on a medium customarily used for software interchange; or,
240 +
241 +    b) Accompany it with a written offer, valid for at least three
242 +    years, to give any third party, for a charge no more than your
243 +    cost of physically performing source distribution, a complete
244 +    machine-readable copy of the corresponding source code, to be
245 +    distributed under the terms of Sections 1 and 2 above on a medium
246 +    customarily used for software interchange; or,
247 +
248 +    c) Accompany it with the information you received as to the offer
249 +    to distribute corresponding source code.  (This alternative is
250 +    allowed only for noncommercial distribution and only if you
251 +    received the program in object code or executable form with such
252 +    an offer, in accord with Subsection b above.)
253 +
254 +The source code for a work means the preferred form of the work for
255 +making modifications to it.  For an executable work, complete source
256 +code means all the source code for all modules it contains, plus any
257 +associated interface definition files, plus the scripts used to
258 +control compilation and installation of the executable.  However, as a
259 +special exception, the source code distributed need not include
260 +anything that is normally distributed (in either source or binary
261 +form) with the major components (compiler, kernel, and so on) of the
262 +operating system on which the executable runs, unless that component
263 +itself accompanies the executable.
264 +
265 +If distribution of executable or object code is made by offering
266 +access to copy from a designated place, then offering equivalent
267 +access to copy the source code from the same place counts as
268 +distribution of the source code, even though third parties are not
269 +compelled to copy the source along with the object code.
270 +\f
271 +  4. You may not copy, modify, sublicense, or distribute the Program
272 +except as expressly provided under this License.  Any attempt
273 +otherwise to copy, modify, sublicense or distribute the Program is
274 +void, and will automatically terminate your rights under this License.
275 +However, parties who have received copies, or rights, from you under
276 +this License will not have their licenses terminated so long as such
277 +parties remain in full compliance.
278 +
279 +  5. You are not required to accept this License, since you have not
280 +signed it.  However, nothing else grants you permission to modify or
281 +distribute the Program or its derivative works.  These actions are
282 +prohibited by law if you do not accept this License.  Therefore, by
283 +modifying or distributing the Program (or any work based on the
284 +Program), you indicate your acceptance of this License to do so, and
285 +all its terms and conditions for copying, distributing or modifying
286 +the Program or works based on it.
287 +
288 +  6. Each time you redistribute the Program (or any work based on the
289 +Program), the recipient automatically receives a license from the
290 +original licensor to copy, distribute or modify the Program subject to
291 +these terms and conditions.  You may not impose any further
292 +restrictions on the recipients' exercise of the rights granted herein.
293 +You are not responsible for enforcing compliance by third parties to
294 +this License.
295 +
296 +  7. If, as a consequence of a court judgment or allegation of patent
297 +infringement or for any other reason (not limited to patent issues),
298 +conditions are imposed on you (whether by court order, agreement or
299 +otherwise) that contradict the conditions of this License, they do not
300 +excuse you from the conditions of this License.  If you cannot
301 +distribute so as to satisfy simultaneously your obligations under this
302 +License and any other pertinent obligations, then as a consequence you
303 +may not distribute the Program at all.  For example, if a patent
304 +license would not permit royalty-free redistribution of the Program by
305 +all those who receive copies directly or indirectly through you, then
306 +the only way you could satisfy both it and this License would be to
307 +refrain entirely from distribution of the Program.
308 +
309 +If any portion of this section is held invalid or unenforceable under
310 +any particular circumstance, the balance of the section is intended to
311 +apply and the section as a whole is intended to apply in other
312 +circumstances.
313 +
314 +It is not the purpose of this section to induce you to infringe any
315 +patents or other property right claims or to contest validity of any
316 +such claims; this section has the sole purpose of protecting the
317 +integrity of the free software distribution system, which is
318 +implemented by public license practices.  Many people have made
319 +generous contributions to the wide range of software distributed
320 +through that system in reliance on consistent application of that
321 +system; it is up to the author/donor to decide if he or she is willing
322 +to distribute software through any other system and a licensee cannot
323 +impose that choice.
324 +
325 +This section is intended to make thoroughly clear what is believed to
326 +be a consequence of the rest of this License.
327 +\f
328 +  8. If the distribution and/or use of the Program is restricted in
329 +certain countries either by patents or by copyrighted interfaces, the
330 +original copyright holder who places the Program under this License
331 +may add an explicit geographical distribution limitation excluding
332 +those countries, so that distribution is permitted only in or among
333 +countries not thus excluded.  In such case, this License incorporates
334 +the limitation as if written in the body of this License.
335 +
336 +  9. The Free Software Foundation may publish revised and/or new versions
337 +of the General Public License from time to time.  Such new versions will
338 +be similar in spirit to the present version, but may differ in detail to
339 +address new problems or concerns.
340 +
341 +Each version is given a distinguishing version number.  If the Program
342 +specifies a version number of this License which applies to it and "any
343 +later version", you have the option of following the terms and conditions
344 +either of that version or of any later version published by the Free
345 +Software Foundation.  If the Program does not specify a version number of
346 +this License, you may choose any version ever published by the Free Software
347 +Foundation.
348 +
349 +  10. If you wish to incorporate parts of the Program into other free
350 +programs whose distribution conditions are different, write to the author
351 +to ask for permission.  For software which is copyrighted by the Free
352 +Software Foundation, write to the Free Software Foundation; we sometimes
353 +make exceptions for this.  Our decision will be guided by the two goals
354 +of preserving the free status of all derivatives of our free software and
355 +of promoting the sharing and reuse of software generally.
356 +
357 +                           NO WARRANTY
358 +
359 +  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
360 +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
361 +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
362 +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
363 +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
364 +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
365 +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
366 +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
367 +REPAIR OR CORRECTION.
368 +
369 +  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
370 +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
371 +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
372 +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
373 +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
374 +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
375 +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
376 +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
377 +POSSIBILITY OF SUCH DAMAGES.
378 +
379 +                    END OF TERMS AND CONDITIONS
380 +\f
381 +           How to Apply These Terms to Your New Programs
382 +
383 +  If you develop a new program, and you want it to be of the greatest
384 +possible use to the public, the best way to achieve this is to make it
385 +free software which everyone can redistribute and change under these terms.
386 +
387 +  To do so, attach the following notices to the program.  It is safest
388 +to attach them to the start of each source file to most effectively
389 +convey the exclusion of warranty; and each file should have at least
390 +the "copyright" line and a pointer to where the full notice is found.
391 +
392 +    <one line to give the program's name and a brief idea of what it does.>
393 +    Copyright (C) <year>  <name of author>
394 +
395 +    This program is free software; you can redistribute it and/or modify
396 +    it under the terms of the GNU General Public License as published by
397 +    the Free Software Foundation; either version 2 of the License, or
398 +    (at your option) any later version.
399 +
400 +    This program is distributed in the hope that it will be useful,
401 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
402 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
403 +    GNU General Public License for more details.
404 +
405 +    You should have received a copy of the GNU General Public License
406 +    along with this program; if not, write to the Free Software
407 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
408 +
409 +
410 +Also add information on how to contact you by electronic and paper mail.
411 +
412 +If the program is interactive, make it output a short notice like this
413 +when it starts in an interactive mode:
414 +
415 +    Gnomovision version 69, Copyright (C) year  name of author
416 +    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
417 +    This is free software, and you are welcome to redistribute it
418 +    under certain conditions; type `show c' for details.
419 +
420 +The hypothetical commands `show w' and `show c' should show the appropriate
421 +parts of the General Public License.  Of course, the commands you use may
422 +be called something other than `show w' and `show c'; they could even be
423 +mouse-clicks or menu items--whatever suits your program.
424 +
425 +You should also get your employer (if you work as a programmer) or your
426 +school, if any, to sign a "copyright disclaimer" for the program, if
427 +necessary.  Here is a sample; alter the names:
428 +
429 +  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
430 +  `Gnomovision' (which makes passes at compilers) written by James Hacker.
431 +
432 +  <signature of Ty Coon>, 1 April 1989
433 +  Ty Coon, President of Vice
434 +
435 +This General Public License does not permit incorporating your program into
436 +proprietary programs.  If your program is a subroutine library, you may
437 +consider it more useful to permit linking proprietary applications with the
438 +library.  If this is what you want to do, use the GNU Library General
439 +Public License instead of this License.
440 diff --git a/base/cgcs-users/cgcs-users-1.0/COPYRIGHT b/base/cgcs-users/cgcs-users-1.0/COPYRIGHT
441 new file mode 100644
442 index 0000000..7507d05
443 --- /dev/null
444 +++ b/base/cgcs-users/cgcs-users-1.0/COPYRIGHT
445 @@ -0,0 +1,17 @@
446 +This file is part of IBSH (Iron Bars Shell) , a restricted Unix shell
447 +Copyright (C) 2005  Attila Nagyidai
448 +
449 +This program is free software; you can redistribute it and/or
450 +modify it under the terms of the GNU General Public License
451 +as published by the Free Software Foundation; either version 2
452 +of the License, or (at your option) any later version.
453 +
454 +This program is distributed in the hope that it will be useful,
455 +but WITHOUT ANY WARRANTY; without even the implied warranty of
456 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
457 +GNU General Public License for more details.
458 +
459 +You should have received a copy of the GNU General Public License
460 +along with this program; if not, write to the Free Software
461 +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
462 +
463 diff --git a/base/cgcs-users/cgcs-users-1.0/INSTALL b/base/cgcs-users/cgcs-users-1.0/INSTALL
464 new file mode 100644
465 index 0000000..42b1866
466 --- /dev/null
467 +++ b/base/cgcs-users/cgcs-users-1.0/INSTALL
468 @@ -0,0 +1,23 @@
469 +Installing ibsh is really easy, so no need for the usual sections
470 +in this document. There is no configure script either, so if 
471 +something wrong, make will fail.
472 +
473 +# make ibsh
474 +# make ibsh_install
475 +
476 +Optionally:
477 +
478 +# make clean
479 +
480 +
481 +To uninstall ibsh:
482 +
483 +# make ibsh_uninstall
484 +
485 +
486 +Of course you will have to enable this shell by:
487 +# echo /bin/ibsh >> /etc/shells
488 +or however you like it.
489 +And make sure the permissions read 0755 !
490 +
491 +2005.03.24.
492 diff --git a/base/cgcs-users/cgcs-users-1.0/Makefile b/base/cgcs-users/cgcs-users-1.0/Makefile
493 new file mode 100644
494 index 0000000..ed37d00
495 --- /dev/null
496 +++ b/base/cgcs-users/cgcs-users-1.0/Makefile
497 @@ -0,0 +1,56 @@
498 +# This is the makefile for ibsh 0.3e
499 +CC = gcc
500 +OBJECTS = main.o command.o jail.o execute.o config.o misc.o antixploit.o delbadfiles.o
501 +
502 +ibsh: ${OBJECTS} ibsh.h
503 +       ${CC} -o ibsh ${OBJECTS}
504 +
505 +main.o: main.c ibsh.h
506 +       ${CC} -c main.c
507 +
508 +command.o: command.c ibsh.h
509 +       ${CC} -c command.c
510 +
511 +jail.o: jail.c ibsh.h
512 +       ${CC} -c jail.c
513 +
514 +execute.o: execute.c ibsh.h
515 +       ${CC} -c execute.c
516 +
517 +config.o: config.c ibsh.h
518 +       ${CC} -c config.c
519 +
520 +misc.o: misc.c ibsh.h
521 +       ${CC} -c misc.c
522 +
523 +antixploit.o: antixploit.c ibsh.h
524 +       ${CC} -c antixploit.c
525 +
526 +delbadfiles.o: delbadfiles.c ibsh.h
527 +       ${CC} -c delbadfiles.c
528 +
529 +ibsh_install:
530 +       cp ./ibsh /bin/
531 +       mkdir /etc/ibsh
532 +       mkdir /etc/ibsh/cmds
533 +       mkdir /etc/ibsh/xtns
534 +       cp ./globals.cmds /etc/ibsh/
535 +       cp ./globals.xtns /etc/ibsh/
536 +
537 +ibsh_uninstall:
538 +       rm -rf /etc/ibsh/globals.cmds
539 +       rm -rf /etc/ibsh/globals.xtns
540 +       rm -rf /etc/ibsh/cmds/*.*
541 +       rm -rf /etc/ibsh/xtns/*.*
542 +       rmdir /etc/ibsh/cmds
543 +       rmdir /etc/ibsh/xtns
544 +       rmdir /etc/ibsh
545 +       rm -rf /bin/ibsh
546 +
547 +clean:
548 +       rm -rf ibsh
549 +       rm -rf *.o
550 +
551 +
552 +# 13:49 2005.04.06.
553 +
554 diff --git a/base/cgcs-users/cgcs-users-1.0/README b/base/cgcs-users/cgcs-users-1.0/README
555 new file mode 100644
556 index 0000000..2035e57
557 --- /dev/null
558 +++ b/base/cgcs-users/cgcs-users-1.0/README
559 @@ -0,0 +1,29 @@
560 +       Iron Bars SHell - a restricted interactive shell.
561 +
562 +Overview
563 +
564 +       For long i have been in the search of a decent restricted shell, but in vain.
565 +       The few i found, were really easy to hack, and there were quite a few docs
566 +       around on the web about hacking restricted shells with a menu interface.
567 +       For my definitions, a restricted shell must not only prevent the user to 
568 +       escape her jail, but also not to access any files outside the jail.
569 +       The system administrator must have total control over the restricted shell.
570 +       These are the major features incorporated and realized by ibsh.
571 +
572 +
573 +Features
574 +
575 +       Please read the changelog.      
576 +
577 +
578 +Installation
579 +
580 +       Read the INSTALL file.
581 +
582 +
583 +Contact
584 +       See Authors file.
585 +
586 +
587 +Attila Nagyidai
588 +2005.05.23.
589 diff --git a/base/cgcs-users/cgcs-users-1.0/Release b/base/cgcs-users/cgcs-users-1.0/Release
590 new file mode 100644
591 index 0000000..e6cb9f3
592 --- /dev/null
593 +++ b/base/cgcs-users/cgcs-users-1.0/Release
594 @@ -0,0 +1,17 @@
595 +This release introduces minor bugfixes, and important new and renewed features.
596 +Erasing evil files in the home directory of the user is incorporated again, with 
597 +many improvements. First of all: no file will be erased! Only the access to them
598 +will be blocked. The extension policy has changed, now ibsh blocks those extensions,
599 +that are NOT listed. This goes in sync with the usual method of operation of ibsh.
600 +The execute permission of files in the user space, will be removed.
601 +New customizing features were added: each user now can have her own commands and 
602 +extensions file, created and maintained by the system administrator. Some users
603 +(employees) may require access to special programs. User configuration files allow
604 +this access only those, who need it, not for everybody.
605 +Ibsh now scans not only the extensions of files, but the content too! Whatever the permission
606 +for a certain file exists, if that contains source code, or is a linux binary, access
607 +will be blocked.
608 +The absolute path for the users is now limited to 255 characters. Longer, already
609 +existing filenames will be renamed.
610 +
611 +06/04/2005 
612 diff --git a/base/cgcs-users/cgcs-users-1.0/TODO b/base/cgcs-users/cgcs-users-1.0/TODO
613 new file mode 100644
614 index 0000000..9a8de60
615 --- /dev/null
616 +++ b/base/cgcs-users/cgcs-users-1.0/TODO
617 @@ -0,0 +1,10 @@
618 +TODO
619 +
620 +       - tab completion.
621 +       - shell variables.
622 +       - some changes to the prompt, maybe variable prompt.
623 +       - history
624 +       - to be able to use corporate, or other large/complicated programs in a safe
625 +       working environment, yet be able to share files/work with others.
626 +
627 +2005.05.23.
628 diff --git a/base/cgcs-users/cgcs-users-1.0/VERSION b/base/cgcs-users/cgcs-users-1.0/VERSION
629 new file mode 100644
630 index 0000000..aaf9552
631 --- /dev/null
632 +++ b/base/cgcs-users/cgcs-users-1.0/VERSION
633 @@ -0,0 +1 @@
634 +IBSH v0.3e
635 diff --git a/base/cgcs-users/cgcs-users-1.0/antixploit.c b/base/cgcs-users/cgcs-users-1.0/antixploit.c
636 new file mode 100644
637 index 0000000..79ac9e4
638 --- /dev/null
639 +++ b/base/cgcs-users/cgcs-users-1.0/antixploit.c
640 @@ -0,0 +1,131 @@
641 +/*
642 +  Created: 03.19.05 11:34:57 by Attila Nagyidai
643 +
644 +  $Id: C\040Console.c,v 1.1.2.1 2003/08/13 00:38:46 neum Exp $
645 +
646 +  This file is part of IBSH (Iron Bars Shell) , a restricted Unix shell
647 +  Copyright (C) 2005  Attila Nagyidai
648 +
649 +  This program is free software; you can redistribute it and/or
650 +  modify it under the terms of the GNU General Public License
651 +  as published by the Free Software Foundation; either version 2
652 +  of the License, or (at your option) any later version.
653 +
654 +  This program is distributed in the hope that it will be useful,
655 +  but WITHOUT ANY WARRANTY; without even the implied warranty of
656 +  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
657 +  GNU General Public License for more details.
658 +
659 +  You should have received a copy of the GNU General Public License
660 +  along with this program; if not, write to the Free Software
661 +  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
662 +
663 +  Author: Attila Nagyidai
664 +  Email: na@ent.hu
665 +
666 +  Co-Author: Shy
667 +  Email: shy@cpan.org
668 +
669 +  Co-Author: Witzy
670 +  Email: stazzz@altern.org
671 +  
672 +  URL: http://ibsh.sourceforge.net
673 +  IRC: irc.freenode.net #ibsh
674 +  RSS, Statistics, etc: http://sourceforge.net/projects/ibsh/
675 +
676 +*/
677 +
678 +/* Header files */
679 +#include "ibsh.h"
680 +
681 +
682 +void lshift( char *line )
683 +{
684 +  int i = 0;
685 +  
686 +  for (i=0; i<strlen(line) - 1; i++) {
687 +      line[i] = line[i+1];
688 +  }
689 +}
690 +
691 +
692 +/* Checks if a part of the command line contains */
693 +/* a file in the jail, that is a source code. */
694 +/* Source codes must not be compiled, interpreted, */
695 +/* or otherwise used. */
696 +/* abspath is loggedin.udir, if the token is a path. */
697 +/* otherwise abspath is realpath. */
698 +int antixploit( const char *abspath, char *token )
699 +{
700 +  char jailfile[STRING_SIZE], line[LINE_SIZE], temp[BUFFER_SIZE];
701 +  struct stat info;
702 +  FILE *fp;
703 +  int retval = 0;
704 +
705 +  
706 +  snprintf(jailfile, STRING_SIZE, "%s/%s/%s", loggedin.udir, abspath, token);
707 +#ifdef DEBUG
708 +  printf("jailfile: %s\n", jailfile);
709 +#endif
710 +  if ( (lstat(jailfile, &info)) == -1 ) {
711 +      // this is not a file
712 +      return 0;
713 +  }
714 +
715 +  fp = fopen(jailfile, "rb");
716 +  if ( fp == NULL ) {
717 +      // if i cant open it, gcc cant open it
718 +      return 0;
719 +  }
720 +
721 +  fgets(line, LINE_SIZE, fp);
722 +  while ( line[0] != '\0' ) {
723 +#ifdef DEBUG
724 +      printf("Line: %s\n", line);
725 +#endif
726 +      // c, c++
727 +      if ( (strncmp(line, C_CODE, strlen(C_CODE) - 1)) == 0 ) {
728 +          retval = 1;
729 +          break;
730 +      }
731 +      // perl, sh, python
732 +      if ( (strncmp(line, SHELL_CODE, strlen(SHELL_CODE) - 1)) == 0 ) {
733 +          retval = 1;
734 +          break;
735 +      }
736 +      // python
737 +      if ( (strncmp(line, PYTHON_CODE, strlen(PYTHON_CODE) - 1)) == 0 ) {
738 +          retval = 1;
739 +          break;
740 +      }
741 +      // ada
742 +      if ( (strncmp(line, ADA_CODE, strlen(ADA_CODE) - 1)) == 0 ) {
743 +          retval = 1;
744 +          break;
745 +      }
746 +      // eiffel
747 +      if ( (strncmp(line, EIFFEL_CODE, strlen(EIFFEL_CODE) - 1)) == 0 ) {
748 +          retval = 1;
749 +          break;
750 +      }
751 +      // lisp
752 +      if ( (strncmp(line, LISP_CODE, strlen(LISP_CODE) - 1)) == 0 ) {
753 +          retval = 1;
754 +          break;
755 +      }
756 +      // elf
757 +      lshift(line);
758 +      if ( (strncmp(line, ELF_CODE, strlen(ELF_CODE) - 1)) == 0 ) {
759 +          retval = 1;
760 +          break;
761 +      }
762 +      bzero(line, LINE_SIZE);
763 +      fgets(line, LINE_SIZE, fp);
764 +  }
765 +  fclose(fp);
766 +#ifdef DEBUG
767 +  printf("retval: %d\n", retval);
768 +#endif
769 +  return retval;
770 +}
771 +
772 diff --git a/base/cgcs-users/cgcs-users-1.0/command.c b/base/cgcs-users/cgcs-users-1.0/command.c
773 new file mode 100644
774 index 0000000..91d9d8f
775 --- /dev/null
776 +++ b/base/cgcs-users/cgcs-users-1.0/command.c
777 @@ -0,0 +1,209 @@
778 +/*
779 +  Created: 03.19.05 11:34:57 by Attila Nagyidai
780 +
781 +  $Id: C\040Console.c,v 1.1.2.1 2003/08/13 00:38:46 neum Exp $
782 +
783 +  This file is part of IBSH (Iron Bars Shell) , a restricted Unix shell
784 +  Copyright (C) 2005  Attila Nagyidai
785 +
786 +  This program is free software; you can redistribute it and/or
787 +  modify it under the terms of the GNU General Public License
788 +  as published by the Free Software Foundation; either version 2
789 +  of the License, or (at your option) any later version.
790 +
791 +  This program is distributed in the hope that it will be useful,
792 +  but WITHOUT ANY WARRANTY; without even the implied warranty of
793 +  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
794 +  GNU General Public License for more details.
795 +
796 +  You should have received a copy of the GNU General Public License
797 +  along with this program; if not, write to the Free Software
798 +  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
799 +
800 +  Author: Attila Nagyidai
801 +  Email: na@ent.hu
802 +
803 +  Co-Author: Shy
804 +  Email: shy@cpan.org
805 +
806 +  Co-Author: Witzy
807 +  Email: stazzz@altern.org
808 +  
809 +  URL: http://ibsh.sourceforge.net
810 +  IRC: irc.freenode.net #ibsh
811 +  RSS, Statistics, etc: http://sourceforge.net/projects/ibsh/
812 +
813 +*/
814 +
815 +/* Header files */
816 +#include "ibsh.h"
817 +
818 +extern Strng commands[MAX_ITEMS];
819 +
820 +/* This is my version of scanf. It offers good protection against */
821 +/* buffer overflow attacks. */
822 +/* Technical Description: */
823 +/* Variables: the char to read to from stdin, the sum of chars typed in, */
824 +/* and an integer for length checking. */
825 +/* Read characters from stdin in a loop, until Enter is pressed. */
826 +/* The line size check wont stop accepting characters, but it will */
827 +/* break long commands to LINE_SIZEd pieces. */
828 +/* Update: */
829 +/* Read only 80 characters. If the current path + this 80 chars + / */
830 +/* are longer then 255, read less chars. */
831 +void myscanf( char *vptr, char *abspath )
832 +{
833 +    int c;
834 +               char chars[STRING_SIZE];
835 +    int i = 0, j = 0;
836 +    int linesize = LINE_SIZE;
837 +
838 +               fflush(stdin);
839 +    if ( (strlen(abspath)) > (255 - 80 - 1) ) {
840 +        linesize = 255 - strlen(abspath) - 1; /* thats for the / */
841 +    }
842 +
843 +    while ( ((c = getchar()) != 10) && ( i < linesize ) ) {
844 +                               //printf("%d", c);
845 +                               if  (c > 127) {
846 +                                                c = 0;
847 +                                               //ungetc(c, stdin);
848 +                                               //fflush(stdin);
849 +                                               break;
850 +                               }
851 +             if ( c < 0 ) {
852 +                 ungetc(c, stdin);
853 +                 openlog("ibsh", LOG_PID, LOG_AUTH);
854 +            syslog(LOG_INFO, "user %s has logged out.", loggedin.uname);
855 +            closelog();
856 +            exit(0);
857 +             }
858 +        chars[i] = c;
859 +        /* the user is not allowed to pass long lines of trash to ibsh */
860 +        i++;
861 +    }
862 +    chars[i] = '\0';
863 +   strncpy(vptr,chars,STRING_SIZE-1);
864 +   vptr[STRING_SIZE-1] = '\0';
865 +}
866 +
867 +
868 +/* Checks, if the user command, is blacklisted, a hack attempt, */
869 +/* or it is a real and allowed command. */
870 +/* Technical Description: */
871 +/* Variables: pointer for the strtok, temporary strings, counters, */
872 +/* and an integer to check, how deep is the user in the jail. That is */
873 +/* the level of subdirectories below jail root. It is set to -1, because */
874 +/* there is always a / in the jailpath. So only subdir /'s are counted. */
875 +/* Check if the command contains special characters, if yes, quit. */
876 +/* If the user is in jailroot, a ../ is not appropriate! */
877 +/* Count the slashes in the jailpath, so if the user uses way too many */
878 +/* ../ 's, then we will know. Split the command to particles by the spaces. */
879 +/* Count the dirups (../); if a token starts with a /, paste the homedir path */
880 +/* right in front of it. Thats your root booby, not / !!!! */
881 +/* Finally check the command against the COMMANDS_LIST. */
882 +int CommandOK( const char *thecommand, const char *rootdir,
883 +const char *jailpath, char *newcommand )
884 +{
885 +  char *tok;
886 +  char temp1[STRING_SIZE], *temp2;
887 +  int i = 0, j = 0;
888 +  int subdirlevel = -1; /* jailpath always starts with a / */
889 +  int dirupfound = 0;
890 +  int listed = 0;
891 +
892 +  /* First, get the fancy stuff: */
893 +  /* ../ out of the jailroot, too many ../ out of some */
894 +  /* subdirectory in the jail, multiple commands, pipes. */
895 +  bzero(newcommand,STRING_SIZE);
896 +
897 +  if ( (strstr(thecommand, ";")) != NULL ) {
898 +      return 0;
899 +  }
900 +  if ( (strstr(thecommand, "|")) != NULL ) {
901 +      return 0;
902 +  }
903 +  if ( (strstr(thecommand, "&")) != NULL ) {
904 +      return 0;
905 +  }
906 +  if ( (strstr(thecommand, "&&")) != NULL ) {
907 +      return 0;
908 +  }
909 +  if ( (strstr(thecommand, "||")) != NULL ) {
910 +      return 0;
911 +  }
912 +  /* The user is in the jailroot. */
913 +  if ( (strcmp(jailpath, "/")) == 0 ) {
914 +      /* Does the user wish to get out ? */
915 +      if ( (strstr(thecommand, "..")) != NULL ) {
916 +             return 0;
917 +      }
918 +  }
919 +  /* The user is deeper, than the jailroot, and */
920 +  /* this is a problem. How deep is he, how many */
921 +  /* ../ do we allow ?? */
922 +  else {
923 +      for (i = 0; i < strlen(jailpath); i++) {
924 +          if ( jailpath[i] == '/' ) {
925 +              subdirlevel++;
926 +          }
927 +      }
928 +  }
929 +
930 +  /* Split the command */
931 +  for (tok = strtok((void *) thecommand, " "); tok; tok = strtok(0, " ")) {
932 +      /* Separate parts of the command with a space */
933 +      if ( (strlen(newcommand)) > 0 ) {
934 +          strncat(newcommand," ", STRING_SIZE-strlen(newcommand)-1);
935 +      }
936 +      
937 +      /* He wants to get to the real root, does he ? */
938 +      /* In that case, add the jailroot to the left. */
939 +      if ( tok[0] == '/' ) {
940 +        strncat(newcommand,rootdir,STRING_SIZE-strlen(newcommand)-1);
941 +       }
942 +
943 +      /* how many ../ are here */
944 +      /* if too many, that is more, then how deep */
945 +      /* the user in the subdirs inside the jail is, */
946 +      /* cancel the execution of the command. */
947 +      if ( (strstr(tok, "../")) != NULL ) {
948 +        strncpy(temp1,tok,sizeof(temp1)-1);
949 +        temp1[sizeof(temp1)-1] = '\0';
950 +       
951 +       while (1) {
952 +              temp2 = strstr(temp1, "../");
953 +              if ( temp2 == NULL ) {
954 +                  break;
955 +              }
956 +              LTrim3(temp2, temp1);
957 +              dirupfound++;
958 +          }
959 +          if ( dirupfound > subdirlevel ) {
960 +              return 0;
961 +          }
962 +          /* replace dirups with real path */
963 +          for (i = 0; i < dirupfound; i++) {
964 +              PathMinusOne(jailpath, tok, subdirlevel,sizeof(tok));
965 +          }
966 +      }
967 +          /* if command is not listed, return 0 */
968 +      i = 0;
969 +      while ( ((strlen(commands[i])) > 0) && ( j == 0 ) ) {
970 +       if ( (strcmp(tok, commands[i])) == 0 ) {
971 +                listed = 1;
972 +                break;
973 +          }
974 +          i++;
975 +      }
976 +      j++;
977 +      strncat(newcommand,tok,STRING_SIZE-strlen(newcommand)-1);
978
979 +}
980 +#ifdef DEBUG
981 +  printf("old: %s; new: %s; ok: %d\n", thecommand, newcommand, listed);
982 +#endif
983 +  return listed;
984 +}
985 +
986 +
987 diff --git a/base/cgcs-users/cgcs-users-1.0/config.c b/base/cgcs-users/cgcs-users-1.0/config.c
988 new file mode 100644
989 index 0000000..8e2af23
990 --- /dev/null
991 +++ b/base/cgcs-users/cgcs-users-1.0/config.c
992 @@ -0,0 +1,179 @@
993 +/*
994 +  Created: 03.19.05 11:34:57 by Attila Nagyidai
995 +
996 +  $Id: C\040Console.c,v 1.1.2.1 2003/08/13 00:38:46 neum Exp $
997 +
998 +  This file is part of IBSH (Iron Bars Shell) , a restricted Unix shell
999 +  Copyright (C) 2005  Attila Nagyidai
1000 +
1001 +  Copyright(c) 2013-2017 Wind River Systems, Inc. All rights reserved.
1002 +
1003 +  This program is free software; you can redistribute it and/or
1004 +  modify it under the terms of the GNU General Public License
1005 +  as published by the Free Software Foundation; either version 2
1006 +  of the License, or (at your option) any later version.
1007 +
1008 +  This program is distributed in the hope that it will be useful,
1009 +  but WITHOUT ANY WARRANTY; without even the implied warranty of
1010 +  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1011 +  GNU General Public License for more details.
1012 +
1013 +  You should have received a copy of the GNU General Public License
1014 +  along with this program; if not, write to the Free Software
1015 +  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
1016 +
1017 +  Author: Attila Nagyidai
1018 +  Email: na@ent.hu
1019 +
1020 +  Co-Author: Shy
1021 +  Email: shy@cpan.org
1022 +
1023 +  Co-Author: Witzy
1024 +  Email: stazzz@altern.org
1025 +  
1026 +  URL: http://ibsh.sourceforge.net
1027 +  IRC: irc.freenode.net #ibsh
1028 +  RSS, Statistics, etc: http://sourceforge.net/projects/ibsh/
1029 +
1030 +*/
1031 +
1032 +/* Header files */
1033 +#include "ibsh.h"
1034 +
1035 +extern Strng commands[MAX_ITEMS];
1036 +extern Strng extensions[MAX_ITEMS];
1037 +
1038 +/* Shy's improved version of the original (and not well working) loadconfig. */
1039 +/* Reads both config files, and parses the contents into arrays. */
1040 +/* This one effectively dismisses every comment from the files. */
1041 +/* Technical Description: */
1042 +/* Variables: file pointer, counters, temporary string arrays. */
1043 +/* The method is the same for both files. First open the file, catch */
1044 +/* any errors. Read file 'til eof. Not read comments (starting with '#'), */
1045 +/* remove trailing newline character. Copy the finished item to the */
1046 +/* pass-by-address arguments. */
1047 +int LoadConfig( void )
1048 +{
1049 +  FILE *fp;
1050 +  int i = 0;
1051 +  char *file_user;
1052 +  
1053 +  Strng tmp[MAX_ITEMS];
1054 +  Strng tmp2[MAX_ITEMS];
1055 +
1056 +  /* COMMAND CONFIG !!!! */
1057 +  file_user = (char *)malloc(strlen(loggedin.uname) + strlen(COMMANDS_DIR) + strlen(".cmds") + 2);
1058 +
1059 +  if(loggedin.uname != NULL)
1060 +       sprintf(file_user, "%s/%s.cmds", COMMANDS_DIR, loggedin.uname);
1061 +  else{
1062 +         free(file_user);
1063 +         return -1;
1064 +  }
1065 +
1066 +  /* Open global config,if not present go out !!! */
1067 +  if((fp = fopen(COMMANDS_FILE,"r")) == NULL) {
1068 +      OPENLOG;
1069 +      syslog(LOG_ERR, "ibsh panic! Global commands file %s can not be read.", COMMANDS_FILE);
1070 +      CLOSELOG;
1071 +      exit(0);
1072 +  }
1073 +
1074 +  while (!feof(fp) && (i<MAX_ITEMS)) {
1075 +        fgets(tmp[i],STRING_SIZE,fp);
1076 +        if ( tmp[i][0] != '#' ) {
1077 +                /* Delete '\n' */
1078 +                tmp[i][strlen(tmp[i]) - 1] = '\0';
1079 +                strncpy(commands[i],tmp[i],strlen(tmp[i]));
1080 +       
1081 +#ifdef DEBUG
1082 +                printf("COMMANDS %s\n",commands[i]);
1083 +#endif
1084 +               i++;
1085 +      }
1086 +  }
1087 +  fclose(fp);
1088 +
1089 +
1090 +#ifdef DEBUG
1091 +  printf("FILE USER %s\n",file_user);
1092 +#endif
1093 +  /* Add the user command */
1094 +  if ((fp = fopen(file_user,"r")) == NULL) {
1095 +             free(file_user);
1096 +       }
1097 +  else {
1098 +  i--;
1099 +  
1100 +  while (!feof(fp) && (i<MAX_ITEMS)) {
1101 +        fgets(tmp[i],STRING_SIZE,fp);
1102 +        if ( tmp[i][0] != '#' ) {
1103 +                // Delete '\n'
1104 +                tmp[i][strlen(tmp[i]) - 1] = '\0';
1105 +                strncpy(commands[i],tmp[i],strlen(tmp[i]));
1106 +#ifdef DEBUG
1107 +                printf("COMMANDS %s\n",commands[i]);
1108 +#endif
1109 +
1110 +               i++;
1111 +      }
1112 +  }
1113 +  fclose(fp);
1114 +  free(file_user);
1115 +  }
1116 +
1117 +  i = 0;
1118 +  
1119 +  /* EXTENSIONS CONFIG !!!!*/
1120 +  
1121 +  file_user = (char *)malloc(strlen(loggedin.uname) + strlen(EXTENSIONS_DIR) + strlen(".xtns") + 2);
1122 +  
1123 +  sprintf(file_user, "%s/%s.xtns", EXTENSIONS_DIR, loggedin.uname);
1124 +
1125 +    /* Open global config,if not present go out !!! */
1126 +  if((fp = fopen(EXTENSIONS_FILE,"r")) == NULL) {
1127 +      OPENLOG;
1128 +      syslog(LOG_ERR, "ibsh panic! Global extensions file %s can not be read.", EXTENSIONS_FILE);
1129 +      CLOSELOG;
1130 +      printf("heyxtns");
1131 +      exit(0);
1132 +  }
1133 +
1134 +  while (!feof(fp) && (i<MAX_ITEMS)) {
1135 +    fgets(tmp2[i],STRING_SIZE,fp);
1136 +        if ( tmp2[i][0] != '#' ) {
1137 +                /* Delete '\n' */
1138 +                tmp2[i][strlen(tmp2[i]) - 1] = '\0';
1139 +                strncpy(extensions[i],tmp2[i],strlen(tmp2[i]));
1140 +#ifdef DEBUG
1141 +                printf("EXTENSIONS %s\n",extensions[i]);
1142 +#endif
1143 +               i++;
1144 +      }
1145 +  }
1146 +  fclose(fp);
1147 +
1148 +  
1149 +  /* Add the user extensions */
1150 +  if ((fp = fopen(file_user,"r")) == NULL) {
1151 +             free(file_user);
1152 +             return 0;
1153 +       }
1154 +
1155 +  i--;
1156 +  
1157 +  while (!feof(fp) && (i<MAX_ITEMS)) {
1158 +        fgets(tmp2[i],STRING_SIZE,fp);
1159 +        if ( tmp2[i][0] != '#' ) {
1160 +                // Delete '\n'
1161 +                tmp2[i][strlen(tmp2[i]) - 1] = '\0';
1162 +                strncpy(extensions[i],tmp2[i],strlen(tmp2[i]));
1163 +               i++;
1164 +      }
1165 +  }
1166 +  fclose(fp);
1167 +  free(file_user);
1168 +  
1169 +  return 0;
1170 +}
1171 +
1172 diff --git a/base/cgcs-users/cgcs-users-1.0/delbadfiles.c b/base/cgcs-users/cgcs-users-1.0/delbadfiles.c
1173 new file mode 100644
1174 index 0000000..fc09f4b
1175 --- /dev/null
1176 +++ b/base/cgcs-users/cgcs-users-1.0/delbadfiles.c
1177 @@ -0,0 +1,239 @@
1178 +/*
1179 +  Created: 03.19.05 11:34:57 by Attila Nagyidai
1180 +
1181 +  $Id: C\040Console.c,v 1.1.2.1 2003/08/13 00:38:46 neum Exp $
1182 +
1183 +  This file is part of IBSH (Iron Bars Shell) , a restricted Unix shell
1184 +  Copyright (C) 2005  Attila Nagyidai
1185 +
1186 +  This program is free software; you can redistribute it and/or
1187 +  modify it under the terms of the GNU General Public License
1188 +  as published by the Free Software Foundation; either version 2
1189 +  of the License, or (at your option) any later version.
1190 +
1191 +  This program is distributed in the hope that it will be useful,
1192 +  but WITHOUT ANY WARRANTY; without even the implied warranty of
1193 +  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1194 +  GNU General Public License for more details.
1195 +
1196 +  You should have received a copy of the GNU General Public License
1197 +  along with this program; if not, write to the Free Software
1198 +  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
1199 +
1200 +  Author: Attila Nagyidai
1201 +  Email: na@ent.hu
1202 +
1203 +  Co-Author: Shy
1204 +  Email: shy@cpan.org
1205 +
1206 +  Co-Author: Witzy
1207 +  Email: stazzz@altern.org
1208 +  
1209 +  URL: http://ibsh.sourceforge.net
1210 +  IRC: irc.freenode.net #ibsh
1211 +  RSS, Statistics, etc: http://sourceforge.net/projects/ibsh/
1212 +
1213 +*/
1214 +
1215 +/* Header files */
1216 +#include "ibsh.h"
1217 +
1218 +extern Strng extensions[MAX_ITEMS];
1219 +
1220 +/* witzy's fix of the DelBadFiles function, making it work and adding features.
1221 +   It drops rights of the files which don't end with an extension present into the extensions array,
1222 +   deletes symbolic links pointing out of the jail, and makes unexecutable the files that are executable.
1223 +   A message is printed each time such a file is found, explaining what was done.
1224 +   Don't forget that this function chdirs to the path given into parameter, so when DelBadFiles returns,
1225 +   your current working directory is this path.
1226 +*/
1227 +void DelBadFiles (const char *basedir)
1228 +{
1229 +  DIR *dp;
1230 +  struct dirent *list;
1231 +  struct stat info, attr;
1232 +  char tmp[STRING_SIZE];
1233 +  int i, allowed;
1234 +
1235 +  strncpy(tmp, basedir, STRING_SIZE - 1);
1236 +  if ( lstat( tmp, &info ) == -1 ) {
1237 +      return;
1238 +  }
1239 +
1240 +  if ( !S_ISDIR(info.st_mode) ) {
1241 +      return;
1242 +  }
1243 +
1244 +  if ( (dp = opendir(tmp)) == NULL ) {
1245 +           closedir( dp );
1246 +      return;
1247 +  }
1248 +
1249 +  if ( chdir(tmp) == -1 ) {
1250 +      return;
1251 +  }
1252 +
1253 +  while ( (list = readdir(dp)) != NULL ) {
1254 +#ifdef DEBUG
1255 +    printf("direntry: %s\n", list->d_name);
1256 +#endif
1257 +    if ( (lstat(list->d_name, &attr)) < 0 )
1258 +      continue;
1259 +    
1260 +    // rename long path names
1261 +#ifdef DEBUG
1262 +    printf("length: %d;\n", (strlen(basedir) + strlen(list->d_name) + 2) );
1263 +#endif
1264 +    if ( (strlen(basedir) + strlen(list->d_name) + 2) > 255 ) {
1265 +      snprintf(tmp, 255 - strlen(basedir) - 2, "%s", list->d_name);
1266 +      rename(list->d_name, tmp);
1267 +#ifdef DEBUG
1268 +      printf("%s renamed to %s !\n", list->d_name, tmp);
1269 +#endif
1270 +      if ( (antixploit(basedir, tmp)) == 1 ) {
1271 +       removeAllRights(list->d_name, &attr);
1272 +      }
1273 +      if (isExecutable(&attr)) {
1274 +       makeUnexecutable(tmp, &attr);
1275 +      }
1276 +      continue;
1277 +    }
1278 +
1279 +    if ( S_ISDIR(attr.st_mode) ) { /* in the case of a directory */
1280 +      if ( ((strcmp(list->d_name, ".")) != 0) && ((strcmp(list->d_name, "..")) != 0) ) {
1281 +#ifdef DEBUG
1282 +       printf("recursive call for %s\n", list->d_name);
1283 +#endif
1284 +       DelBadFiles(list->d_name); /* recursively look for bad files in this directory */
1285 +       chdir ("..");
1286 +      }
1287 +    } else if ( S_ISLNK(attr.st_mode) ) { /* in the case of a symlink */
1288 +      if ( symlinkGoesOuttaJail(list->d_name) ) {
1289 +#ifdef DEBUG
1290 +       printf("symlinkoutofjail: %s\n", list->d_name);
1291 +#endif
1292 +       if (unlink(list->d_name) == 0) {
1293 +         bzero (tmp, sizeof(tmp));
1294 +         snprintf (tmp, sizeof(tmp)-1, "Illegal symbolic link %s was erased. Contact the sysadmin for policy.\n", list->d_name);
1295 +         logPrintBadfile (tmp);
1296 +       }
1297 +      }
1298 +    } else if (hasSomeRwxRights(&attr)) { /* other cases (in particular a file), only if there are some rights on it */
1299 +#ifdef DEBUG
1300 +      printf("%s has some rights\n", list->d_name);
1301 +#endif
1302 +      /* check the runnability of the file */
1303 +      if (isExecutable(&attr)) {
1304 +#ifdef DEBUG
1305 +       printf("%s executable\n", list->d_name);
1306 +#endif
1307 +       if (makeUnexecutable(list->d_name, &attr) == 0) {
1308 +         bzero (tmp, sizeof(tmp));
1309 +         snprintf (tmp, sizeof(tmp)-1, "Executable file %s is not anymore. Contact the sysadmin for policy.\n", list->d_name);
1310 +         logPrintBadfile (tmp);
1311 +       }
1312 +      }
1313 +      
1314 +      if ( (antixploit(basedir, list->d_name)) == 1 ) {
1315 +       if (removeAllRights(list->d_name, &attr) == 0) {
1316 +         bzero (tmp, sizeof(tmp));
1317 +         snprintf (tmp, sizeof(tmp)-1, "Illegal file %s got its rights dropped. Contact the sysadmin for policy.\n", list->d_name);
1318 +         logPrintBadfile (tmp);
1319 +         continue;
1320 +       }
1321 +      }
1322 +      
1323 +      /* check if the file has a permitted extension */
1324 +      for (i = 0, allowed = 0; (strlen(extensions[i])) > 0 && !allowed; i++) {
1325 +       if ( (strstr(list->d_name, extensions[i])) != NULL ) {
1326 +#ifdef DEBUG
1327 +         printf("filename: %s; extension: %s\n", list->d_name, extensions[i]);
1328 +#endif
1329 +         allowed = 1;
1330 +       }
1331 +      } /* for */
1332 +      if (!allowed) { /* if the file hasn't an allowed extension */
1333 +#ifdef DEBUG
1334 +       printf("not allowed extension for %s\n", list->d_name);
1335 +#endif
1336 +       if (removeAllRights(list->d_name, &attr) == 0) {
1337 +         bzero (tmp, sizeof(tmp));
1338 +         snprintf (tmp, sizeof(tmp)-1, "Illegal file %s got its rights dropped. Contact the sysadmin for policy.\n", list->d_name);
1339 +         logPrintBadfile (tmp);
1340 +       }
1341 +      }
1342 +    } /* else */
1343 +
1344 +  } /* while */
1345 +  
1346 +  closedir( dp );
1347 +}
1348 +
1349 +/* takes a symlink location, resolves it and returns :
1350 +   1 if the symlink points out of the jail
1351 +   0 else, meaning the symlink is ok
1352 +*/
1353 +int symlinkGoesOuttaJail (const char * sl)
1354 +{
1355 +  char fPnted[PATH_MAX];
1356 +  char rslvdPath[PATH_MAX]; /* size of PATH_MAX because of realpath() behavior */
1357 +  int i;
1358 +  
1359 +  i = readlink (sl, fPnted, PATH_MAX);
1360 +  if ( i > 0 && i < PATH_MAX ) {
1361 +    fPnted[i] = '\0';
1362 +    if (realpath (fPnted, rslvdPath) == rslvdPath) {
1363 +      if ( strncmp (loggedin.udir, rslvdPath, strlen(loggedin.udir)) == 0 )
1364 +       return 0;
1365 +      else
1366 +       return 1;
1367 +    }
1368 +  }
1369 +  return 1; /* if this line is reached, there was a problem with the processing of the symlink, 
1370 +              e.g. the path is too long, so we should consider that the symlink is bad, 
1371 +              and may be deleted by the calling function */
1372 +}
1373 +
1374 +/* takes a stat structure, and returns
1375 +   1 if at least one of the user/group/other execution bits or suid/guid are set
1376 +   0 if no such bit is set at all
1377 + */
1378 +int isExecutable (struct stat * s)
1379 +{
1380 +  if ( ((s->st_mode & S_IXUSR) == S_IXUSR)
1381 +       | ((s->st_mode & S_IXGRP) == S_IXGRP)
1382 +       | ((s->st_mode & S_IXOTH) == S_IXOTH)
1383 +       | ((s->st_mode & S_ISUID) == S_ISUID)
1384 +       | ((s->st_mode & S_ISGID) == S_ISGID) )
1385 +    return 1;
1386 +  return 0;
1387 +}
1388 +
1389 +int hasSomeRwxRights (struct stat * s)
1390 +{
1391 +  if ( ((s->st_mode & S_IRWXU) != 0)
1392 +       | ((s->st_mode & S_IRWXG) != 0)
1393 +       | ((s->st_mode & S_IRWXO) != 0) )
1394 +    return 1;
1395 +  return 0;
1396 +}
1397 +
1398 +int makeUnexecutable (const char * filename, struct stat * s)
1399 +{
1400 +  return chmod (filename,
1401 +               s->st_mode & ~(S_IXUSR | S_IXGRP | S_IXOTH | S_ISUID | S_ISGID) );
1402 +}
1403 +
1404 +int removeAllRights (const char * filename, struct stat * s)
1405 +{
1406 +  return chmod (filename, 
1407 +               s->st_mode & ~(S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID) );
1408 +}
1409 +
1410 +void logPrintBadfile (const char * msg)
1411 +{
1412 +  OPENLOG;
1413 +  syslog(LOG_WARNING, "%s", msg);
1414 +  CLOSELOG;
1415 +  //  printf ("ibsh: %s\n", msg);
1416 +}
1417 diff --git a/base/cgcs-users/cgcs-users-1.0/example.allowall.xtns b/base/cgcs-users/cgcs-users-1.0/example.allowall.xtns
1418 new file mode 100644
1419 index 0000000..d0963cd
1420 --- /dev/null
1421 +++ b/base/cgcs-users/cgcs-users-1.0/example.allowall.xtns
1422 @@ -0,0 +1,28 @@
1423 +# Add any extension the user may use.
1424 +q
1425 +w
1426 +e
1427 +r
1428 +t
1429 +y
1430 +u
1431 +i
1432 +o
1433 +p
1434 +a
1435 +s
1436 +d
1437 +f
1438 +g
1439 +h
1440 +j
1441 +k
1442 +l
1443 +z
1444 +x
1445 +c
1446 +v
1447 +b
1448 +n
1449 +m
1450 +
1451 diff --git a/base/cgcs-users/cgcs-users-1.0/example.denyall.xtns b/base/cgcs-users/cgcs-users-1.0/example.denyall.xtns
1452 new file mode 100644
1453 index 0000000..9dead3a
1454 --- /dev/null
1455 +++ b/base/cgcs-users/cgcs-users-1.0/example.denyall.xtns
1456 @@ -0,0 +1,2 @@
1457 +# Add any extension the user may use.
1458 +
1459 diff --git a/base/cgcs-users/cgcs-users-1.0/execute.c b/base/cgcs-users/cgcs-users-1.0/execute.c
1460 new file mode 100644
1461 index 0000000..2d80366
1462 --- /dev/null
1463 +++ b/base/cgcs-users/cgcs-users-1.0/execute.c
1464 @@ -0,0 +1,159 @@
1465 +/*
1466 +  Created: 03.19.05 11:34:57 by Attila Nagyidai
1467 +
1468 +  $Id: C\040Console.c,v 1.1.2.1 2003/08/13 00:38:46 neum Exp $
1469 +
1470 +  This file is part of IBSH (Iron Bars Shell) , a restricted Unix shell
1471 +  Copyright (C) 2005  Attila Nagyidai
1472 +
1473 +  This program is free software; you can redistribute it and/or
1474 +  modify it under the terms of the GNU General Public License
1475 +  as published by the Free Software Foundation; either version 2
1476 +  of the License, or (at your option) any later version.
1477 +
1478 +  This program is distributed in the hope that it will be useful,
1479 +  but WITHOUT ANY WARRANTY; without even the implied warranty of
1480 +  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1481 +  GNU General Public License for more details.
1482 +
1483 +  You should have received a copy of the GNU General Public License
1484 +  along with this program; if not, write to the Free Software
1485 +  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
1486 +
1487 +  Author: Attila Nagyidai
1488 +  Email: na@ent.hu
1489 +
1490 +  Co-Author: Shy
1491 +  Email: shy@cpan.org
1492 +
1493 +  Co-Author: Witzy
1494 +  Email: stazzz@altern.org
1495 +  
1496 +  URL: http://ibsh.sourceforge.net
1497 +  IRC: irc.freenode.net #ibsh
1498 +  RSS, Statistics, etc: http://sourceforge.net/projects/ibsh/
1499 +
1500 +*/
1501 +
1502 +/* Header files */
1503 +#include "ibsh.h"
1504 +
1505 +/* Counts the spaces in the command */
1506 +int nbspace(const char *command)
1507 +{
1508 +int i=0;
1509 +int nbspace=0;
1510 +
1511 +while(command[i] != '\0'){
1512 +       if(command[i] == ' ')
1513 +               nbspace++;
1514 +       i++;
1515 +}
1516 +
1517 +return nbspace;
1518 +}
1519 +
1520 +/* Shy's improved and secured version of hhsystem, originally taken from */
1521 +/* the book: Linux Unix Systemprogramming by Helmut Herold. */
1522 +int  hhsystem(const char *user_command)   /*--- Version ohne Signalbehandlung ---*/
1523 +{
1524 +   pid_t   pid;
1525 +   int     status;
1526 +   int i=0;
1527 +   int find = 0;
1528 +
1529 +   char *field;
1530 +
1531 +   char path[STRING_SIZE];
1532 +
1533 +   char *current_path;
1534 +   char *fieldspath;
1535 +   char *params[nbspace(user_command) + 1];
1536 +
1537 +   DIR *currentdir;
1538 +   struct dirent *pdirent;
1539 +
1540 +   if (user_command == NULL)
1541 +      return(1);   /* In Unix ist immer Kommandoprozessor vorhanden */
1542 +
1543 +   if ( (pid=fork()) < 0)
1544 +      status = -1;
1545 +
1546 +   else if (pid == 0) {
1547 +        /* Split the command */
1548 +       field = strtok((char *)user_command," ");
1549 +       while(field != NULL){
1550 +#ifdef DEBUG
1551 +               printf("CHAMPS %s\n",field);
1552 +#endif
1553 +               params[i] = malloc(strlen(field) + 1);
1554 +               bzero(params[i],strlen(field)+1);
1555 +               strncpy(params[i],field,strlen(field));
1556 +               i++;
1557 +               field = strtok(NULL," ");
1558 +
1559 +       }
1560 +       /* Put NULL at the end for execve */
1561 +       params[i] = NULL;
1562 +
1563 +       /* Get PATH */
1564 +       current_path = getenv("PATH");
1565 +
1566 +#ifdef DEBUG
1567 +       printf("PATH %s %s\n",current_path,loggedin.udir);
1568 +#endif
1569 +
1570 +       /* Parse the PATH if the command is in the home dir it's skip !! */
1571 +        fieldspath = strtok((char *)current_path,":");
1572 +               while((fieldspath != NULL) && find != 1){
1573 +#ifdef DEBUG
1574 +                       printf("FIELD PATH %s\n",fieldspath);
1575 +#endif
1576 +                       if(!strstr(fieldspath,loggedin.udir)){
1577 +                               if((currentdir = opendir(fieldspath)) != NULL){
1578 +
1579 +                                       while(((pdirent = readdir(currentdir)) != NULL) && find != 1){
1580 +                                               if(!strncmp(pdirent->d_name,params[0],sizeof(params[0]))){
1581 +#ifdef DEBUG
1582 +                                               printf("TROUVE %s!!!!\n",pdirent->d_name);
1583 +#endif
1584 +                                               find = 1;
1585 +
1586 +                                       }
1587 +                               }
1588 +                       }
1589 +                               closedir(currentdir);
1590 +                       }
1591 +                       if(find == 0)
1592 +                               fieldspath = strtok(NULL,":");
1593 +                       
1594 +               }
1595 +
1596 +       /* Contruct the real command with the good path */
1597 +       if(find == 1 && ((strlen(fieldspath)+strlen(params[0])+1) < sizeof(path))){
1598 +               bzero(path,sizeof(path));
1599 +               snprintf(path,sizeof(path)-1,"%s/%s",fieldspath,params[0]);
1600 +               path[sizeof(path)-1] = '\0';
1601 +
1602 +#ifdef DEBUG
1603 +    printf("PATH FINAL %s %d ok!\n",path,strlen(path));
1604 +               printf("PARAMS[0] %s\n",params[0]);
1605 +               printf("PARAMS[1] %s\n",params[1]);
1606 +#endif
1607 +               execve(path,params,environ);
1608 +       }
1609 +       /* The command is in the home dir :( bad for you guys !! */
1610 +       else{
1611 +               status = -1;
1612 +       }
1613 +       _exit(127);
1614 +
1615 +   } else
1616 +      while (waitpid(pid, &status, 0) < 0)
1617 +         if (errno != EINTR) {
1618 +            status = -1;
1619 +            break;
1620 +         }
1621 +
1622 +   return(status);
1623 +}
1624 diff --git a/base/cgcs-users/cgcs-users-1.0/globals.cmds b/base/cgcs-users/cgcs-users-1.0/globals.cmds
1625 new file mode 100644
1626 index 0000000..8c9b7a4
1627 --- /dev/null
1628 +++ b/base/cgcs-users/cgcs-users-1.0/globals.cmds
1629 @@ -0,0 +1,8 @@
1630 +# Add any commands the user may execute. Even shell commands.
1631 +# You have to allow logout and/or exit, so the user can logout!
1632 +# cd and pwd should also be allowed. Note: other shell builtin
1633 +# commands are not yet implemented!
1634 +cd
1635 +pwd
1636 +logout
1637 +exit
1638 diff --git a/base/cgcs-users/cgcs-users-1.0/globals.xtns b/base/cgcs-users/cgcs-users-1.0/globals.xtns
1639 new file mode 100644
1640 index 0000000..71f86f8
1641 --- /dev/null
1642 +++ b/base/cgcs-users/cgcs-users-1.0/globals.xtns
1643 @@ -0,0 +1,3 @@
1644 +# Add any extension the user may use.
1645 +.doc
1646 +.txt
1647 diff --git a/base/cgcs-users/cgcs-users-1.0/ibsh.h b/base/cgcs-users/cgcs-users-1.0/ibsh.h
1648 new file mode 100644
1649 index 0000000..9d9d692
1650 --- /dev/null
1651 +++ b/base/cgcs-users/cgcs-users-1.0/ibsh.h
1652 @@ -0,0 +1,126 @@
1653 +/*
1654 +  Created: 03.19.05 11:15:21 by Attila Nagyidai
1655 +
1656 +  $Id: C\040Header.h,v 1.1.2.1 2003/08/13 00:38:46 neum Exp $
1657 +
1658 +  This file is part of IBSH (Iron Bars Shell) , a restricted Unix shell
1659 +  Copyright (C) 2005  Attila Nagyidai
1660 +
1661 +  This program is free software; you can redistribute it and/or
1662 +  modify it under the terms of the GNU General Public License
1663 +  as published by the Free Software Foundation; either version 2
1664 +  of the License, or (at your option) any later version.
1665 +
1666 +  This program is distributed in the hope that it will be useful,
1667 +  but WITHOUT ANY WARRANTY; without even the implied warranty of
1668 +  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1669 +  GNU General Public License for more details.
1670 +
1671 +  You should have received a copy of the GNU General Public License
1672 +  along with this program; if not, write to the Free Software
1673 +  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
1674 +
1675 +  Author: Attila Nagyidai
1676 +  Email: na@ent.hu
1677 +
1678 +  Co-Author: Shy
1679 +  Email: shy@cpan.org
1680 +
1681 +  URL: http://ibsh.sourceforge.net
1682 +  IRC: irc.freenode.net #ibsh
1683 +  RSS, Statistics, etc: http://sourceforge.net/projects/ibsh/
1684 +
1685 +*/
1686 +
1687 +#ifndef _IBSH_H
1688 +#define _IBSH_H
1689 +
1690 +/* Insert Code here */
1691 +#include <stdio.h>
1692 +#include <stdlib.h>
1693 +#include <string.h>
1694 +#include <time.h>
1695 +#include <unistd.h>
1696 +#include <sys/types.h>
1697 +#include <sys/stat.h>
1698 +#include <sys/wait.h>
1699 +#include <syslog.h>
1700 +#include <fcntl.h>
1701 +#include <errno.h>
1702 +#include <dirent.h>
1703 +#include <pwd.h>
1704 +#include <grp.h>
1705 +#include <limits.h>
1706 +#include <glob.h>
1707 +#include <signal.h>
1708 +
1709 +#define PAM_SIZE    8
1710 +#define LINE_SIZE   80
1711 +#define STRING_SIZE 255
1712 +#define BUFFER_SIZE 4096
1713 +#define PATH_MAX 4096
1714 +#define MAX_ITEMS   50
1715 +#define COMMANDS_DIR "/etc/ibsh/cmds"
1716 +#define COMMANDS_FILE "/etc/ibsh/globals.cmds"
1717 +#define EXTENSIONS_DIR "/etc/ibsh/xtns"
1718 +#define EXTENSIONS_FILE "/etc/ibsh/globals.xtns"
1719 +
1720 +/* Antixploit */
1721 +#define C_CODE  "#include"
1722 +#define SHELL_CODE  "#!/"
1723 +#define PYTHON_CODE "import"
1724 +#define ADA_CODE  "package body"
1725 +#define EIFFEL_CODE "feature --"
1726 +#define LISP_CODE "(defun"
1727 +#define ELF_CODE "ELF"
1728 +
1729 +/* Logging */
1730 +#define OPENLOG     openlog("ibsh", LOG_PID, LOG_AUTH)
1731 +#define CLOSELOG    closelog()
1732 +
1733 +/* Typedefs, structs, globals */
1734 +typedef struct theuser {
1735 +    char uname[STRING_SIZE];
1736 +    uid_t uid;
1737 +    char udir[STRING_SIZE];
1738 +    struct passwd *record;
1739 +} theuser;
1740 +
1741 +typedef char Strng[STRING_SIZE];
1742 +
1743 +theuser loggedin; /* user info */
1744 +
1745 +//static Strng commands[MAX_ITEMS];  /* permitted commands */
1746 +Strng commands[MAX_ITEMS];
1747 +Strng extensions[MAX_ITEMS];
1748 +/*static Strng extensions[MAX_ITEMS];   permitted extensions */
1749 +char real_path[STRING_SIZE];    /* absolute path */
1750 +char jail_path[STRING_SIZE];    /* path inside the jail */
1751 +char user_command[STRING_SIZE];   /* whatever the user types */
1752 +char filtered_command[STRING_SIZE]; /* this one will be executed */
1753 +int exitcode;
1754 +extern char **environ;
1755 +
1756 +
1757 +int CommandOK( const char *thecommand, const char *rootdir,
1758 +const char *jailpath, char *newcommand );
1759 +void LTrim3( const char *base, char *result );
1760 +void GetPositionInJail( const char *abspath, const char *rootdir, char *relpath );
1761 +int LoadConfig( void );
1762 +void myscanf( char *vptr, char *abspath );
1763 +int  hhsystem(const char *kdozeile);
1764 +void PathMinusOne( const char *basepath, char *evalpath, int slashcount,size_t nevalpath);
1765 +void log_attempt( const char *username );
1766 +int nbspace(const char *command);
1767 +void lshift( char *line );
1768 +int antixploit( const char *abspath, char *token );
1769 +void logPrintBadfile (const char * msg);
1770 +int removeAllRights (const char * filename, struct stat * s);
1771 +int makeUnexecutable (const char * filename, struct stat * s);
1772 +int hasSomeRwxRights (struct stat * s);
1773 +int isExecutable (struct stat * s);
1774 +int symlinkGoesOuttaJail (const char * sl);
1775 +void DelBadFiles (const char *basedir);
1776 +
1777 +
1778 +#endif /* _IBSH_H */
1779 diff --git a/base/cgcs-users/cgcs-users-1.0/jail.c b/base/cgcs-users/cgcs-users-1.0/jail.c
1780 new file mode 100644
1781 index 0000000..ab3300a
1782 --- /dev/null
1783 +++ b/base/cgcs-users/cgcs-users-1.0/jail.c
1784 @@ -0,0 +1,101 @@
1785 +/*
1786 +  Created: 03.19.05 11:34:57 by Attila Nagyidai
1787 +
1788 +  $Id: C\040Console.c,v 1.1.2.1 2003/08/13 00:38:46 neum Exp $
1789 +
1790 +  This file is part of IBSH (Iron Bars Shell) , a restricted Unix shell
1791 +  Copyright (C) 2005  Attila Nagyidai
1792 +
1793 +  This program is free software; you can redistribute it and/or
1794 +  modify it under the terms of the GNU General Public License
1795 +  as published by the Free Software Foundation; either version 2
1796 +  of the License, or (at your option) any later version.
1797 +
1798 +  This program is distributed in the hope that it will be useful,
1799 +  but WITHOUT ANY WARRANTY; without even the implied warranty of
1800 +  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1801 +  GNU General Public License for more details.
1802 +
1803 +  You should have received a copy of the GNU General Public License
1804 +  along with this program; if not, write to the Free Software
1805 +  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
1806 +
1807 +  Author: Attila Nagyidai
1808 +  Email: na@ent.hu
1809 +
1810 +  Co-Author: Shy
1811 +  Email: shy@cpan.org
1812 +
1813 +  Co-Author: Witzy
1814 +  Email: stazzz@altern.org
1815 +  
1816 +  URL: http://ibsh.sourceforge.net
1817 +  IRC: irc.freenode.net #ibsh
1818 +  RSS, Statistics, etc: http://sourceforge.net/projects/ibsh/
1819 +
1820 +*/
1821 +
1822 +/* Header files */
1823 +#include "ibsh.h"
1824 +
1825 +
1826 +
1827 +/* Remove the path of the Jail root dir from the displayed paths! */
1828 +/* Return the jail path from the absolute path. */
1829 +/* Copy characters from absolute path to jail path, starting, where the */
1830 +/* jail root ends. */
1831 +void GetPositionInJail( const char *abspath, const char *rootdir, char *relpath )
1832 +{
1833 +  int i = 0;
1834 +  int j = 0;
1835 +  
1836 +  bzero(relpath, strlen(relpath));
1837 +  for (i = strlen(rootdir); i < strlen(abspath); i++) {
1838 +      relpath[j] = abspath[i];
1839 +      j++;
1840 +  }
1841 +  relpath[j] = '\0';
1842 +}
1843 +
1844 +/* Take 3 characters from left off a string. */
1845 +/* It practically removes one ../ . */
1846 +void LTrim3( const char *base, char *result )
1847 +{
1848 +  int i = 0;
1849 +  int j = 0;
1850 +
1851 +  bzero(result, strlen(result));
1852 +  for (i = 3; i < strlen(base); i++) {
1853 +      result[j] = base[i];
1854 +      j++;
1855 +  }
1856 +  result[j] = '\0';
1857 +}
1858 +
1859 +/* Remove one subdirectory from the path in the argument. */
1860 +/* In case the user uses ../ 's in his command. */
1861 +/* Technical Description: */
1862 +/* Variables: string pointer for the strtok function, and an */
1863 +/* integer to stop the removing. */
1864 +/* Disassemble the path by the slashes. And glue the required parts */
1865 +/* together. Number of required parts = number of all parts - 1 . */
1866 +void PathMinusOne( const char *basepath, char *evalpath, int slashcount,size_t nevalpath )
1867 +{
1868 +  char *tok;
1869 +  int j = 1;
1870 +  
1871 +  bzero(evalpath, strlen(evalpath));
1872 +  if ( slashcount == 1 ) {
1873 +      strncpy(evalpath,"/",nevalpath-1);
1874 +      evalpath[nevalpath-1] = '\0';
1875 +  }
1876 +  else {
1877 +      for (tok = strtok((void *) basepath, "/"); tok; tok = strtok(0, "/")) {
1878 +          if ( j < slashcount ) {
1879 +              strncat(evalpath,tok,nevalpath-strlen(evalpath)-1);
1880 +               strncat(evalpath,"/",nevalpath-strlen(evalpath)-1);
1881 +          }
1882 +          j++;
1883 +      }
1884 +  }
1885 +}
1886 diff --git a/base/cgcs-users/cgcs-users-1.0/main.c b/base/cgcs-users/cgcs-users-1.0/main.c
1887 new file mode 100644
1888 index 0000000..1d92899
1889 --- /dev/null
1890 +++ b/base/cgcs-users/cgcs-users-1.0/main.c
1891 @@ -0,0 +1,239 @@
1892 +/*
1893 +  Created: 03.19.05 11:34:57 by Attila Nagyidai
1894 +
1895 +  $Id: C\040Console.c,v 1.1.2.1 2003/08/13 00:38:46 neum Exp $
1896 +
1897 +  This file is part of IBSH (Iron Bars Shell) , a restricted Unix shell
1898 +  Copyright (C) 2005  Attila Nagyidai
1899 +
1900 +  Copyright(c) 2013-2017 Wind River Systems, Inc. All rights reserved.
1901 +
1902 +  This program is free software; you can redistribute it and/or
1903 +  modify it under the terms of the GNU General Public License
1904 +  as published by the Free Software Foundation; either version 2
1905 +  of the License, or (at your option) any later version.
1906 +
1907 +  This program is distributed in the hope that it will be useful,
1908 +  but WITHOUT ANY WARRANTY; without even the implied warranty of
1909 +  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1910 +  GNU General Public License for more details.
1911 +
1912 +  You should have received a copy of the GNU General Public License
1913 +  along with this program; if not, write to the Free Software
1914 +  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
1915 +
1916 +  Author: Attila Nagyidai
1917 +  Email: na@ent.hu
1918 +
1919 +  Co-Author: Shy
1920 +  Email: shy@cpan.org
1921 +
1922 +  Co-Author: Witzy
1923 +  Email: stazzz@altern.org
1924 +  
1925 +  URL: http://ibsh.sourceforge.net
1926 +  IRC: irc.freenode.net #ibsh
1927 +  RSS, Statistics, etc: http://sourceforge.net/projects/ibsh/
1928 +
1929 +*/
1930 +
1931 +/* Header files */
1932 +#include "ibsh.h"
1933 +#include "stdlib.h"
1934 +
1935 +/* Main: */
1936 +/* Handle arguments, read config files, start command processing. */
1937 +/* IBSH doesnt use any command line arguments, but my text editor */
1938 +/* uses this code in all new c files to create. And i didnt have the */
1939 +/* heart to remove it. ;p */
1940 +/* Technical Description: */
1941 +/* Get the passwd entry for the user. The uid is easily aquired, since */
1942 +/* it is the real user id. After that, grab the passwd file entry upon */
1943 +/* the id, and copy the information to the loggedin struct. */
1944 +/* Add some signal handlers too. */
1945 +/* The infinite loop: */
1946 +/* Get the current directory, the full path. Compute the jailpath from that, */
1947 +/* that is the directories below the users homedir, which is the jail root. */
1948 +/* The jail ceiling if you like. Print some prompt to the user with the jailpath, */
1949 +/* and read stdin for incoming commands. Filter out the bad commands, typos, the */
1950 +/* not allowed commands. It the command is ok, execute it. If it is a shell builtin, */
1951 +/* use our builtin code, otherwise use execve. After execve, check if the user didnt */
1952 +/* use the last command to create some illegal content. If yes, erase that. Give the */
1953 +/* notice only afterwards. */
1954 +
1955 +void ALRMhandler(int sig) {
1956 +    OPENLOG;
1957 +    syslog(LOG_INFO, "CLI timeout, user %s has logged out.", loggedin.uname);
1958 +    CLOSELOG;
1959 +    exit(0);
1960 +}
1961 +
1962 +int main(int argc, char **argv)
1963 +{
1964 +  char temp[STRING_SIZE], *buf;
1965 +  struct stat info;
1966 +  uid_t ruid, euid;
1967 +  gid_t rgid, egid;
1968 +  unsigned int tout_cli = 0;
1969 +
1970 +  const char* tout = getenv("TMOUT");
1971 +  if (tout)
1972 +    tout_cli = atoi(tout);
1973 +  else
1974 +    //default to 5 mins
1975 +    tout_cli = 300;
1976 +
1977 +  /* setuid protection */
1978 +  ruid = getuid();
1979 +  euid = geteuid();
1980 +  rgid = getgid();
1981 +  egid = getegid();
1982 +  if ( (ruid!=euid) || (ruid==0) || (euid==0) || (rgid!=egid) || (rgid==0) || (egid==0) ) {
1983 +      OPENLOG;
1984 +      syslog(LOG_ERR, "setuid/setgid violation!");
1985 +      CLOSELOG;
1986 +      printf("ibsh: setuid/setgid violation!! exiting...\n");
1987 +#ifdef DEBUG
1988 +      printf("ruid: %d;euid: %d;rgid: %d;egid: %d\n", ruid,euid,rgid,egid);
1989 +#endif
1990 +      exit(0);
1991 +  }
1992 +
1993 +  /* To Do: The code of your application goes here */
1994 +  /* First part: */
1995 +  /* Get essential information about the user who got this shell: */
1996 +  /* first the username, then the user id. Upon this, retrieve the */
1997 +  /* user's record in the passwd file. */
1998 +  bzero(&loggedin, sizeof(loggedin));
1999 +  loggedin.uid = getuid();
2000 +  loggedin.record = getpwuid(loggedin.uid);
2001 +  if ( loggedin.record == NULL ) {
2002 +      loggedin.record = getpwnam(loggedin.uname);
2003 +      if ( loggedin.record == NULL ) {
2004 +          openlog(loggedin.uname, LOG_PID, LOG_AUTH);
2005 +          syslog(LOG_ERR, "Can not obtain user information");
2006 +          closelog();
2007 +          exit(0);
2008 +      }
2009 +  }
2010 +  strncpy(loggedin.uname, loggedin.record->pw_name, PAM_SIZE);
2011 +  strncpy(loggedin.udir, loggedin.record->pw_dir, STRING_SIZE);
2012 +
2013 +  /* Second part: */
2014 +  /* Handle some signal catching. Read the configuration files. */
2015 +  signal( SIGINT, SIG_IGN );
2016 +  signal( SIGQUIT, SIG_IGN );
2017 +  signal( SIGTERM, SIG_IGN );
2018 +  signal( SIGTSTP, SIG_IGN );
2019 +  signal( SIGALRM, ALRMhandler );
2020 +  LoadConfig();
2021 +
2022 +  /* Command mode */
2023 +  if(argc == 3) {
2024 +      if ( argv[1][1] == 'c' ) {
2025 +          if ( CommandOK(argv[2], loggedin.udir, "/", filtered_command) == 1) {
2026 +                exitcode = hhsystem(filtered_command);
2027 +                OPENLOG;
2028 +                syslog(LOG_INFO, "command %s ordered, command %s has been executed.",
2029 +                argv[2], filtered_command);
2030 +                CLOSELOG;
2031 +                exit(exitcode);
2032 +          }
2033 +          exit(0);
2034 +      }
2035 +      else {
2036 +        exit(0);
2037 +      }
2038 +  }
2039 +
2040 +  OPENLOG;
2041 +  syslog(LOG_INFO, "user %s has logged in.", loggedin.uname);
2042 +  CLOSELOG;
2043 +
2044 +
2045 +  DelBadFiles(loggedin.udir);
2046 +  chdir (loggedin.udir);
2047 +
2048 +
2049 +  /* Third part: */
2050 +  /* Start reading and processing the user issued commands. */
2051 +  /* Split the command by the spaces, filter out anything, */
2052 +  /* that would allow the user to access files outside the */
2053 +  /* jail. Filter out multiples and pipes as well. No program */
2054 +  /* will be allowed to run, unless it is mentioned in the */
2055 +  /* config files. Files that are created with an extension */
2056 +  /* that is listed in the other config file, must be deleted! */
2057 +  alarm(tout_cli);
2058 +  for ( ; ; ) {
2059 +    /* Where is he ? */
2060 +    getcwd(real_path, STRING_SIZE);
2061 +    GetPositionInJail(real_path, loggedin.udir, jail_path);
2062 +    if ( (strlen(jail_path)) == 0 ) {
2063 +        strncpy(jail_path, "/", 2);
2064 +    }
2065 +    /* We don't want the user to know where he actually is. */
2066 +    /* This is the prompt! */
2067 +    printf("[%s]%% ", loggedin.uname);
2068 +    /* scanf("%s", user_command); */
2069 +    myscanf(user_command, real_path);
2070 +    alarm(tout_cli);
2071 +    /* Command interpretation and execution. */
2072 +    if ( (CommandOK(user_command, loggedin.udir, jail_path, filtered_command)) == 0 ) {
2073 +        log_attempt(loggedin.uname);  /* v0.2a */
2074 +        continue;
2075 +    }
2076 +    /* If the user issued command starts with a shell builtin. */
2077 +    bzero(temp, strlen(temp));
2078 +    if ( (buf = strstr(filtered_command, "cd")) != NULL ) {
2079 +      if ( (strcmp(buf, filtered_command)) == 0 ) {
2080 +          LTrim3(filtered_command, temp);
2081 +          if ( (strcmp(temp, real_path)) != 0 ) {
2082 +            if ( (strcmp(temp, "..")) == 0 ) {
2083 +                PathMinusOne(jail_path, temp, 1,sizeof(temp));
2084 +            }
2085 +            if ( (strcmp(temp, "/")) == 0 ) {
2086 +                strncpy(temp, loggedin.udir, LINE_SIZE);
2087 +            }
2088 +            exitcode = chdir(temp);
2089 +            if ( exitcode == -1 ) {
2090 +                printf("ibsh: cd: %s: No such file or directory\n", temp);
2091 +            }
2092 +          }
2093 +          continue;
2094 +      }
2095 +    }
2096 +    else if ( (buf = strstr(filtered_command, "pwd")) != NULL ) {
2097 +     if ( (strcmp(buf, filtered_command)) == 0 ) {
2098 +          printf("%s\n", jail_path);
2099 +          continue;
2100 +      }
2101 +    }
2102 +    else if ( (buf = strstr(filtered_command, "logout")) != NULL ) {
2103 +      if ( (strcmp(buf, filtered_command)) == 0 ) {
2104 +          OPENLOG;
2105 +          syslog(LOG_INFO, "user %s has logged out.", loggedin.uname);
2106 +          CLOSELOG;
2107 +          break;
2108 +      }
2109 +    }
2110 +    else if ( (buf = strstr(filtered_command, "exit")) != NULL ) {
2111 +      if ( (strcmp(buf, filtered_command)) == 0 ) {
2112 +          OPENLOG;
2113 +          syslog(LOG_INFO, "user %s has logged out.", loggedin.uname);
2114 +          CLOSELOG;
2115 +          break;
2116 +      }
2117 +    }
2118 +    else {
2119 +        exitcode = hhsystem(filtered_command);
2120 +        if ( exitcode < 0 ) {
2121 +            printf("%s\n", strerror(errno));
2122 +        }
2123 +    }
2124 +    getcwd(real_path, STRING_SIZE);
2125 +    DelBadFiles(loggedin.udir);
2126 +    chdir (real_path);
2127 +  }
2128 +  return 0;
2129 +}
2130 +
2131 diff --git a/base/cgcs-users/cgcs-users-1.0/misc.c b/base/cgcs-users/cgcs-users-1.0/misc.c
2132 new file mode 100644
2133 index 0000000..d73ddb8
2134 --- /dev/null
2135 +++ b/base/cgcs-users/cgcs-users-1.0/misc.c
2136 @@ -0,0 +1,52 @@
2137 +/*
2138 +  Created: 03.19.05 11:34:57 by Attila Nagyidai
2139 +
2140 +  $Id: C\040Console.c,v 1.1.2.1 2003/08/13 00:38:46 neum Exp $
2141 +
2142 +  This file is part of IBSH (Iron Bars Shell) , a restricted Unix shell
2143 +  Copyright (C) 2005  Attila Nagyidai
2144 +
2145 +  This program is free software; you can redistribute it and/or
2146 +  modify it under the terms of the GNU General Public License
2147 +  as published by the Free Software Foundation; either version 2
2148 +  of the License, or (at your option) any later version.
2149 +
2150 +  This program is distributed in the hope that it will be useful,
2151 +  but WITHOUT ANY WARRANTY; without even the implied warranty of
2152 +  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2153 +  GNU General Public License for more details.
2154 +
2155 +  You should have received a copy of the GNU General Public License
2156 +  along with this program; if not, write to the Free Software
2157 +  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
2158 +
2159 +  Author: Attila Nagyidai
2160 +  Email: na@ent.hu
2161 +
2162 +  Co-Author: Shy
2163 +  Email: shy@cpan.org
2164 +
2165 +  Co-Author: Witzy
2166 +  Email: stazzz@altern.org
2167 +  
2168 +  URL: http://ibsh.sourceforge.net
2169 +  IRC: irc.freenode.net #ibsh
2170 +  RSS, Statistics, etc: http://sourceforge.net/projects/ibsh/
2171 +
2172 +*/
2173 +
2174 +/* Header files */
2175 +#include "ibsh.h"
2176 +
2177 +/* If the command is not ok, there is a possible hack attempt. */
2178 +/* Can also be a typo, but we're not taking any chances. v0.2a */
2179 +void log_attempt( const char *username )
2180 +{
2181 +  char logmsg[STRING_SIZE];
2182 +
2183 +  snprintf(logmsg, 50, "Possible hack attempt by %s.", username);
2184 +  
2185 +  OPENLOG;
2186 +  syslog(LOG_WARNING, "%s", logmsg);
2187 +  CLOSELOG;
2188 +}
2189 -- 
2190 2.17.1
2191