aboutsummaryrefslogtreecommitdiff
path: root/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre
diff options
context:
space:
mode:
Diffstat (limited to 'riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre')
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/CHANGES5
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/COPYING339
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/Makefile103
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/README22
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/Version2
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/__end_parse.c10
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/__parse_feed.c14
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/__parse_getline.c14
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/__parse_split.c15
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/__prepare_parse.c22
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/byte_copy.c6
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/byte_diff.c11
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/byte_set.c7
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/byte_zero.c4
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/config.h54
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/faillog_do.c70
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/fmt_ulong.c10
-rwxr-xr-xriemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/get_headers25
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/get_tz.c42
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/lastlog_do.c43
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/log_do.c21
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/md5.c177
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/md5.h21
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/md5crypt.c140
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nlogin-auth.c125
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nlogin-tiny.c175
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nlogin.c129
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_ctime.c41
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getgrent.c37
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getgrgid.c11
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getgrnam.c11
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getgrouplist.c33
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getpwent.c44
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getpwgid.c11
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getpwnam.c11
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getpwuid.c11
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getspent.c47
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getspnam.c11
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_initgroups.c11
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/parselib.h10
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/pass_check.c20
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/prot_uidgid.c11
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/read_password.c15
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/safe_io.c21
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/scan_uid.c14
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/scan_ulong.c8
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/str_add.c5
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/str_copy.c5
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/str_copynz.c7
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/str_diff.c4
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/str_diffn.c13
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/str_len.c5
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/str_lib.c6
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/str_mycat.c9
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/utmp_do.c53
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/utmp_io.c30
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/write_devlog.c16
57 files changed, 2137 insertions, 0 deletions
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/CHANGES b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/CHANGES
new file mode 100644
index 0000000..b9e06b3
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/CHANGES
@@ -0,0 +1,5 @@
+added ~/.hushlogin checking for /etc/motd
+added /var/log/faillog support
+
+added nlogin-tiny
+
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/COPYING b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/COPYING
new file mode 100644
index 0000000..d511905
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/COPYING
@@ -0,0 +1,339 @@
+ 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.
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/Makefile b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/Makefile
new file mode 100644
index 0000000..be7a581
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/Makefile
@@ -0,0 +1,103 @@
+SHELL=/bin/sh
+
+CC=gcc
+CFLAGS=-O2 -Wall -W
+LDFLAGS=-s
+
+CCC = $(CC) $(CFLAGS)
+CCL = $(CC) $(CFLAGS) $(LDFLAGS)
+STR = strip -R .comment -R .note
+
+ALL = nlogin nlogin-auth nlogin-tiny
+
+default: $(ALL)
+
+nlogin: nlogin.c lib.a
+ ${CCL} -o $@ $^
+ @$(STR) $@
+nlogin-%: nlogin-%.c lib.a
+ ${CCL} -o $@ $^
+ @$(STR) $@
+clean:
+ rm -f $(ALL) *.o *.a *.s a.out *_defs.h
+
+install: $(ALL)
+ install -d $(DESTDIR)/bin
+ install -m755 $^ $(DESTDIR)/bin
+
+g_h = ./get_headers
+
+%_defs.h: %_*.c
+ $(g_h) $@ -Gsys/types.h $^ > $@
+str_defs.h: str_*.c
+ $(g_h) $@ -Lbyte_defs.h -Lfmt_defs.h -Lscan_defs.h $^ > $@
+time_defs.h: get_tz.c nv_ctime.c write_dev*.c
+ $(g_h) $@ -Lstr_defs.h $^ > $@
+parse_defs.h: __*.c
+ $(g_h) $@ -Lstr_defs.h $^ > $@
+utmp_defs.h: utmp_*.c safe_io.c log_do.c lastlog_do.c
+ $(g_h) $@ -Ltime_defs.h $^ > $@
+prot_defs.h: prot_*.c read_pass*.c pass_check.c
+ $(g_h) $@ -Gsys/types.h -Lmd5.h $^ > $@
+md5_defs.h: md5*.c
+ $(g_h) $@ $^ > $@
+pw_%_defs.h: nv_*%*.c
+ $(g_h) $@ $^ > $@
+pw_defs.h:
+ $(g_h) $@ -Lstr_defs.h -Lpw_pw_defs.h -Lpw_gr_defs.h \
+ -Lpw_sp_defs.h $^ > $@
+
+%.o: %.c config.h
+ ${CCC} -c $<
+
+STR_O = $(patsubst %.c,%.o,$(wildcard str_*.c))
+BYTE_O = $(patsubst %.c,%.o,$(wildcard byte_*.c))
+SCAN_O = $(patsubst %.c,%.o,$(wildcard scan_*.c))
+FMT_O = $(patsubst %.c,%.o,$(wildcard fmt_*.c))
+PARSE_O = $(patsubst %.c,%.o,$(wildcard __*.c))
+UTMP_O = $(patsubst %.c,%.o,$(wildcard *_io.c *_do.c *_devlog.c))
+TIME_O = $(patsubst %.c,%.o,$(wildcard *ctime.c *_tz.c))
+PASS_O = $(patsubst %.c,%.o,$(wildcard *pass*.c prot_*.c))
+MD5_O = $(patsubst %.c,%.o,$(wildcard md5*.c))
+PW_PW_O = $(patsubst %.c,%.o,$(wildcard nv_*pw*.c))
+PW_GR_O = $(patsubst %.c,%.o,$(wildcard nv_*gr*.c))
+PW_SP_O = $(patsubst %.c,%.o,$(wildcard nv_*sp*.c))
+PW_O = $(PW_PW_O) $(PW_GR_O) $(PW_SP_O)
+
+str_%.o: str_defs.h
+fmt_%.o: fmt_defs.h
+scan_%.o: scan_defs.h
+byte_%.o: byte_defs.h
+nv_%gr%.o: pw_gr_defs.h
+nv_%pw%.o: pw_pw_defs.h
+nv_%sp%.o: pw_sp_defs.h
+md5%.o: md5_defs.h
+__%.o: parse_defs.h
+
+ALL_O = $(STR_O) $(BYTE_O) $(SCAN_O) $(FMT_O) $(PARSE_O) $(PW_O) \
+ $(PASS_O) $(MD5_O) $(UTMP_O) $(TIME_O)
+
+ALL_H = str_defs.h byte_defs.h scan_defs.h fmt_defs.h parse_defs.h \
+ pw_defs.h pw_pw_defs.h pw_gr_defs.h pw_sp_defs.h \
+ utmp_defs.h time_defs.h prot_defs.h md5_defs.h
+
+lib.a: $(ALL_H) $(ALL_O)
+ ar cr lib.a $(ALL_O)
+
+MYARCH:=$(shell uname -m | sed -e 's/i[4-9]86/i386/' -e 's/armv[3-6]t\?e\?[lb]/arm/')
+dietlibc/bin-$(MYARCH)/diet:
+ cvs -d :pserver:[email protected]:/cvs -z9 co dietlibc
+ cd dietlibc && make
+dietbuild: dietlibc/bin-$(MYARCH)/diet
+ DIETHOME=$(CURDIR)/dietlibc make \
+ CC="$(CURDIR)/$< -Os gcc -nostdinc -I$(CURDIR)/dietlibc/include"
+
+TAR=tar
+TAR_OPT=
+MY_NAME=$(notdir $(CURDIR))
+tar:
+ cd .. && $(TAR) -cvzf $(MY_NAME).tar.gz $(TAR_OPT) \
+ --owner=root --group=root --exclude dietlibc $(MY_NAME)
+packit:
+ ( echo $(MY_NAME); date -u -R ) > Version
+ make clean tar TAR=tar.f TAR_OPT=--sort
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/README b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/README
new file mode 100644
index 0000000..3c5f3c9
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/README
@@ -0,0 +1,22 @@
+http://riemann.fmi.uni-sofia.bg/programs/
+This is the login which I wrote for me.
+
+Build:
+ make
+
+ To compile with dietlibc use
+ make CC='diet -Os gcc -nostdinc'
+
+ It's possible to use also
+ make dietbuild
+
+Install:
+ make install
+ or
+ cp nlogin /bin/
+ cp nlogin-tiny /bin/
+ cp nlogin-auth /bin/nlogin-auth <-- do not change the location !!!
+
+Look also the file config.h included here.
+
+Enjoy, Nikola Vladov
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/Version b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/Version
new file mode 100644
index 0000000..02c5575
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/Version
@@ -0,0 +1,2 @@
+nlogin-0.3-pre
+Tue, 17 Jun 2008 10:35:26 -0000
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/__end_parse.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/__end_parse.c
new file mode 100644
index 0000000..03e458d
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/__end_parse.c
@@ -0,0 +1,10 @@
+#include <sys/types.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include "parselib.h"
+
+void __end_parse(struct state* s) /*EXTRACT_INCL*/{
+ munmap((void*)(s->buffirst),s->buflen);
+ s->buffirst=0;
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/__parse_feed.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/__parse_feed.c
new file mode 100644
index 0000000..66b6791
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/__parse_feed.c
@@ -0,0 +1,14 @@
+#include <sys/types.h>
+#include "parselib.h"
+
+int __parse_feed(struct state *s, char *buf, unsigned int len) /*EXTRACT_INCL*/{
+ char *p;
+ unsigned int u;
+ again:
+ p = (char *)(s->buffirst) + s->cur;
+ if (!(u = __parse_getline(s,'\n'))) return 0;
+ if (u >= len) goto again; /* very long line; skip it */
+ byte_copy(buf,u,p);
+ buf[u++]=0;
+ return u;
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/__parse_getline.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/__parse_getline.c
new file mode 100644
index 0000000..ed2b53a
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/__parse_getline.c
@@ -0,0 +1,14 @@
+#include <sys/types.h>
+#include "parselib.h"
+
+size_t __parse_getline(struct state *s, int c) /*EXTRACT_INCL*/ {
+ size_t n;
+
+ for (n=s->cur; n < s->buflen && s->buffirst[n] != c; ++n);
+ n = n-s->cur;
+ s->cur += n;
+
+ /* skip 'c' or emty lines: ^c$ */
+ for (;s->cur < s->buflen && s->buffirst[s->cur] == c;) s->cur++;
+ return n;
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/__parse_split.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/__parse_split.c
new file mode 100644
index 0000000..54e15cf
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/__parse_split.c
@@ -0,0 +1,15 @@
+
+int __parse_split(char *p,int buf_len,int c,int maxarg,char *arg[]) /*EXTRACT_INCL*/{
+ int i = 0;
+ char *end = p + buf_len;
+ for (arg[0]=p; p<end; p++) {
+ if (*p == c || *p == 0) {
+ *p = 0;
+ ++i;
+ if (i >= maxarg) break;
+ arg[i] = p+1;
+ }
+ }
+ arg[i] = 0;
+ return i;
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/__prepare_parse.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/__prepare_parse.c
new file mode 100644
index 0000000..1cf86a4
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/__prepare_parse.c
@@ -0,0 +1,22 @@
+#include <sys/types.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include "parselib.h"
+
+void __prepare_parse(const char* filename,struct state* s) /*EXTRACT_INCL*/{
+ int fd;
+ s->cur=0;
+ if (s->buffirst) return; /* already mapped */
+ fd=open(filename,O_RDONLY);
+ if (fd>=0) {
+ s->buflen=lseek(fd,0,SEEK_END);
+ s->buffirst=mmap(0,s->buflen,PROT_READ,MAP_PRIVATE,fd,0);
+ if (s->buffirst==(const char*)-1)
+ s->buffirst=0;
+ close(fd);
+ } else {
+ s->buflen=0;
+ s->buffirst=0;
+ }
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/byte_copy.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/byte_copy.c
new file mode 100644
index 0000000..3d25769
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/byte_copy.c
@@ -0,0 +1,6 @@
+void byte_copy(void *to, unsigned long n, const void *from) /*EXTRACT_INCL*/ {
+ char *d=(char*)to;
+ char *s=(char*)from;
+ unsigned long k=0;
+ for (; k<n; k++) d[k] = s[k];
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/byte_diff.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/byte_diff.c
new file mode 100644
index 0000000..a0bc17e
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/byte_diff.c
@@ -0,0 +1,11 @@
+int byte_diff(const void* a, unsigned long len, const void* b) /*EXTRACT_INCL*/ {
+ char *x=(char *)a;
+ char *y=(char *)b;
+ unsigned long u=0;
+ char ch=0;
+ for (; u<len; u++) {
+ ch = x[u] - y[u];
+ if (ch) break;
+ }
+ return ch;
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/byte_set.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/byte_set.c
new file mode 100644
index 0000000..33b3d77
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/byte_set.c
@@ -0,0 +1,7 @@
+void byte_set(const void* dst, unsigned long len, char ch) /*EXTRACT_INCL*/ {
+ char *d=(char*)dst;
+ while (len) {
+ --len;
+ d[len] = ch;
+ }
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/byte_zero.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/byte_zero.c
new file mode 100644
index 0000000..0813e05
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/byte_zero.c
@@ -0,0 +1,4 @@
+void byte_zero(const void *a, unsigned long len) /*EXTRACT_INCL*/ {
+ char *x=(char *)a;
+ while (len > 0) x[--len] = 0;
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/config.h b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/config.h
new file mode 100644
index 0000000..50086ea
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/config.h
@@ -0,0 +1,54 @@
+/* feel free to change */
+
+#ifndef CONFIG__H__
+#define CONFIG__H__
+
+#ifdef NV_SETPWENT
+#define DONT_NEED_GECOS
+#define __PASSWD_BUFFER 128
+#define __PASSWD_FILE "/etc/passwd"
+#endif
+
+#ifdef NV_SETGRENT
+#define __GROUP_BUFFER 128
+#define __GROUP_FILE "/etc/group"
+#define SCAN_GROUPS 16
+#endif
+
+#ifdef NV_SETSPENT
+#define DONT_NEED_ALL_SHADOW
+#define __SHADOW_BUFFER 128
+#define __SHADOW_FILE "/etc/shadow"
+#endif
+
+#ifdef LOGIN_PROGRAM
+#define LOGIN_AUTHORITY "/bin/nlogin-auth"
+
+
+/* uncomment some lines to use build-in C functions */
+// #define nv_getpwnam getpwnam
+// #define nv_getspnam getspnam
+// #define nv_gergrnam getgrnam
+// #define nv_initgroups initgroups
+#endif
+
+#ifdef PASS_CHECK_C
+/* define next to use build-in (/lib/libcrypt.so) shared crypt()
+ build with: make ... LDFLAGS='-s -lcrypt' */
+
+// #define USE_BUILDIN_C_CRYPT
+
+#ifndef USE_BUILDIN_C_CRYPT
+#define pass_crypt_appl md5crypt
+#include "md5.h"
+
+#else
+#define pass_crypt_appl crypt
+#include <unistd.h>
+#ifndef __dietlibc__
+#include <crypt.h>
+#endif
+#endif
+#endif
+
+#endif
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/faillog_do.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/faillog_do.c
new file mode 100644
index 0000000..84e2f83
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/faillog_do.c
@@ -0,0 +1,70 @@
+#include <unistd.h>
+#include <fcntl.h>
+#include <time.h>
+#include <sys/types.h>
+#include "str_defs.h"
+#include "utmp_defs.h"
+
+struct faillog {
+ short fail_cnt; /* failures since last success */
+ short fail_max; /* failures before turning account off */
+ char fail_line[12]; /* last failure occured here */
+ time_t fail_time; /* last failure occured then */
+ /*
+ * If nonzero, the account will be re-enabled if there are no
+ * failures for fail_locktime seconds since last failure.
+ */
+ long fail_locktime;
+};
+
+#ifndef NV_PATH_FAILLOG
+#define NV_PATH_FAILLOG "/var/log/faillog"
+#endif
+
+#define FL_SIZE sizeof(struct faillog)
+#define SC(A,B) str_copynz(A, B, sizeof(A))
+
+/*
+ OK==0 failure; 1 good password; -1 only check
+ if return is nonzero login is disabled !!!
+*/
+int faillog_do(unsigned int uid, char *line, int OK) /*EXTRACT_INCL*/{
+ struct faillog fl;
+ off_t offset = uid * FL_SIZE;
+ int fd, ret=0;
+ time_t now;
+
+ fd = open(NV_PATH_FAILLOG, O_RDWR);
+ if (fd<0) return 0;
+
+ if (lseek(fd,offset,SEEK_SET) ==offset && read(fd,&fl,FL_SIZE)==FL_SIZE) {
+ switch (OK) {
+ case 1: fl.fail_cnt = 0; break;
+ case 0:
+ if (fl.fail_max == 0 ||
+ fl.fail_cnt <= fl.fail_max) fl.fail_cnt += 1;
+ }
+ } else
+ byte_zero(&fl, FL_SIZE);
+
+ now = time(0);
+ if (fl.fail_locktime &&
+ fl.fail_time &&
+ (now < fl.fail_time || /* barery failed */
+ now - fl.fail_time > fl.fail_locktime))
+ fl.fail_cnt = 0; /* unlock account */
+
+ if (fl.fail_max > 0 &&
+ fl.fail_cnt > fl.fail_max) ret = -1; /* disable logging */
+
+ fl.fail_time = now;
+ SC(fl.fail_line, line);
+
+ if (lseek(fd, offset, SEEK_SET) ==offset)
+ SAFE_IO(write, fd, &fl, FL_SIZE);
+
+ fsync(fd);
+ close(fd);
+
+ return (OK==1) ? 0 : ret;
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/fmt_ulong.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/fmt_ulong.c
new file mode 100644
index 0000000..12ff9f9
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/fmt_ulong.c
@@ -0,0 +1,10 @@
+unsigned int fmt_ulong(register char *s,register unsigned long u) /*EXTRACT_INCL*/ {
+ register unsigned int len; register unsigned long q;
+ len = 1; q = u; /* DJB */
+ while (q > 9) { ++len; q /= 10; }
+ if (s) {
+ s += len;
+ do { *--s = '0' + (u % 10); u /= 10; } while(u); /* handles u == 0 */
+ }
+ return len;
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/get_headers b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/get_headers
new file mode 100755
index 0000000..a18b474
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/get_headers
@@ -0,0 +1,25 @@
+#!/bin/sh
+[ $# -lt 2 ] && exit 1
+
+export PATH=/bin:/usr/bin
+name=`echo $1 | sed -e 's/\./__DOT__/g' -e 's/\//__SLASH__/g'`
+shift
+
+echo '#ifndef' AUTO_FILE__$$__$name
+echo '#define' AUTO_FILE__$$__$name
+echo '/* '`date`' */'
+
+while test $# -gt 0; do
+ case $1 in
+ -L*) echo $1 | sed -e 's/^../#include "/' -e 's/$/"/' ; shift;;
+ -G*) echo $1 | sed -e 's/^../#include </' -e 's/$/>/' ; shift;;
+ -I*) echo $1 | sed -e 's/^../#include /'; shift;;
+ *) break;;
+ esac
+done
+
+if [ $# -gt 0 ] ; then
+ sed -n -e 's/\(.*\) \/\*EXTRACT_INCL\*\/.*/extern \1;/p' \
+ -e 's/ \/\*EXTRACT_UNMOD\*\/.*//p' $@
+fi
+echo '#endif'
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/get_tz.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/get_tz.c
new file mode 100644
index 0000000..94b42e1
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/get_tz.c
@@ -0,0 +1,42 @@
+#include <unistd.h>
+#include <fcntl.h>
+#include "parselib.h"
+
+static struct state s;
+
+static int parse(unsigned char *x)
+ {return (x[0]<<24) | (x[1]<<16) | (x[2]<<8) | x[3];}
+
+static time_t time_offset(time_t *t, int forward) {
+ unsigned char *T = (unsigned char *)s.buffirst, *tmp,*x;
+ size_t L = s.buflen;
+ time_t i, k, res, tzh_timecnt;
+ if (!T || L<44) return 0;
+ tzh_timecnt = parse(T+32);
+ tmp=T+44;
+ x=tmp+tzh_timecnt*4;
+ for (i=tzh_timecnt-1; 0<=i; --i) {
+ k = parse(tmp+i*4);
+ if (forward) if (*t < k) continue;
+
+ res = parse(x +tzh_timecnt +6*(unsigned char)x[i]);
+
+ if (forward) return res;
+ else
+ if (k+res <= *t) return -res;
+ }
+ return 0;
+}
+
+time_t get_tz(time_t *t, int forward) /*EXTRACT_INCL*/{
+ if (forward==-1) {
+ __end_parse(&s);
+ s.cur=0;
+ return 0;
+ }
+ if (!s.cur) {
+ __prepare_parse("/etc/localtime",&s);
+ s.cur=1;
+ }
+ return time_offset(t,forward);
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/lastlog_do.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/lastlog_do.c
new file mode 100644
index 0000000..f840ea1
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/lastlog_do.c
@@ -0,0 +1,43 @@
+#include <unistd.h>
+#include <fcntl.h>
+#include <utmp.h>
+#include <time.h>
+#include "time_defs.h"
+#include "utmp_defs.h"
+#include "prot_defs.h"
+
+#ifndef LASTLOG_FILE
+#define LASTLOG_FILE "/var/log/lastlog"
+#endif
+
+#define SC(A,B) str_copynz(A, B, sizeof(A))
+
+void lastlog_do(char *buf, unsigned int uid, char *line) /*EXTRACT_INCL*/{
+ int fd = open(LASTLOG_FILE, O_RDWR);
+ struct lastlog ll;
+ off_t offset = uid * sizeof ll;
+ char *p=buf;
+
+ p[0] = 0;
+ if (fd<0 || lseek(fd, offset, SEEK_SET) != offset) goto do_close;
+ if (read(fd, &ll, sizeof ll) == sizeof ll && ll.ll_time) {
+ p += str_copy(p, "Last login: ");
+ p += nv_ctime(p, ll.ll_time, 24);
+ p += str_copy(p, " on ");
+ p += str_add(p, ll.ll_line, sizeof ll.ll_line);
+ if (ll.ll_host[0]) {
+ p += str_copy(p, " from ");
+ p += str_add(p, ll.ll_host, 40);
+ }
+ *p++ = '\n';
+ *p = 0;
+ }
+
+ if (lseek(fd, offset, SEEK_SET) != offset) goto do_close;
+ byte_zero(&ll, sizeof ll);
+ ll.ll_time=time(0);
+ SC(ll.ll_line, line);
+ SAFE_IO(write, fd, &ll, sizeof ll);
+ do_close:
+ close(fd);
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/log_do.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/log_do.c
new file mode 100644
index 0000000..01e8e01
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/log_do.c
@@ -0,0 +1,21 @@
+#include <unistd.h>
+#include <fcntl.h>
+#include <time.h>
+#include "time_defs.h"
+
+void log_do(char *buf,int OK, char *program, char *username, char *tty) /*EXTRACT_INCL*/{
+ char *p=buf;
+ *p++ ='<';
+ p += fmt_ulong(p, (10<<3) | (4+2*OK)); /* 4 warn, 5 notice, 6 info */
+ *p++ = '>';
+ nv_ctime(p,time(0), 26);
+ p += str_add(p,p+4,16);
+ p += str_add(p,program,32); *p++='[';
+ p += fmt_ulong(p,getpid());
+ p += str_copy(p,"]: ");
+ p += str_add(p,username,32);
+ p += str_copy(p, (OK) ? " logged on " : " fail on ");
+ p += str_add(p,tty,32);
+ *p++ = '\n';
+ write_devlog(buf, p-buf);
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/md5.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/md5.c
new file mode 100644
index 0000000..abeb93d
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/md5.c
@@ -0,0 +1,177 @@
+/*
+md5.c
+small size MD5 20080116
+public domain
+written by Nikola Vladov
+inspired by ditlibc, libtomcrypt, bglibs
+*/
+
+#include <stdint.h>
+#include <endian.h>
+#include "md5.h"
+
+#ifndef __BYTE_ORDER
+#error __BYTE_ORDER is undefined
+#endif
+
+#if (__BYTE_ORDER == __BIG_ENDIAN)
+/*
+ Block copy and convert byte order to little-endian.
+ dst must be 32bit aligned.
+ Length is the number of 32bit words
+*/
+static void load_lendian (uint32_t *dst, const uint8_t *src, int length) {
+ while (length--) {
+ *dst=(((uint32_t)src[3])<<24) |
+ (((uint32_t)src[2])<<16) |
+ (((uint32_t)src[1])<< 8) |
+ (uint32_t)src[0];
+ src+=4;
+ dst++;
+ }
+}
+
+#define STORE32L(buf,s,len) \
+ load_lendian((uint32_t *)(buf), (const uint8_t *)(s), len)
+#else
+#define STORE32L(buf,s,len) byte_copy(buf,len*4,s)
+#endif
+
+#define ROL(a,s) ((a<<s)|(a>>(32-s)))
+#define F(x,y,z) (z^(x&(y^z)))
+#define G(x,y,z) (y^(z&(y^x)))
+#define H(x,y,z) (x^y^z)
+#define I(x,y,z) (y^(x|(~z)))
+
+#define SET4(A,B,C,D,a,b,c,d) A =a; B =b; C =c; D =d
+#define PLUS4(A,B,C,D,a,b,c,d) A+=a; B+=b; C+=c; D+=d
+
+static const unsigned char Worder[64] = {
+ 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
+ 1,6,11,0,5,10,15,4,9,14,3,8,13,2,7,12,
+ 5,8,11,14,1,4,7,10,13,0,3,6,9,12,15,2,
+ 0,7,14,5,12,3,10,1,8,15,6,13,4,11,2,9
+};
+
+static const unsigned char Rorder[64] = {
+ 7,12,17,22,7,12,17,22,7,12,17,22,7,12,17,22,
+ 5,9,14,20,5,9,14,20,5,9,14,20,5,9,14,20,
+ 4,11,16,23,4,11,16,23,4,11,16,23,4,11,16,23,
+ 6,10,15,21,6,10,15,21,6,10,15,21,6,10,15,21
+};
+
+static const uint32_t Korder[64] = {
+ 0xd76aa478UL, 0xe8c7b756UL, 0x242070dbUL, 0xc1bdceeeUL, 0xf57c0fafUL,
+ 0x4787c62aUL, 0xa8304613UL, 0xfd469501UL, 0x698098d8UL, 0x8b44f7afUL,
+ 0xffff5bb1UL, 0x895cd7beUL, 0x6b901122UL, 0xfd987193UL, 0xa679438eUL,
+ 0x49b40821UL, 0xf61e2562UL, 0xc040b340UL, 0x265e5a51UL, 0xe9b6c7aaUL,
+ 0xd62f105dUL, 0x02441453UL, 0xd8a1e681UL, 0xe7d3fbc8UL, 0x21e1cde6UL,
+ 0xc33707d6UL, 0xf4d50d87UL, 0x455a14edUL, 0xa9e3e905UL, 0xfcefa3f8UL,
+ 0x676f02d9UL, 0x8d2a4c8aUL, 0xfffa3942UL, 0x8771f681UL, 0x6d9d6122UL,
+ 0xfde5380cUL, 0xa4beea44UL, 0x4bdecfa9UL, 0xf6bb4b60UL, 0xbebfbc70UL,
+ 0x289b7ec6UL, 0xeaa127faUL, 0xd4ef3085UL, 0x04881d05UL, 0xd9d4d039UL,
+ 0xe6db99e5UL, 0x1fa27cf8UL, 0xc4ac5665UL, 0xf4292244UL, 0x432aff97UL,
+ 0xab9423a7UL, 0xfc93a039UL, 0x655b59c3UL, 0x8f0ccc92UL, 0xffeff47dUL,
+ 0x85845dd1UL, 0x6fa87e4fUL, 0xfe2ce6e0UL, 0xa3014314UL, 0x4e0811a1UL,
+ 0xf7537e82UL, 0xbd3af235UL, 0x2ad7d2bbUL, 0xeb86d391UL
+};
+
+static void md5_compress(md5_state *md, const unsigned char *buf) {
+ uint32_t i, a, b, c, d, t, *W = (uint32_t *)md->buf;
+ STORE32L(W,buf,16);
+ SET4(a,b,c,d, md->state[0], md->state[1], md->state[2], md->state[3]);
+
+ for (i = 0; i < 64; ++i) {
+ if (i<16) a += F(b,c,d);
+ else if (i<32) a += G(b,c,d);
+ else if (i<48) a += H(b,c,d);
+ else a += I(b,c,d);
+ a += W[Worder[i]] + Korder[i];
+ t = ROL(a, Rorder[i]) + b;
+ SET4(a,d,c,b, d,c,b,t);
+ }
+
+ PLUS4(md->state[0], md->state[1], md->state[2], md->state[3], a,b,c,d);
+}
+
+/**
+ Initialize the hash state
+ @param md The hash state you wish to initialize
+*/
+static const uint32_t init_state[4] = {
+ 0x67452301UL, 0xefcdab89UL, 0x98badcfeUL, 0x10325476UL
+};
+
+void md5_init(md5_state *md) /*EXTRACT_INCL*/{
+ md->length = 0;
+ byte_copy(md->state, sizeof(init_state), init_state);
+}
+
+/**
+ Process a block of memory though the hash
+ @param md The hash state
+ @param in The data to hash
+ @param inlen The length of the data (octets)
+*/
+
+void md5_update(md5_state *md,const unsigned char *vdata,unsigned long data_len) /*EXTRACT_INCL*/{
+ const unsigned char *data = vdata;
+ unsigned use, mlen = md->length % 64;
+
+ md->length += data_len;
+ if (mlen > 0 && data_len >= (use = 64 - mlen)) {
+ byte_copy(md->buf + mlen, use, data);
+ md5_compress(md, md->buf);
+ mlen = 0;
+ data_len -= use;
+ data += use;
+ }
+
+ while (data_len >= 64) {
+ md5_compress (md, data);
+ data_len -= 64;
+ data += 64;
+ }
+
+ byte_copy(md->buf + mlen, data_len, data);
+}
+
+/**
+ Terminate the hash to get the digest
+ @param md The hash state
+ @param out [out] The destination of the hash (16 bytes)
+*/
+void md5_final(md5_state *md, unsigned char *out) /*EXTRACT_INCL*/{
+ uint64_t length = md->length;
+ uint32_t mlen = length % 64;
+
+ /* increase the length of the message */
+ length *= 8;
+
+ /* append the '1' bit */
+ md->buf[mlen++] = (unsigned char)0x80;
+
+ /* if the length is currently above 56 bytes we append zeros
+ * then compress. Then we can fall back to padding zeros and length
+ * encoding like normal.
+ */
+ byte_zero(md->buf + mlen, 64-mlen);
+ if (mlen > 64-8) {
+ md5_compress(md, md->buf);
+ byte_zero(md->buf, 64-8);
+ }
+
+ /* store length */
+#if (__BYTE_ORDER == __BIG_ENDIAN)
+ length = (length<<32)|(length>>32)
+#endif
+ STORE32L(md->buf+56, &length, 2);
+ md5_compress(md, md->buf);
+
+ /* copy output */
+#if (__BYTE_ORDER == __BIG_ENDIAN)
+ STORE32L(md->state, md->state, 4);
+#endif
+ byte_copy(out, 16, md->state);
+ byte_zero(md, sizeof(md5_state));
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/md5.h b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/md5.h
new file mode 100644
index 0000000..0c8a889
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/md5.h
@@ -0,0 +1,21 @@
+#ifndef MD5_H
+#define MD5_h
+#include <stdint.h>
+
+struct md5_state {
+ unsigned char buf[64];
+ uint32_t state[4];
+ uint64_t length;
+};
+
+typedef struct md5_state md5_state;
+#include "md5_defs.h"
+
+#define MD5_CTX md5_state
+#define MD5_Init md5_init
+#define MD5_Update md5_update
+#define MD5_Final(buf, hash) md5_final(hash, buf)
+
+#include "str_defs.h"
+#include "byte_defs.h"
+#endif
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/md5crypt.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/md5crypt.c
new file mode 100644
index 0000000..ab15e8f
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/md5crypt.c
@@ -0,0 +1,140 @@
+/* $OpenBSD: md5crypt.c,v 1.9 1997/07/23 20:58:27 kstailey Exp $ */
+
+/*
+ * ----------------------------------------------------------------------------
+ * "THE BEER-WARE LICENSE" (Revision 42):
+ * <[email protected]> wrote this file. As long as you retain this notice you
+ * can do whatever you want with this stuff. If we meet some day, and you think
+ * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
+ * ----------------------------------------------------------------------------
+ *
+ * $FreeBSD: crypt.c,v 1.5 1996/10/14 08:34:02 phk Exp $
+ *
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char rcsid[] = "$OpenBSD: md5crypt.c,v 1.9 1997/07/23 20:58:27 kstailey Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <unistd.h>
+#include "md5.h"
+
+static unsigned char itoa64[] = /* 0 ... 63 => ascii - 64 */
+ "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+
+static void to64(unsigned char *s, uint32_t v, int n)
+{
+ while (--n >= 0) {
+ *s++ = itoa64[v&0x3f];
+ v >>= 6;
+ }
+}
+
+/*
+ * UNIX password
+ *
+ * Use MD5 for what it is best at...
+ */
+
+#define R(F,P,Q,R) to64(p, (F[P]<<16) | (F[Q]<<8) | F[R], 4); p += 4
+#define magic (unsigned char *)"$1$"
+
+char *md5crypt(const char *pw, const char *salt) /*EXTRACT_INCL*/
+{
+ static char passwd[40];
+ const unsigned char *sp,*ep;
+ unsigned char final[16], *p = (unsigned char *)pw;
+ int sl,i,pw_len = str_len(pw);
+ MD5_CTX ctx,ctx1;
+
+ /* Refine the Salt first */
+ sp = (const unsigned char *)salt;
+
+ /* If it starts with the magic string, then skip that */
+ if (!byte_diff(sp,3,magic))
+ sp += 3;
+
+ /* It stops at the first '$', max 8 chars */
+ for(ep=sp;*ep && *ep != '$' && ep < (sp+8);ep++)
+ continue;
+
+ /* get the length of the true salt */
+ sl = ep - sp;
+
+ MD5_Init(&ctx);
+
+ /* The password first, since that is what is most unknown */
+ MD5_Update(&ctx,p,pw_len);
+
+ /* Then our magic string */
+ MD5_Update(&ctx,magic,3);
+
+ /* Then the raw salt */
+ MD5_Update(&ctx,sp,sl);
+
+ /* Then just as many characters of the MD5(pw,salt,pw) */
+ MD5_Init(&ctx1);
+ MD5_Update(&ctx1,p,pw_len);
+ MD5_Update(&ctx1,sp,sl);
+ MD5_Update(&ctx1,p,pw_len);
+ MD5_Final(final,&ctx1);
+ for (i = pw_len; i > 0; i -= 16)
+ MD5_Update(&ctx,final,(i>16) ? 16 : i);
+
+ /* Don't leave anything around in vm they could use. */
+ byte_zero(final,sizeof(final));
+
+ /* Then something really weird... */
+ for (i = pw_len; i ; i >>= 1)
+ if(i&1)
+ MD5_Update(&ctx, final, 1);
+ else
+ MD5_Update(&ctx, p, 1);
+
+ MD5_Final(final,&ctx);
+
+ /*
+ * and now, just to make sure things don't run too fast
+ * On a 60 Mhz Pentium this takes 34 msec, so you would
+ * need 30 seconds to build a 1000 entry dictionary...
+ */
+ for(i=0;i<1000;i++) {
+ MD5_Init(&ctx1);
+ if(i & 1)
+ MD5_Update(&ctx1,p,pw_len);
+ else
+ MD5_Update(&ctx1,final,16);
+
+ if(i % 3)
+ MD5_Update(&ctx1,sp,sl);
+
+ if(i % 7)
+ MD5_Update(&ctx1,p,pw_len);
+
+ if(i & 1)
+ MD5_Update(&ctx1,final,16);
+ else
+ MD5_Update(&ctx1,p,pw_len);
+ MD5_Final(final,&ctx1);
+ }
+
+ /* Now make the output string */
+ p = (unsigned char *)passwd + 3 + sl;
+ byte_copy(passwd, 3, magic);
+ byte_copy(passwd+3, sl, sp);
+ *p++ = '$';
+
+ R(final, 0, 6,12);
+ R(final, 1, 7,13);
+ R(final, 2, 8,14);
+ R(final, 3, 9,15);
+ R(final, 4,10, 5);
+ to64(p,final[11],2);
+ p[2] = 0;
+
+ /* Don't leave anything around in vm they could use. */
+ byte_zero(final,sizeof(final));
+ pw_len = 0;
+
+ return passwd;
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nlogin-auth.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nlogin-auth.c
new file mode 100644
index 0000000..e275531
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nlogin-auth.c
@@ -0,0 +1,125 @@
+#include <unistd.h>
+#include <errno.h>
+#include <limits.h>
+#include <alloca.h>
+#include "md5.h"
+#include "pw_defs.h"
+#include "utmp_defs.h"
+#include "time_defs.h"
+
+#define fdin 3
+#define fdout 4
+
+#define ZZ(A) if (A) byte_zero(A, str_len(A))
+#define FL(X,Var) *p++ = X; p += fmt_ulong(p, Var); ++p
+#define FN(L,Var) p += str_copy(p,L); p += fmt_ulong(p, Var); ++p
+#define FS(L,Var) p += mycat(p,L,Var); ++p
+
+static struct passwd *pw;
+static char *stored, *encrypted;
+static char up[513];
+
+static int z(int n) {
+ byte_zero(up, sizeof(up));
+ ZZ(stored);
+ ZZ(encrypted);
+ if (n==0) return 0;
+ close(fdin);
+ close(fdout);
+ _exit(n);
+}
+
+static void check_pass(char *program, char *tty) {
+ char *password; /* user name is up */
+ int k=0, i=0, uplen;
+
+ close(0); close(1); close(2);
+ errno = 0;
+ uplen = SAFE_IO(read, fdin, up, sizeof(up));
+ if (errno) z(111);
+ if (uplen >= (int)sizeof(up)) z(1);
+ close(fdin);
+
+ if (uplen==0) z(2);
+ while (up[i++]) if (i >= uplen) z(2);
+ password = up + i;
+ if (i >= uplen) z(2);
+ while (up[i++]) if (i >= uplen) z(2);
+
+ pw = nv_getpwnam(up);
+ if (pw) {
+ struct spwd *spw;
+ if (i<uplen &&
+ !str_diff("-autologin", up+i)) { k=1; goto do_it; }
+
+ if (pw->pw_passwd[0]=='*' ||
+ pw->pw_passwd[0]=='!') goto do_it;
+
+ spw = nv_getspnam(up);
+ if (spw) stored = spw->sp_pwdp;
+ }
+
+ if (!stored || str_len(stored) < 12) k=0;
+ else {
+ encrypted = md5crypt(password, stored);
+ k = !str_diff(encrypted, stored); /* 1 good password */
+ }
+
+ do_it:
+ z(0); /* zero buffers */
+ if (pw) log_do(up, k, program, pw->pw_name, tty);
+ z(!k);
+}
+
+int main(int argc, char **argv) {
+ int i, n = NGROUPS_MAX;
+ struct group *ttygr=0;
+ gid_t groups[NGROUPS_MAX+1];
+ char *p, *tty, lastlog[96];
+
+ (void)argc;
+ tty = ttyname(0);
+ if (tty==0) tty="";
+
+ if (tty && !str_diffn(tty, "/dev/", 5)) p = tty + 5;
+ else p = "UNKNOWN";
+
+ check_pass(strip_slash(argv[0]), p);
+
+ utmp_do(pw->pw_name, p, getppid());
+ lastlog_do(lastlog, pw->pw_uid, p);
+ get_tz(0,-1);
+
+ if (nv_getgrouplist(pw->pw_name, pw->pw_gid, groups, &n) ||
+ n > NGROUPS_MAX) z(5);
+ ttygr = nv_getgrnam("tty");
+
+ z(0);
+ for (p=up,i=0; i<n; i++) {
+ FL('g', groups[i]);
+ if (p-up > 440) z(1);
+ }
+
+ if (p-up +
+ str_len(pw->pw_dir) +
+ str_len(pw->pw_name) +
+ str_len(pw->pw_shell) +
+ str_len(tty) +
+ str_len(lastlog) > 400) z(1);
+
+ FL('t', ttygr ? ttygr->gr_gid : (gid_t)pw->pw_gid);
+ FN("UID=", pw->pw_uid);
+ FN("GID=", pw->pw_gid);
+
+ FS("USER=", pw->pw_name);
+ FS("HOME=", pw->pw_dir);
+ FS("SHELL=", pw->pw_shell);
+ FS("TTY=", tty);
+ p += str_copy(p, lastlog);
+
+ n = (p-up)+5;
+ if (n != SAFE_IO(write, fdout, up, n)) z(1);
+ close(fdout);
+ z(0);
+ return 0;
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nlogin-tiny.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nlogin-tiny.c
new file mode 100644
index 0000000..af9fd96
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nlogin-tiny.c
@@ -0,0 +1,175 @@
+/* login.c */
+#define LOGIN_PROGRAM
+#include <unistd.h>
+#include <fcntl.h>
+#include <time.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <termios.h>
+#include <limits.h>
+#include <grp.h>
+
+#include "config.h"
+#include "str_defs.h"
+#include "utmp_defs.h"
+#include "prot_defs.h"
+
+#define SCAN_env(prefix, len, off, env) \
+ if (str_diffn(p, prefix, len)) goto z_1; \
+ arg[off]=p; env = p+len; p += str_len(p) + 1;
+
+static char up[513], buf[300];
+static char *arg[8], *pw_dir, *pw_shell, *pw_tty, *pw_last, *name;
+static uid_t pw_uid;
+static gid_t pw_gid, tty_gid, gr_list[NGROUPS_MAX], gr_n;
+
+static void z(int n) {
+ byte_zero(up, sizeof up);
+ byte_zero(buf, sizeof buf);
+ if (n==0) return;
+ _exit(n);
+}
+static void myexit(int n,char *s) { write(2,buf, mycat(buf,s,"\n")); z(n); }
+
+int get_userinfo(int pid, int autologin) {
+ char *p = up, *x = buf;
+ int n;
+ dup2(5,3); close(5); close(6);
+ p = up;
+ p += 1 + str_add(p, name, 40);
+ if (autologin) { x = "-autologin"; ++p; }
+ p += str_add(p, x, 120);
+
+ n = p-up+5;
+ if (n != SAFE_IO(write, 4, up, n)) goto z_1;
+ close(4);
+ z(0);
+
+ errno = 0;
+ n=SAFE_IO(read, 3, up, sizeof(up));
+ if (errno || n >= (int)sizeof(up) || n<5 || up[--n] || up[--n]) goto z_1;
+ close(3);
+
+ p=up;
+ for (gr_n=0; gr_n < NGROUPS_MAX;) {
+ if (!(n=scan_uid(p, "g", gr_list + gr_n))) break;
+ gr_n++;
+ p += n;
+ }
+ if (gr_n<1) goto z_1;
+
+ if (!(n=scan_uid(p, "t", &tty_gid))) goto z_1; p+=n;
+ if (!(n=scan_uid(p, "UID=", &pw_uid))) goto z_1; p+=n;
+ if (!(n=scan_uid(p, "GID=", &pw_gid))) goto z_1; p+=n;
+
+ if (str_diffn(p, "USER=", 5) || str_diff(p+5, name)) goto z_1;
+ arg[2] = p; p += 1 + str_len(p);
+
+ SCAN_env("HOME=", 5, 3, pw_dir);
+ SCAN_env("SHELL=", 6, 4, pw_shell);
+ SCAN_env("TTY=", 4, 0, pw_tty);
+
+ if (!str_diffn(p, "Last ", 5)) pw_last = p;
+ return 1; /* good user ;-) */
+ z_1:
+ waitpid(pid,0,0);
+ return 0;
+}
+
+int main(int argc, char **argv, char **env) {
+ char *p;
+ int fd,n, pi[2], OK=0, flag_auto=0;
+ struct termios oldtermios;
+
+ if (ioctl(0, TCGETS, &oldtermios)) _exit(100);
+ oldtermios.c_lflag &= ~(ECHO|ISIG);
+ tcsetattr(0,TCSAFLUSH,&oldtermios);
+
+ argv++;
+ (void)argc;
+ while ((p=argv[0]) && p[0] == '-') {
+ if (p[1]=='f') {
+ if (getuid()) goto do_it;
+
+ if (p[2]) p += 2; /* -fuser */
+ else p = argv[1]; /* -f user */
+
+ if (p && *p && *p != '-') {
+ flag_auto=1;
+ argv[0]=p;
+ break;
+ } else
+ goto do_it;
+ }
+ argv++;
+ }
+
+ if ((name=argv[0])==0 || name[0]==0) goto do_it;
+ if (flag_auto == 0)
+ if (read_password(buf)) goto do_it;
+
+ close(3); close(4); close(5); close(6);
+ if (pipe(pi) || pi[0] != 3 || pi[1] != 4 ||
+ pipe(pi) || pi[0] != 5 || pi[1] != 6)
+ myexit(111, "unable to open pipes");
+
+ switch (n=fork()) {
+ case -1: _exit(11);
+ case 0:
+ z(0);
+ if (prot_uidgid(0, 0, gr_list, 1)) z(21);
+ dup2(6,4); close(5); close(6);
+ arg[0] = LOGIN_AUTHORITY;
+ execve(*arg, arg, 0);
+ _exit(127);
+ default:
+ OK = get_userinfo(n, flag_auto);
+ }
+
+ do_it:
+ byte_zero(buf, sizeof(buf));
+ oldtermios.c_lflag |= ECHO;
+ tcsetattr(0, TCSAFLUSH, &oldtermios);
+
+ if (!OK) { sleep(1); myexit(100,"Sorry :-)"); }
+
+ if (pw_tty || !str_diffn(pw_tty, "/dev/", 5)) {
+ chown(pw_tty, pw_uid, tty_gid);
+ chmod(pw_tty, 0620);
+ }
+
+ p = prot_uidgid(pw_uid, pw_gid, gr_list, gr_n);
+ if (p) {
+ mycat(buf, "unable to set", p);
+ myexit(111, buf);
+ }
+
+ if (chdir(pw_dir)) {
+ n = mycat(buf,"unable to chdir: ", pw_dir); buf[n++] = '\n';
+ write(1,buf,n);
+ chdir("/");
+ }
+
+ if ((fd=open(".hushlogin", O_RDONLY)) >=0) {
+ close(fd);
+ } else {
+ if ((fd=open("/etc/motd", O_RDONLY)) >= -1) {
+ while ((n=read(fd,buf,sizeof buf)) >0) write(1,buf,n);
+ close(fd);
+ }
+ if (pw_last) write(1, pw_last, str_len(pw_last));
+ }
+
+ arg[0] = buf;
+ mycat(buf,"-",strip_slash(pw_shell));
+
+ for (; *env; env++)
+ if (!str_diffn(*env,"TERM=",5)) { arg[5]=*env; break; }
+
+ oldtermios.c_lflag |= ISIG;
+ tcsetattr(0, TCSAFLUSH, &oldtermios);
+ execve(pw_shell,arg,arg+2);
+ return 1;
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nlogin.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nlogin.c
new file mode 100644
index 0000000..ab0128b
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nlogin.c
@@ -0,0 +1,129 @@
+/* login.c */
+#define LOGIN_PROGRAM
+#include <unistd.h>
+#include <fcntl.h>
+#include <time.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <termios.h>
+#include "config.h"
+#include "str_defs.h"
+#include "pw_defs.h"
+#include "utmp_defs.h"
+#include "prot_defs.h"
+
+#define SD(A,B) !str_diffn(A, B, sizeof(A))
+#define SC(A,B) str_copynz(A, B, sizeof(A))
+
+static void myexit(int n,char *s)
+ { write(2,s,str_len(s)); write(2,"\n",1); _exit(n); }
+
+int main(int argc, char **argv, char **env) {
+ struct passwd *pw=0;
+ struct spwd *spwd;
+ char buf[1200], lastlog[96];
+ char *tty, *dev_tty=0, *program, *username=0, *p;
+ char *arg[8] = {buf,0,0,0, 0,0,0,0};
+ int fd,r,OK=0,flag_auto=0;
+ struct termios oldtermios;
+
+ if (ioctl(0, TCGETS, &oldtermios)) _exit(100);
+ oldtermios.c_lflag &= ~(ECHO|ISIG);
+ tcsetattr(0,TCSAFLUSH,&oldtermios);
+
+ if ((dev_tty=ttyname(0)) && !str_diffn("/dev/",dev_tty,5)) tty=dev_tty+5;
+ else { dev_tty = 0; tty="UNKNOWN"; }
+
+ program=strip_slash(argv[0]);
+ argv++; (void)argc;
+ while ((p=argv[0]) && p[0] == '-') {
+ if (p[1]=='f') {
+ if (getuid()) goto do_it;
+
+ if (p[2]) p += 2;
+ else p=argv[1];
+
+ if (p && *p && *p != '-') {
+ flag_auto=1;
+ argv[0]=p;
+ break;
+ } else
+ goto do_it;
+ }
+ argv++;
+ }
+
+ if (argv[0] == 0) goto do_it;
+ if (flag_auto == 0)
+ if (read_password(buf)) goto do_it;
+
+ pw = nv_getpwnam(argv[0]);
+ if (pw) {
+ username = pw->pw_name;
+ if (pw->pw_passwd[0]=='*' ||
+ pw->pw_passwd[0]=='!') goto do_it;
+ }
+ if (!username || *username == 0) goto do_it;
+
+ if (flag_auto==1) OK=1;
+ else {
+ if ((spwd = nv_getspnam(username))==0) goto do_it;
+ OK = pass_check(buf, spwd->sp_pwdp);
+ }
+
+ do_it:
+ byte_zero(buf,sizeof(buf));
+ oldtermios.c_lflag |= ECHO;
+ tcsetattr(0, TCSAFLUSH, &oldtermios);
+ if (!username) username="UNKNOWN";
+
+ log_do(buf,OK, program,username,tty);
+
+ if (!OK) { sleep(1); myexit(100,"Sorry :-)"); }
+ utmp_do(username, tty, getpid());
+ lastlog_do(lastlog, pw->pw_uid, tty);
+ get_tz(0,-1);
+
+ if (dev_tty) {
+ struct group *gr = nv_getgrnam("tty");
+ chown(dev_tty, pw->pw_uid, gr ? gr->gr_gid : pw->pw_gid);
+ chmod(dev_tty, 0620);
+ }
+
+ p = 0;
+ if (nv_initgroups(pw->pw_name,pw->pw_gid) == -1) p = "groups";
+ else if (setgid(pw->pw_gid) == -1) p = "gid";
+ else if (setuid(pw->pw_uid) == -1) p = "uid";
+ if (p) {
+ mycat(buf, "unable to set", p);
+ myexit(111, buf);
+ }
+
+ if (chdir(pw->pw_dir)) {
+ r = mycat(buf,"unable to chdir: ",pw->pw_dir); buf[r++] = '\n';
+ write(1,buf,r);
+ chdir("/");
+ }
+
+ if ((fd=open(".hushlogin", O_RDONLY)) >=0) {
+ close(fd);
+ } else {
+ if ((fd=open("/etc/motd", O_RDONLY)) != -1) {
+ while ((r=read(fd,buf,sizeof buf)) >0) write(1,buf,r);
+ close(fd);
+ }
+ write(1, lastlog, str_len(lastlog));
+ }
+
+ p=buf; p += 1 + mycat(p,"-",strip_slash(pw->pw_shell));
+ arg[2]=p; p += 1 + mycat(p,"HOME=",pw->pw_dir);
+ arg[3]=p; p += 1 + mycat(p,"USER=",pw->pw_name);
+ arg[4]=p; p += 1 + mycat(p,"SHELL=",pw->pw_shell);
+ for (; *env; env++)
+ if (!str_diffn(*env,"TERM=",5)) {arg[5]=*env; break;} /* arg[7] */
+
+ oldtermios.c_lflag |= ISIG;
+ tcsetattr(0, TCSAFLUSH, &oldtermios);
+ execve(pw->pw_shell,arg,arg+2);
+ return(1);
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_ctime.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_ctime.c
new file mode 100644
index 0000000..b7e497a
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_ctime.c
@@ -0,0 +1,41 @@
+#include <time.h>
+#include "time_defs.h"
+
+void num2str(char *c,int i) /*EXTRACT_INCL*/{c[0]=i/10+'0'; c[1]=i%10+'0';}
+
+unsigned int nv_ctime(char *p, time_t now, int len) /*EXTRACT_INCL*/{
+ char days[] = "SunMonTueWedThuFriSat";
+ char months[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
+ unsigned long day, mon, year, tod;
+
+ now += get_tz(&now, 1);
+
+ tod = (unsigned long)(now) % 86400;
+ day = (unsigned long)(now) / 86400;
+ byte_set(p, len, ' ');
+ str_add(p, days +3*((day+4) % 7), 3);
+
+ year = 4*day + 2;
+ year /= 1461;
+ day += 671;
+ day %= 1461; /* day 0 is march 1, 1972 */
+ if (day == 1460) { day = 365; }
+ else { day %= 365; }
+
+ day *= 10;
+ mon = (day + 5) / 306;
+ day = day + 5 - 306 * mon;
+ day /= 10;
+ if (mon >= 10) mon -= 10;
+ else mon += 2; /* day 0,1,30, mon 0..11, year 1970=0,1,2 */
+ /* 4 8 11 14 17 20 */
+ /* "Fri Jan 7 21:08:30 2005\n" */
+ str_add(p+4, months+3*mon, 3);
+ num2str(p+8, day+1); if (p[8]=='0') p[8]=' ';
+ num2str(p+17, tod%60); tod /= 60;
+ num2str(p+11, tod/60);
+ num2str(p+14, tod%60);
+ p[20 + fmt_ulong(p+20, 1970 + year)] = '\n';
+ p[13] = ':'; p[16] = ':';
+ return len;
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getgrent.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getgrent.c
new file mode 100644
index 0000000..ed14ad5
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getgrent.c
@@ -0,0 +1,37 @@
+#include <grp.h> /*EXTRACT_UNMOD*/
+#include "parselib.h"
+#define NV_SETGRENT
+#include "config.h"
+
+static struct state S;
+
+void nv_setgrent() /*EXTRACT_INCL*/ {__prepare_parse(__GROUP_FILE,&S);}
+void nv_endgrent() /*EXTRACT_INCL*/ {__end_parse(&S);}
+
+struct group *nv_getgrent() /*EXTRACT_INCL*/ {
+ static struct group gr;
+ static char *arg[SCAN_GROUPS + 2];
+ static char buf[__GROUP_BUFFER];
+ char *p;
+ unsigned long u;
+
+ if (!S.buffirst) nv_setgrent();
+ if (!S.buffirst) return 0;
+
+ again:
+ if ((u = __parse_feed(&S, buf, sizeof(buf)))==0) return 0;
+ if (4 != __parse_split(buf,u,':',4,arg)) goto again;
+
+ gr.gr_name = arg[0];
+#ifndef DONT_NEED_PASSWD
+ gr.gr_passwd = arg[1];
+#endif
+#ifndef DONT_NEED_GID
+ p=arg[2]; if (!*p || p[scan_ulong(p,&u)]) goto again; gr.gr_gid =u;
+#endif
+#ifndef DONT_NEED_MEMBERS
+ __parse_split(arg[3],str_len(arg[3])+1,',',SCAN_GROUPS,arg);
+ gr.gr_mem = arg;
+#endif
+ return(&gr);
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getgrgid.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getgrgid.c
new file mode 100644
index 0000000..0d2aba3
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getgrgid.c
@@ -0,0 +1,11 @@
+#include <grp.h>
+#include "pw_defs.h"
+
+struct group *nv_getgrgid(gid_t gid) /*EXTRACT_INCL*/ {
+ struct group *tmp;
+ nv_setgrent();
+ while ((tmp = nv_getgrent()))
+ if (tmp->gr_gid == gid) break;
+ nv_endgrent();
+ return tmp;
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getgrnam.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getgrnam.c
new file mode 100644
index 0000000..b276c79
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getgrnam.c
@@ -0,0 +1,11 @@
+#include <grp.h>
+#include "pw_defs.h"
+
+struct group *nv_getgrnam(const char* name) /*EXTRACT_INCL*/ {
+ struct group *tmp;
+ nv_setgrent();
+ while ((tmp = nv_getgrent()))
+ if (!str_diff(tmp->gr_name, name)) break;
+ nv_endgrent();
+ return tmp;
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getgrouplist.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getgrouplist.c
new file mode 100644
index 0000000..d644cce
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getgrouplist.c
@@ -0,0 +1,33 @@
+#include <grp.h>
+#include "pw_defs.h"
+
+int nv_getgrouplist(const char*user, gid_t group, gid_t*groups, int*ngroups) /*EXTRACT_INCL*/ {
+ long n=0,size=*ngroups;
+ struct group*g;
+ int ret=0;
+
+ if (0<size) { groups[n++]=group; }
+ else { *ngroups=0; return (-1); }
+
+ nv_setgrent();
+ while ((g=nv_getgrent())) {
+ char **duh;
+ if (g->gr_gid==group) continue;
+ duh=g->gr_mem;
+ while (*duh) {
+ if (!str_diff(*duh,user)) {
+ if (n>=size) {
+ ret=~ret;
+ goto err_out;
+ }
+ groups[n++]=g->gr_gid;
+ break;
+ }
+ duh++;
+ }
+ }
+err_out:
+ nv_endgrent();
+ *ngroups=n;
+ return ret;
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getpwent.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getpwent.c
new file mode 100644
index 0000000..75ce6cb
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getpwent.c
@@ -0,0 +1,44 @@
+#include <pwd.h> /*EXTRACT_UNMOD*/
+#include "parselib.h"
+#define NV_SETPWENT
+#include "config.h"
+
+static struct state S;
+
+void nv_setpwent() /*EXTRACT_INCL*/ {__prepare_parse(__PASSWD_FILE,&S);}
+void nv_endpwent() /*EXTRACT_INCL*/ {__end_parse(&S);}
+
+struct passwd *nv_getpwent() /*EXTRACT_INCL*/ {
+ static struct passwd pw;
+ static char buf[__PASSWD_BUFFER];
+ char *p,*arg[9];
+ unsigned long u;
+
+ if (!S.buffirst) nv_setpwent();
+ if (!S.buffirst) return 0;
+
+ again:
+ if ((u = __parse_feed(&S, buf, sizeof(buf)))==0) return 0;
+ if (7 != __parse_split(buf,u,':',7,arg)) goto again;
+
+ pw.pw_name = arg[0];
+#ifndef DONT_NEED_PASSWD
+ pw.pw_passwd = arg[1];
+#endif
+#ifndef DONT_NEED_UID
+ p=arg[2]; if (!*p || p[scan_ulong(p,&u)]) goto again; pw.pw_uid =u;
+#endif
+#ifndef DONT_NEED_GID
+ p=arg[3]; if (!*p || p[scan_ulong(p,&u)]) goto again; pw.pw_gid =u;
+#endif
+#ifndef DONT_NEED_GECOS
+ pw.pw_gecos = arg[4];
+#endif
+#ifndef DONT_NEED_DIR
+ pw.pw_dir = arg[5];
+#endif
+#ifndef DONT_NEED_SHELL
+ pw.pw_shell = arg[6];
+#endif
+ return(&pw);
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getpwgid.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getpwgid.c
new file mode 100644
index 0000000..8e65d56
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getpwgid.c
@@ -0,0 +1,11 @@
+#include <pwd.h>
+#include "pw_defs.h"
+
+struct passwd *nv_getpwgid(gid_t gid) /*EXTRACT_INCL*/ {
+ struct passwd *tmp;
+ nv_setpwent();
+ while ((tmp = nv_getpwent()))
+ if (tmp->pw_gid == gid) break;
+ nv_endpwent();
+ return tmp;
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getpwnam.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getpwnam.c
new file mode 100644
index 0000000..3430550
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getpwnam.c
@@ -0,0 +1,11 @@
+#include <pwd.h>
+#include "pw_defs.h"
+
+struct passwd *nv_getpwnam(const char* name) /*EXTRACT_INCL*/ {
+ struct passwd *tmp;
+ nv_setpwent();
+ while ((tmp = nv_getpwent()))
+ if (!str_diff(tmp->pw_name, name)) break;
+ nv_endpwent();
+ return tmp;
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getpwuid.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getpwuid.c
new file mode 100644
index 0000000..5a0e541
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getpwuid.c
@@ -0,0 +1,11 @@
+#include <pwd.h>
+#include "pw_defs.h"
+
+struct passwd *nv_getpwuid(uid_t uid) /*EXTRACT_INCL*/ {
+ struct passwd *tmp;
+ nv_setpwent();
+ while ((tmp = nv_getpwent()))
+ if (tmp->pw_uid == uid) break;
+ nv_endpwent();
+ return tmp;
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getspent.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getspent.c
new file mode 100644
index 0000000..3d6a75c
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getspent.c
@@ -0,0 +1,47 @@
+#include <shadow.h> /*EXTRACT_UNMOD*/
+#include "parselib.h"
+#define NV_SETSPENT
+#include "config.h"
+
+static struct state S;
+
+void nv_setspent() /*EXTRACT_INCL*/{__prepare_parse(__SHADOW_FILE,&S);}
+void nv_endspent() /*EXTRACT_INCL*/{__end_parse(&S);}
+
+struct spwd *nv_getspent() /*EXTRACT_INCL*/ {
+ static struct spwd sp;
+ static char buf[__SHADOW_BUFFER];
+ char *arg[12];
+ unsigned int u;
+
+ if (!S.buffirst) nv_setspent();
+ if (!S.buffirst) return 0;
+
+ again:
+ if ((u=__parse_feed(&S, buf, sizeof(buf)))==0) return 0;
+ if ((u=__parse_split(buf,u,':',9,arg)) < 6) goto again;
+
+ sp.sp_namp = arg[0];
+ sp.sp_pwdp = arg[1];
+#ifndef DONT_NEED_ALL_SHADOW
+ {
+ unsigned long i,j,l;
+ for (i=2; i<u; i++) {
+ j=scan_ulong(arg[i],&l);
+ if (arg[i][j]) goto again;
+ if (j==0) l = (unsigned long)-1;
+
+ switch (i) {
+ case 2: sp.sp_lstchg=l; break;
+ case 3: sp.sp_min=l; break;
+ case 4: sp.sp_max=l; break;
+ case 5: sp.sp_warn=l; break;
+ case 6: sp.sp_inact=l; break;
+ case 7: sp.sp_expire=l; break;
+ case 8: sp.sp_flag=l; break;
+ }
+ }
+ }
+#endif
+ return(&sp);
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getspnam.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getspnam.c
new file mode 100644
index 0000000..7790155
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_getspnam.c
@@ -0,0 +1,11 @@
+#include <shadow.h>
+#include "pw_defs.h"
+
+struct spwd *nv_getspnam(const char* name) /*EXTRACT_INCL*/ {
+ struct spwd *tmp;
+ nv_setspent();
+ while ((tmp = nv_getspent()))
+ if (!str_diff(tmp->sp_namp, name)) break;
+ nv_endspent();
+ return tmp;
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_initgroups.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_initgroups.c
new file mode 100644
index 0000000..51af879
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_initgroups.c
@@ -0,0 +1,11 @@
+#include <grp.h>
+#include <limits.h>
+#include "pw_defs.h"
+
+int nv_initgroups(const char*user,gid_t group) /*EXTRACT_INCL*/ {
+ int n=NGROUPS_MAX;
+ gid_t grouplist[NGROUPS_MAX];
+ nv_getgrouplist(user,group,grouplist,&n);
+ return setgroups(n,grouplist);
+}
+
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/parselib.h b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/parselib.h
new file mode 100644
index 0000000..600356d
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/parselib.h
@@ -0,0 +1,10 @@
+/* parse lib: parse mmapped text with \n terminated lines */
+
+/* a memory buffer. */
+struct state {
+ const char* buffirst; /* pointer to the buffer */
+ size_t buflen; /* length of the buffer */
+ size_t cur; /* already parsed bytes */
+};
+#include "parse_defs.h"
+#include "pw_defs.h"
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/pass_check.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/pass_check.c
new file mode 100644
index 0000000..6628e99
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/pass_check.c
@@ -0,0 +1,20 @@
+#include "str_defs.h"
+#define PASS_CHECK_C
+#include "config.h"
+
+#define del_str(X) byte_zero(X, str_len(X))
+
+int pass_check(char *buf, char *cr_ps) /*EXTRACT_INCL*/{
+ char *pass;
+ int OK = 0;
+
+ if (str_len(cr_ps) < 10) goto do_it;
+
+ pass = pass_crypt_appl(buf, cr_ps);
+ if (!str_diff(pass, cr_ps)) OK=1;
+ del_str(pass);
+
+ do_it:
+ del_str(cr_ps);
+ return OK; /* return 1 if good password */
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/prot_uidgid.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/prot_uidgid.c
new file mode 100644
index 0000000..e19e9a2
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/prot_uidgid.c
@@ -0,0 +1,11 @@
+#include <sys/types.h>
+#include <unistd.h>
+#include <grp.h>
+
+char *prot_uidgid(uid_t uid, gid_t gid, gid_t *gr_list, int len) /*EXTRACT_INCL*/{
+ char *p=0;
+ if (setgroups(len, gr_list) == -1) p = "groups";
+ else if (setgid(gid) == -1) p = "gid";
+ else if (setuid(uid) == -1) p = "uid";
+ return p;
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/read_password.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/read_password.c
new file mode 100644
index 0000000..544e636
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/read_password.c
@@ -0,0 +1,15 @@
+#include <unistd.h>
+
+int read_password(char *buf) /*EXTRACT_INCL*/{
+ int n;
+ alarm(120);
+ write(1, "Password: ", 10);
+ n = read(0, buf, 100);
+ alarm(0);
+ write(1,"\n",1);
+ if (n<0) return -1;
+ while (n && buf[n-1] == '\n') --n;
+ buf[n] = 0;
+ return 0;
+}
+
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/safe_io.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/safe_io.c
new file mode 100644
index 0000000..10d3c95
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/safe_io.c
@@ -0,0 +1,21 @@
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/types.h>
+
+#define SAFE_IO(op,F,B,L) safe_io((int (*)())(op), F,B,L) /*EXTRACT_UNMOD*/
+// #define SAFE_IO(op,F,B,L) op(F,B,L) /*EXTRACT_UNMOD*/
+
+ssize_t safe_io(int (*op)(), int fd, void *x, size_t len) /*EXTRACT_INCL*/{
+ int k = len;
+ while (k > 0) {
+ int ret = op(fd, x, k);
+ if (ret <= 0) {
+ if (ret && errno == EINTR) continue;
+ break;
+ }
+ x += ret;
+ k -= ret;
+ }
+ return len - k;
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/scan_uid.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/scan_uid.c
new file mode 100644
index 0000000..da9c85e
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/scan_uid.c
@@ -0,0 +1,14 @@
+#include <sys/types.h>
+#include "str_defs.h"
+
+unsigned int scan_uid(char *buf, char *prefix, uid_t *uid) /*EXTRACT_INCL*/{
+ int len = str_len(prefix);
+ char *p = buf + len;
+ unsigned long u;
+
+ if (str_diffn(buf,prefix,len) || !(len = scan_ulong(p, &u))) return 0;
+ p += len;
+ if (*p++ != 0) return 0;
+ *uid = u;
+ return p-buf;
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/scan_ulong.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/scan_ulong.c
new file mode 100644
index 0000000..d2a6896
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/scan_ulong.c
@@ -0,0 +1,8 @@
+unsigned int scan_ulong(register char *s, register unsigned long *u) /*EXTRACT_INCL*/ {
+ register unsigned int pos; register unsigned long result;
+ register unsigned long c;
+ pos = 0; result = 0;
+ while ((c = (unsigned long) (unsigned char) (s[pos] - '0')) < 10)
+ { result = result * 10 + c; ++pos; }
+ *u = result; return pos;
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/str_add.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/str_add.c
new file mode 100644
index 0000000..6450d90
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/str_add.c
@@ -0,0 +1,5 @@
+unsigned long str_add(char *d, const char *s, unsigned long u) /*EXTRACT_INCL*/ {
+ unsigned long l=0;
+ for (l=0; s[l] && l<u; l++) d[l] = s[l];
+ return(l);
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/str_copy.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/str_copy.c
new file mode 100644
index 0000000..90d2da6
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/str_copy.c
@@ -0,0 +1,5 @@
+unsigned int str_copy(char *out,const char *in) /*EXTRACT_INCL*/ {
+ unsigned int len=0;
+ while ((out[len]=in[len])) len++;
+ return len;
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/str_copynz.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/str_copynz.c
new file mode 100644
index 0000000..7a2c8e4
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/str_copynz.c
@@ -0,0 +1,7 @@
+#include "str_defs.h"
+
+unsigned long str_copynz(char *dest, const char *src, unsigned long n) /*EXTRACT_INCL*/ {
+ unsigned long k=str_add(dest, src, n);
+ while (k<n) dest[--n] = 0;
+ return k;
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/str_diff.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/str_diff.c
new file mode 100644
index 0000000..8e03d86
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/str_diff.c
@@ -0,0 +1,4 @@
+#include "str_defs.h"
+int str_diff(const char* a, const char* b) /*EXTRACT_INCL*/ {
+ return str_diffn(a,b,(unsigned long)(-1));
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/str_diffn.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/str_diffn.c
new file mode 100644
index 0000000..6570821
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/str_diffn.c
@@ -0,0 +1,13 @@
+#include "str_defs.h"
+
+int str_diffn(const char* a, const char* b, unsigned long limit) /*EXTRACT_INCL*/ {
+ unsigned long u=0;
+ char ch=0;
+
+ for (; u<limit; u++) {
+ ch = a[u] - b[u];
+ if (ch) break;
+ if (a[u]==0) break;
+ }
+ return ch;
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/str_len.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/str_len.c
new file mode 100644
index 0000000..76129ca
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/str_len.c
@@ -0,0 +1,5 @@
+unsigned long str_len(const char * s) /*EXTRACT_INCL*/ {
+ unsigned long len=0;
+ while (s[len]) ++len;
+ return len;
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/str_lib.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/str_lib.c
new file mode 100644
index 0000000..96f623e
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/str_lib.c
@@ -0,0 +1,6 @@
+char *strip_slash(char *s) /*EXTRACT_INCL*/ {
+ char *p, *q;
+ for (p=q=s; *p; p++)
+ if (*p == '/') q=p+1;
+ return q;
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/str_mycat.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/str_mycat.c
new file mode 100644
index 0000000..b2397e5
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/str_mycat.c
@@ -0,0 +1,9 @@
+#include "str_defs.h"
+
+unsigned long mycat(char *d, char *s1, char *s2) /*EXTRACT_INCL*/ {
+ char *p=d;
+ p += str_add(p, s1, 32);
+ p += str_add(p, s2, 240);
+ *p=0;
+ return p-d;
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/utmp_do.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/utmp_do.c
new file mode 100644
index 0000000..c820b42
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/utmp_do.c
@@ -0,0 +1,53 @@
+#include <unistd.h>
+#include <fcntl.h>
+#include <time.h>
+#include <sys/stat.h>
+#include "utmp_defs.h"
+#include "str_defs.h"
+
+#define SD(A,B) !str_diffn(A, B, sizeof(A))
+#define SC(A,B) str_copynz(A, B, sizeof(A))
+
+void utmp_do(char *username, char *line, int pid) /*EXTRACT_INCL*/{
+ off_t pos=0;
+ struct utmp u;
+ char *p;
+ int fd=open(_PATH_UTMP,O_RDWR);
+
+ while (utmp_io(fd, &u,F_RDLCK)) {
+ if (u.ut_pid == pid || SD(u.ut_line, line)) goto foundone;
+ pos += UTMP_SIZE;
+ }
+
+ byte_zero(&u,sizeof(u));
+ pos = lseek(fd,0,SEEK_END);
+ if (pos<0) pos =0;
+ pos = pos - (pos % (UTMP_SIZE));
+
+ foundone:
+ if (u.ut_id[0]==0) {
+ p=line;
+ while (str_len(p) > sizeof u.ut_id) p++;
+ SC(u.ut_id, p);
+ }
+ SC(u.ut_line, line);
+
+ SC(u.ut_user,username);
+ u.ut_type=USER_PROCESS;
+ u.ut_pid=pid;
+
+ byte_zero(u.ut_host,sizeof u.ut_host);
+ u.ut_tv.tv_sec = time(0);
+
+ if (fd>=0) {
+ if (lseek(fd,pos,SEEK_SET) == pos)
+ utmp_io(fd,&u,F_WRLCK);
+ close(fd);
+ }
+
+ fd=open(_PATH_WTMP, O_WRONLY|O_APPEND);
+ if (fd>=0) {
+ write(fd, &u, UTMP_SIZE);
+ close(fd);
+ }
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/utmp_io.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/utmp_io.c
new file mode 100644
index 0000000..ab0a6bc
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/utmp_io.c
@@ -0,0 +1,30 @@
+#include <unistd.h>
+#include <fcntl.h>
+#include <utmp.h> /*EXTRACT_UNMOD*/
+#include "utmp_defs.h"
+
+#define UTMP_SIZE (sizeof(struct utmp)) /*EXTRACT_UNMOD*/
+
+/* type: F_RDLCK or F_WRLCK */
+struct utmp *utmp_io(int fd, struct utmp *ut, int type) /*EXTRACT_INCL*/ {
+ int ret;
+ struct flock fl;
+ int (*op)() = (type==F_WRLCK) ? (int(*)())write : (int(*)())read;
+
+ fl.l_whence = SEEK_CUR;
+ fl.l_start = 0;
+ fl.l_len = UTMP_SIZE;
+ fl.l_pid = 0;
+ fl.l_type = type;
+
+ if (fcntl(fd, F_SETLKW, &fl)) return 0;
+ ret = SAFE_IO(op, fd, ut, UTMP_SIZE);
+
+ fl.l_start = -UTMP_SIZE;
+ fl.l_type = F_UNLCK;
+
+ fcntl(fd, F_SETLK, &fl);
+
+ if (ret != UTMP_SIZE) return 0;
+ return ut;
+}
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/write_devlog.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/write_devlog.c
new file mode 100644
index 0000000..103915f
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/write_devlog.c
@@ -0,0 +1,16 @@
+#include <unistd.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include "str_defs.h"
+
+void write_devlog(void *buf, int len) /*EXTRACT_INCL*/{
+ struct sockaddr_un sa;
+ int fd= socket(AF_UNIX, SOCK_DGRAM, 0);
+ if( fd == -1) return;
+ sa.sun_family = AF_UNIX;
+ str_copynz(sa.sun_path, "/dev/log", 10);
+ if (connect(fd, (struct sockaddr*)&sa, sizeof sa))
+ { close(fd); return; }
+ send(fd, buf, len, 0);
+ close(fd);
+}