+1997-06-03 23:42 Ulrich Drepper <drepper@cygnus.com>
+
+ * elf/dl-support.c: Define and initialize _dl_verbose used in
+ dl-machine.h.
+
+ * io/ftw.c: Expand stat/lstat calls.
+
+ * manual/intro.texi: Also refer to ISO 9945.
+ Update info about SVID.
+ Add description for XPG.
+
+ * md5-crypt/md5-crypt.c: Namespace cleanups.
+ * md5-crypt/md5.c: Likewise.
+ * md5-crypt/md5.h: Likewise.
+ * sysdeps/generic/crypt-entry.c: Likewise.
+
+ * posix/unistd.h (_POSIX2_C_VERSION): Set to 199209L.
+
+ * stdlib/fmtmsg.h: Declare addseverity only if __USE_SVID is
+ defined.
+
+ * sunrpc/rpc_scan.c (findkind): Declare `token' as const.
+ * sunrpc/rpc_util.c (toktostr): Declare `token' as const.
+
+ * time/Makefile: Make tzselect dependen of config.make.
+
+1997-06-01 15:01 Miles Bader <miles@gnu.ai.mit.edu>
+
+ * manual/string.texi (String and Array Utilities): Add `Argz and
+ Envz Vectors' to the menu.
+ (Argz and Envz Vectors, Argz Functions, Envz Functions): New nodes.
+
+1997-05-31 20:59 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
+
+ * login/Makefile (utmpd-routines): Add utmpd.
+ (extra-objs): Add utmpd objects to get dependencies.
+ (distribute): Add sources for utmpd.
+ (subdir-dirs): Define.
+
+1997-06-02 16:28 Ulrich Drepper <drepper@cygnus.com>
+
+ * sysdeps/wordsize-32/inttypes.h: Include features.h and use
+ __CONCAT instead of defined __CONCAT__ ourself.
+ * sysdeps/wordsize-64/inttypes.h: Likewise.
+
+1997-06-01 19:11 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
+
+ * sysdeps/wordsize-64/inttypes.h (INTMAX_C): Use `l' suffix, not
+ `ll'.
+ (PRIdFAST, PRIoFAST, PRIxFAST, PRIuFAST, SCNdFAST, SCNiFAST,
+ SCNoFAST, SCNxFAST): Correct format specifiers.
+
+1997-06-02 04:23 Ulrich Drepper <drepper@cygnus.com>
+
+ * sysdeps/unix/syscalls.list: Make fchdir weak alias for __fchdir.
+
+1997-06-01 19:17 Ulrich Drepper <drepper@cygnus.com>
+
+ * md5-crypt/Makefile: Correct libmd5crypt file to really generate
+ DES free libcrypt.
+ * md5-crypt/onlymd5-entry.c: New file. Wrapper around
+ sysdeps/generic/crypt-entry.c.
+
+1997-06-01 12:48 Ulrich Drepper <drepper@cygnus.com>
+
+ * sysdeps/unix/sysv/linux/alpha/gnu/types.h (__fd_mask): Change
+ type to `unsigned long int'.
+ Patch by Richard Henderson <richard@twiddle.rth.home>.
+
+1997-05-30 17:34 Andreas Jaeger <aj@arthur.rhein-neckar.de>
+
+ * sysdeps/generic/bb_init_func.c (__bb_init_func): Use ISO C
+ declaration style.
+
+ * nss/nss_files/files-hosts.c: Delete inclusion of
+ "../resolv/mapv4v6hostent.h".
+
1997-05-31 02:33 Ulrich Drepper <drepper@cygnus.com>
* io/ftwtest-sh: More tests.
/* This file defines some things that for the dynamic linker are defined in
rtld.c and dl-sysdep.c in ways appropriate to bootstrap dynamic linking. */
+#include <stdlib.h>
+
+
extern char *__progname;
char **_dl_argv = &__progname; /* This is checked for some error messages. */
/* This defines the default search path for libraries.
For the dynamic linker it is set by -rpath when linking. */
const char *_dl_rpath = DEFAULT_RPATH;
+
+/* If nonzero print warnings about problematic situations. */
+int _dl_verbose;
+
+
+static void init_verbose (void) __attribute__ ((unused));
+
+static void
+init_verbose (void)
+{
+ _dl_verbose = *(getenv ("LD_WARN") ?: "") == '\0' ? 0 : 1;
+}
+text_set_element (__libc_subinit, init_verbose);
memcpy (data->dirbuf + data->ftw.base, name, namlen);
data->dirbuf[data->ftw.base + namlen] = '\0';
- if (((data->flags & FTW_PHYS) ? lstat : stat) (data->dirbuf, &st) < 0)
+ if (((data->flags & FTW_PHYS)
+ ? __lxstat (_STAT_VER, data->dirbuf, &st)
+ : __xstat (_STAT_VER, data->dirbuf, &st)) < 0)
{
if (errno != EACCES && errno != ENOENT)
result = -1;
else if (!(data->flags & FTW_PHYS)
- && lstat (data->dirbuf, &st) == 0
+ && __lxstat (_STAT_VER, data->dirbuf, &st) == 0
&& S_ISLNK (st.st_mode))
flag = FTW_SLN;
else
}
if (result == 0
- && (!(data->flags & FTW_MOUNT) || flag == FTW_NS
- || st.st_dev == data->dev))
+ && (flag == FTW_NS
+ || !(data->flags & FTW_MOUNT) || st.st_dev == data->dev))
{
if ((data->flags & FTW_PHYS) || flag == FTW_NS
|| (!find_object (data, &st)
/* Change back to current directory. */
int done = 0;
if (dir->stream != NULL)
- if (fchdir (dirfd (dir->stream)) == 0)
+ if (__fchdir (dirfd (dir->stream)) == 0)
done = 1;
if (!done)
/* If necessary, change to this directory. */
if (data->flags & FTW_CHDIR)
{
- if (fchdir (dirfd (dir.stream)) < 0)
+ if (__fchdir (dirfd (dir.stream)) < 0)
{
if (errno == ENOSYS)
{
/* Get stat info for start directory. */
if (result == 0)
- if (((flags & FTW_PHYS) ? lstat : stat) (data.dirbuf, &st) < 0)
+ if (((flags & FTW_PHYS)
+ ? __lxstat (_STAT_VER, data.dirbuf, &st)
+ : __xstat (_STAT_VER, data.dirbuf, &st)) < 0)
{
if (errno == EACCES)
result = (*data.func) (data.dirbuf, &st, FTW_NS, &data.ftw);
else if (!(flags & FTW_PHYS)
&& errno == ENOENT
- && lstat (dir, &st) == 0 && S_ISLNK (st.st_mode))
+ && __lxstat (_STAT_VER, dir, &st) == 0
+ && S_ISLNK (st.st_mode))
result = (*data.func) (data.dirbuf, &st, data.cvt_arr[FTW_SLN],
&data.ftw);
else
--- /dev/null
+escape_char /
+comment_char %
+%
+% Czech Language Locale for Czech
+% Source:
+% Address: U ¹koly 292 Without diactitical chars: U skoly 292
+% 783 72 Velký Týnec 782 72 Velky Tynec
+% Contact: Vladimir Michl
+% Email: Vladimir.Michl@upol.cz
+% Tel:
+% Fax:
+% Language: cs
+% Territory: CZ
+% Revision: 1.01
+% Date: 1997-01-17
+% Application: general
+% Users: general
+% Repertoiremap: mnemonic.ds
+% Charset: ISO_8859-2:1987
+% Distribution and use is free, also
+% for commercial purposes.
+
+% zpracovánÃ:
+%% localedef -c -i <tento-soubor> -f "ISO_8859-2:1987" 'cs_CZ.ISO-8859-2'
+%% pokud se podaøà odstranit chyby, lze -c vynechat.
+
+%% pro úspì¹né pøelo¾enà je tøeba mÃt kolekci lokalizacà WG15collection.
+%% Tuto rozbalit do adresáøe
+%% /usr/share/i18n
+%% Lokalizace se pak budou tvoøit v adresáøi /usr/share/locale
+
+%% Také je dobré do souboru /usr/share/locale/locale.alias napsat tyto øádky
+%% cz cs_CZ.ISO88592
+%% cs cs_CZ.ISO88592
+%% czech cs_CZ.ISO88592
+
+
+%% Poøadà znakù
+%% Mo¾ná jsou nìkteré akcentované znaky jinak ne¾ by mìly být,
+%% zkuste zkontrolovat a pøÃpadné vylep¹enà mi poslat.
+%% ----------------------------------------------------------
+
+LC_COLLATE
+% Definice pÃsmene ch
+collating-element <c-h> from "<c><h>"
+collating-element <C-h> from "<C><h>"
+collating-element <C-H> from "<C><H>"
+
+collating-symbol <CAPITAL>
+collating-symbol <SMALL>
+
+collating-symbol <NONE>
+collating-symbol <ACUTE>
+%collating-symbol <GRAVE>
+%collating-symbol <DOUBLE-GRAVE>
+collating-symbol <BREVE>
+collating-symbol <CIRCUMFLEX>
+collating-symbol <CARON>
+collating-symbol <RING>
+collating-symbol <DIAERESIS>
+collating-symbol <DOUBLE-ACUTE>
+%collating-symbol <TILDE>
+collating-symbol <DOT>
+collating-symbol <STROKE>
+collating-symbol <CEDILLA>
+collating-symbol <OGONEK>
+
+order_start forward;backward/
+ ;forward;position
+
+<CAPITAL>
+<SMALL>
+
+<NONE>
+<ACUTE>
+<CARON>
+<RING>
+%<GRAVE>
+%<DOUBLE-GRAVE>
+<BREVE>
+<CIRCUMFLEX>
+<DIAERESIS>
+<DOUBLE-ACUTE>
+%<TILDE>
+<DOT>
+<STROKE>
+<CEDILLA>
+<OGONEK>
+
+%
+<NS> <NS>;<NS>;<NS>;IGNORE
+<SP> IGNORE;IGNORE;IGNORE;<SP>
+<HT> IGNORE;IGNORE;IGNORE;<HT>
+<VT> IGNORE;IGNORE;IGNORE;<VT>
+<CR> IGNORE;IGNORE;IGNORE;<CR>
+<LF> IGNORE;IGNORE;IGNORE;<LF>
+<FF> IGNORE;IGNORE;IGNORE;<FF>
+<_> IGNORE;IGNORE;IGNORE;<_>
+<--> IGNORE;IGNORE;IGNORE;<-->
+<-> IGNORE;IGNORE;IGNORE;<->
+<,> IGNORE;IGNORE;IGNORE;<,>
+<;> IGNORE;IGNORE;IGNORE;<;>
+<:> IGNORE;IGNORE;IGNORE;<:>
+<!> IGNORE;IGNORE;IGNORE;<!>
+<?> IGNORE;IGNORE;IGNORE;<?>
+<//> IGNORE;IGNORE;IGNORE;<//>
+<.> IGNORE;IGNORE;IGNORE;<.>
+<''> IGNORE;IGNORE;IGNORE;<''>
+<'!> IGNORE;IGNORE;IGNORE;<'!>
+<'/>> IGNORE;IGNORE;IGNORE;<'/>>
+<':> IGNORE;IGNORE;IGNORE;<':>
+<'?> IGNORE;IGNORE;IGNORE;<'?>
+<',> IGNORE;IGNORE;IGNORE;<',>
+<'> IGNORE;IGNORE;IGNORE;<'>
+<"> IGNORE;IGNORE;IGNORE;<">
+<(> IGNORE;IGNORE;IGNORE;<(>
+<)> IGNORE;IGNORE;IGNORE;<)>
+<<(> IGNORE;IGNORE;IGNORE;<<(>
+<)/>> IGNORE;IGNORE;IGNORE;<)/>>
+<(!> IGNORE;IGNORE;IGNORE;<(!>
+<!)> IGNORE;IGNORE;IGNORE;<!)>
+<SE> IGNORE;IGNORE;IGNORE;<SE>
+<At> IGNORE;IGNORE;IGNORE;<At>
+<Cu> IGNORE;IGNORE;IGNORE;<Cu>
+<DO> IGNORE;IGNORE;IGNORE;<DO>
+<*> IGNORE;IGNORE;IGNORE;<*>
+<////> IGNORE;IGNORE;IGNORE;<////>
+<&> IGNORE;IGNORE;IGNORE;<&>
+<Nb> IGNORE;IGNORE;IGNORE;<Nb>
+<%> IGNORE;IGNORE;IGNORE;<%>
+<+> IGNORE;IGNORE;IGNORE;<+>
+<-:> IGNORE;IGNORE;IGNORE;<-:>
+<*X> IGNORE;IGNORE;IGNORE;<*X>
+<<> IGNORE;IGNORE;IGNORE;<<>
+<=> IGNORE;IGNORE;IGNORE;<=>
+</>> IGNORE;IGNORE;IGNORE;</>>
+<!!> IGNORE;IGNORE;IGNORE;<!!>
+<DG> IGNORE;IGNORE;IGNORE;<DG>
+<'<> IGNORE;IGNORE;IGNORE;<'<>
+<'(> IGNORE;IGNORE;IGNORE;<'(>
+<'.> IGNORE;IGNORE;IGNORE;<'.>
+<'0> IGNORE;IGNORE;IGNORE;<'0>
+<';> IGNORE;IGNORE;IGNORE;<';>
+<'"> IGNORE;IGNORE;IGNORE;<'">
+<NU> IGNORE;IGNORE;IGNORE;<NU>
+<SH> IGNORE;IGNORE;IGNORE;<SH>
+<SX> IGNORE;IGNORE;IGNORE;<SX>
+<EX> IGNORE;IGNORE;IGNORE;<EX>
+<ET> IGNORE;IGNORE;IGNORE;<ET>
+<EQ> IGNORE;IGNORE;IGNORE;<EQ>
+<AK> IGNORE;IGNORE;IGNORE;<AK>
+<BL> IGNORE;IGNORE;IGNORE;<BL>
+<BS> IGNORE;IGNORE;IGNORE;<BS>
+<SO> IGNORE;IGNORE;IGNORE;<SO>
+<SI> IGNORE;IGNORE;IGNORE;<SI>
+<DL> IGNORE;IGNORE;IGNORE;<DL>
+<D1> IGNORE;IGNORE;IGNORE;<D1>
+<D2> IGNORE;IGNORE;IGNORE;<D2>
+<D3> IGNORE;IGNORE;IGNORE;<D3>
+<D4> IGNORE;IGNORE;IGNORE;<D4>
+<NK> IGNORE;IGNORE;IGNORE;<NK>
+<SY> IGNORE;IGNORE;IGNORE;<SY>
+<EB> IGNORE;IGNORE;IGNORE;<EB>
+<CN> IGNORE;IGNORE;IGNORE;<CN>
+<EM> IGNORE;IGNORE;IGNORE;<EM>
+<SB> IGNORE;IGNORE;IGNORE;<SB>
+<EC> IGNORE;IGNORE;IGNORE;<EC>
+<FS> IGNORE;IGNORE;IGNORE;<FS>
+<GS> IGNORE;IGNORE;IGNORE;<GS>
+<RS> IGNORE;IGNORE;IGNORE;<RS>
+<US> IGNORE;IGNORE;IGNORE;<US>
+<DT> IGNORE;IGNORE;IGNORE;<DT>
+<PA> IGNORE;IGNORE;IGNORE;<PA>
+<HO> IGNORE;IGNORE;IGNORE;<HO>
+<BH> IGNORE;IGNORE;IGNORE;<BH>
+<NH> IGNORE;IGNORE;IGNORE;<NH>
+<IN> IGNORE;IGNORE;IGNORE;<IN>
+<NL> IGNORE;IGNORE;IGNORE;<NL>
+<SA> IGNORE;IGNORE;IGNORE;<SA>
+<ES> IGNORE;IGNORE;IGNORE;<ES>
+<HS> IGNORE;IGNORE;IGNORE;<HS>
+<HJ> IGNORE;IGNORE;IGNORE;<HJ>
+<VS> IGNORE;IGNORE;IGNORE;<VS>
+<PD> IGNORE;IGNORE;IGNORE;<PD>
+<PU> IGNORE;IGNORE;IGNORE;<PU>
+<RI> IGNORE;IGNORE;IGNORE;<RI>
+<S2> IGNORE;IGNORE;IGNORE;<S2>
+<S3> IGNORE;IGNORE;IGNORE;<S3>
+<DC> IGNORE;IGNORE;IGNORE;<DC>
+<P1> IGNORE;IGNORE;IGNORE;<P1>
+<P2> IGNORE;IGNORE;IGNORE;<P2>
+<TS> IGNORE;IGNORE;IGNORE;<TS>
+<CC> IGNORE;IGNORE;IGNORE;<CC>
+<MW> IGNORE;IGNORE;IGNORE;<MW>
+<SG> IGNORE;IGNORE;IGNORE;<SG>
+<EG> IGNORE;IGNORE;IGNORE;<EG>
+<SS> IGNORE;IGNORE;IGNORE;<SS>
+<GC> IGNORE;IGNORE;IGNORE;<GC>
+<SC> IGNORE;IGNORE;IGNORE;<SC>
+<CI> IGNORE;IGNORE;IGNORE;<CI>
+<ST> IGNORE;IGNORE;IGNORE;<ST>
+<OC> IGNORE;IGNORE;IGNORE;<OC>
+<PM> IGNORE;IGNORE;IGNORE;<PM>
+<AC> IGNORE;IGNORE;IGNORE;<AC>
+UNDEFINED IGNORE;IGNORE;IGNORE
+
+<0> <0>;<0>;IGNORE;IGNORE
+<1> <1>;<1>;IGNORE;IGNORE
+<2> <2>;<2>;IGNORE;IGNORE
+<3> <3>;<3>;IGNORE;IGNORE
+<4> <4>;<4>;IGNORE;IGNORE
+<5> <5>;<5>;IGNORE;IGNORE
+<6> <6>;<6>;IGNORE;IGNORE
+<7> <7>;<7>;IGNORE;IGNORE
+<8> <8>;<8>;IGNORE;IGNORE
+<9> <9>;<9>;IGNORE;IGNORE
+
+<A> <A>;<NONE>;<CAPITAL>;IGNORE
+<a> <A>;<NONE>;<SMALL>;IGNORE
+<A'> <A>;<ACUTE>;<CAPITAL>;IGNORE
+<a'> <A>;<ACUTE>;<SMALL>;IGNORE
+<A(> <A>;<BREVE>;<CAPITAL>;IGNORE
+<a(> <A>;<BREVE>;<SMALL>;IGNORE
+<A/>> <A>;<CIRCUMFLEX>;<CAPITAL>;IGNORE
+<a/>> <A>;<CIRCUMFLEX>;<SMALL>;IGNORE
+<A:> <A>;<DIAERESIS>;<CAPITAL>;IGNORE
+<a:> <A>;<DIAERESIS>;<SMALL>;IGNORE
+<A;> <A>;<OGONEK>;<CAPITAL>;IGNORE
+<a;> <A>;<OGONEK>;<SMALL>;IGNORE
+
+<B> <B>;<NONE>;<CAPITAL>;IGNORE
+<b> <B>;<NONE>;<SMALL>;IGNORE
+
+<C> <C>;<NONE>;<CAPITAL>;IGNORE
+<c> <C>;<NONE>;<SMALL>;IGNORE
+<C<> <C>;<CARON>;<CAPITAL>;IGNORE
+<c<> <C>;<CARON>;<SMALL>;IGNORE
+<C'> <C>;<ACUTE>;<CAPITAL>;IGNORE
+<c'> <C>;<ACUTE>;<SMALL>;IGNORE
+<C,> <C>;<CEDILLA>;<CAPITAL>;IGNORE
+<c,> <C>;<CEDILLA>;<SMALL>;IGNORE
+
+<D> <D>;<NONE>;<CAPITAL>;IGNORE
+<d> <D>;<NONE>;<SMALL>;IGNORE
+<D<> <D>;<CARON>;<CAPITAL>;IGNORE
+<d<> <D>;<CARON>;<SMALL>;IGNORE
+<D//> <D>;<STROKE>;<CAPITAL>;IGNORE
+<d//> <D>;<STROKE>;<SMALL>;IGNORE
+
+<E> <E>;<NONE>;<CAPITAL>;IGNORE
+<e> <E>;<NONE>;<SMALL>;IGNORE
+<E'> <E>;<ACUTE>;<CAPITAL>;IGNORE
+<e'> <E>;<ACUTE>;<SMALL>;IGNORE
+<E<> <E>;<CARON>;<CAPITAL>;IGNORE
+<e<> <E>;<CARON>;<SMALL>;IGNORE
+<E:> <E>;<DIAERESIS>;<CAPITAL>;IGNORE
+<e:> <E>;<DIAERESIS>;<SMALL>;IGNORE
+<E;> <E>;<OGONEK>;<CAPITAL>;IGNORE
+<e;> <E>;<OGONEK>;<SMALL>;IGNORE
+
+<F> <F>;<NONE>;<CAPITAL>;IGNORE
+<f> <F>;<NONE>;<SMALL>;IGNORE
+
+<G> <G>;<NONE>;<CAPITAL>;IGNORE
+<g> <G>;<NONE>;<SMALL>;IGNORE
+
+<H> <H>;<NONE>;<CAPITAL>;IGNORE
+<h> <H>;<NONE>;<SMALL>;IGNORE
+
+<C-H> <C-H>;<NONE>;<CAPITAL>;IGNORE
+<C-h> <C-h>;<NONE>;<CAPITAL>;IGNORE
+<c-h> <c-h>;<NONE>;<SMALL>;IGNORE
+
+<I> <I>;<NONE>;<CAPITAL>;IGNORE
+<i> <I>;<NONE>;<SMALL>;IGNORE
+<I'> <I>;<ACUTE>;<CAPITAL>;IGNORE
+<i'> <I>;<ACUTE>;<SMALL>;IGNORE
+<I/>> <I>;<CIRCUMFLEX>;<CAPITAL>;IGNORE
+<i/>> <I>;<CIRCUMFLEX>;<SMALL>;IGNORE
+
+<J> <J>;<NONE>;<CAPITAL>;IGNORE
+<j> <J>;<NONE>;<SMALL>;IGNORE
+
+<K> <K>;<NONE>;<CAPITAL>;IGNORE
+<k> <K>;<NONE>;<SMALL>;IGNORE
+
+<L> <L>;<NONE>;<CAPITAL>;IGNORE
+<l> <L>;<NONE>;<SMALL>;IGNORE
+<L'> <L>;<ACUTE>;<CAPITAL>;IGNORE
+<l'> <L>;<ACUTE>;<SMALL>;IGNORE
+<L<> <L>;<CARON>;<CAPITAL>;IGNORE
+<l<> <L>;<CARON>;<SMALL>;IGNORE
+<L//> <L>;<STROKE>;<CAPITAL>;IGNORE
+<l//> <L>;<STROKE>;<SMALL>;IGNORE
+
+<M> <M>;<NONE>;<CAPITAL>;IGNORE
+<m> <M>;<NONE>;<SMALL>;IGNORE
+
+<N> <N>;<NONE>;<CAPITAL>;IGNORE
+<n> <N>;<NONE>;<SMALL>;IGNORE
+<N<> <N>;<CARON>;<CAPITAL>;IGNORE
+<n<> <N>;<CARON>;<SMALL>;IGNORE
+<N'> <N>;<ACUTE>;<CAPITAL>;IGNORE
+<n'> <N>;<ACUTE>;<SMALL>;IGNORE
+
+<O> <O>;<NONE>;<CAPITAL>;IGNORE
+<o> <O>;<NONE>;<SMALL>;IGNORE
+<O'> <O>;<ACUTE>;<CAPITAL>;IGNORE
+<o'> <O>;<ACUTE>;<SMALL>;IGNORE
+<O/>> <O>;<CIRCUMFLEX>;<CAPITAL>;IGNORE
+<o/>> <O>;<CIRCUMFLEX>;<SMALL>;IGNORE
+<O:> <O>;<DIAERESIS>;<CAPITAL>;IGNORE
+<o:> <O>;<DIAERESIS>;<SMALL>;IGNORE
+<O"> <O>;<DOUBLE-ACUTE>;<CAPITAL>;IGNORE
+<o"> <O>;<DOUBLE-ACUTE>;<SMALL>;IGNORE
+
+<P> <P>;<NONE>;<CAPITAL>;IGNORE
+<p> <P>;<NONE>;<SMALL>;IGNORE
+
+<Q> <Q>;<NONE>;<CAPITAL>;IGNORE
+<q> <Q>;<NONE>;<SMALL>;IGNORE
+
+<R> <R>;<NONE>;<CAPITAL>;IGNORE
+<r> <R>;<NONE>;<SMALL>;IGNORE
+<R<> <R>;<CARON>;<CAPITAL>;IGNORE
+<r<> <R>;<CARON>;<SMALL>;IGNORE
+<R'> <R>;<ACUTE>;<CAPITAL>;IGNORE
+<r'> <R>;<ACUTE>;<SMALL>;IGNORE
+
+<S> <S>;<NONE>;<CAPITAL>;IGNORE
+<s> <S>;<NONE>;<SMALL>;IGNORE
+<S<> <S>;<CARON>;<CAPITAL>;IGNORE
+<s<> <S>;<CARON>;<SMALL>;IGNORE
+<S'> <S>;<ACUTE>;<CAPITAL>;IGNORE
+<s'> <S>;<ACUTE>;<SMALL>;IGNORE
+<S,> <S>;<CEDILLA>;<CAPITAL>;IGNORE
+<s,> <S>;<CEDILLA>;<SMALL>;IGNORE
+
+<T> <T>;<NONE>;<CAPITAL>;IGNORE
+<t> <T>;<NONE>;<SMALL>;IGNORE
+<T<> <T>;<CARON>;<CAPITAL>;IGNORE
+<t<> <T>;<CARON>;<SMALL>;IGNORE
+<T,> <T>;<CEDILLA>;<CAPITAL>;IGNORE
+<t,> <T>;<CEDILLA>;<SMALL>;IGNORE
+
+<U> <U>;<NONE>;<CAPITAL>;IGNORE
+<u> <U>;<NONE>;<SMALL>;IGNORE
+<U'> <U>;<ACUTE>;<CAPITAL>;IGNORE
+<u'> <U>;<ACUTE>;<SMALL>;IGNORE
+<U0> <U>;<RING>;<CAPITAL>;IGNORE
+<u0> <U>;<RING>;<SMALL>;IGNORE
+<U:> <U>;<DIAERESIS>;<CAPITAL>;IGNORE
+<u:> <U>;<DIAERESIS>;<SMALL>;IGNORE
+<U"> <U>;<DOUBLE-ACUTE>;<CAPITAL>;IGNORE
+<u"> <U>;<DOUBLE-ACUTE>;<SMALL>;IGNORE
+
+<V> <V>;<NONE>;<CAPITAL>;IGNORE
+<v> <V>;<NONE>;<SMALL>;IGNORE
+
+<W> <W>;<NONE>;<CAPITAL>;IGNORE
+<w> <W>;<NONE>;<SMALL>;IGNORE
+
+<X> <X>;<NONE>;<CAPITAL>;IGNORE
+<x> <X>;<NONE>;<SMALL>;IGNORE
+
+<Y> <Y>;<NONE>;<CAPITAL>;IGNORE
+<y> <Y>;<NONE>;<SMALL>;IGNORE
+<Y'> <Y>;<ACUTE>;<CAPITAL>;IGNORE
+<y'> <Y>;<ACUTE>;<SMALL>;IGNORE
+
+<Z> <Z>;<NONE>;<CAPITAL>;IGNORE
+<z> <Z>;<NONE>;<SMALL>;IGNORE
+<Z<> <Z>;<CARON>;<CAPITAL>;IGNORE
+<z<> <Z>;<CARON>;<SMALL>;IGNORE
+<Z'> <Z>;<ACUTE>;<CAPITAL>;IGNORE
+<z'> <Z>;<ACUTE>;<SMALL>;IGNORE
+<Z.> <Z>;<DOT>;<CAPITAL>;IGNORE
+<z.> <Z>;<DOT>;<SMALL>;IGNORE
+
+order_end
+
+END LC_COLLATE
+
+% Definice typù znakù
+
+LC_CTYPE
+
+digit <0>;<1>;<2>;<3>;<4>;/
+ <5>;<6>;<7>;<8>;<9>
+
+xdigit <0>;<1>;<2>;<3>;<4>;/
+ <5>;<6>;<7>;<8>;<9>;/
+ <a>;...;<f>;/
+ <A>;...;<F>
+
+punct <!>;...;<//>;/
+ <:>;...;<At>;/
+ <<(>;...;<'!>;/
+ <(!>;...;<'?>;/
+ <'(>;<Cu>;<SE>;<':>;/
+ <-->;<DG>;<';>;<''>;/
+ <'<>;<',>;<'">;<*X>;/
+ <-:>;<'.>
+
+blank <SP>;<HT>;<NS>
+
+space <SP>;<LF>;<VT>;<FF>;/
+ <CR>;<HT>;<NS>
+
+cntrl <NU>;<SH>;<SX>;<EX>;<ET>;<EQ>;/
+ <AK>;<BL>;<BS>;<HT>;<LF>;<VT>;/
+ <FF>;<CR>;<SO>;<SI>;<DL>;<D1>;/
+ <D2>;<D3>;<D4>;<NK>;<SY>;<EB>;/
+ <CN>;<EM>;<SB>;<EC>;<FS>;<GS>;/
+ <RS>;<US>;<DT>;<PA>;<HO>;<BH>;/
+ <NH>;<IN>;<NL>;<SA>;<ES>;<HS>;/
+ <HJ>;<VS>;<PD>;<PU>;<RI>;<S2>;/
+ <S3>;<DC>;<P1>;<P2>;<TS>;<CC>;/
+ <MW>;<SG>;<EG>;<SS>;<GC>;<SC>;/
+ <CI>;<ST>;<OC>;<PM>;<AC>
+
+alpha <A>;...;<Z>;/
+ <A;>;/
+ <L//>;/
+ <L<>;/
+ <S'>;/
+ <S<>;/
+ <S,>;/
+ <T<>;/
+ <Z'>;/
+ <Z<>;/
+ <Z.>;/
+ <R'>;/
+ <A'>;/
+ <A/>>;/
+ <A(>;/
+ <A:>;/
+ <L'>;/
+ <C'>;/
+ <C,>;/
+ <C<>;/
+ <E'>;/
+ <E;>;/
+ <E:>;/
+ <E<>;/
+ <I'>;/
+ <I/>>;/
+ <D<>;/
+ <D//>;/
+ <N'>;/
+ <N<>;/
+ <O'>;/
+ <O/>>;/
+ <O">;/
+ <O:>;/
+ <R<>;/
+ <U0>;/
+ <U'>;/
+ <U">;/
+ <U:>;/
+ <Y'>;/
+ <T,>;/
+ <a>;...;<z>;/
+ <a;>;/
+ <l//>;/
+ <l<>;/
+ <s'>;/
+ <s<>;/
+ <s,>;/
+ <t<>;/
+ <z'>;/
+ <z<>;/
+ <z.>;/
+ <ss>;/
+ <r'>;/
+ <a'>;/
+ <a/>>;/
+ <a(>;/
+ <a:>;/
+ <l'>;/
+ <c'>;/
+ <c,>;/
+ <c<>;/
+ <e'>;/
+ <e;>;/
+ <e:>;/
+ <e<>;/
+ <i'>;/
+ <i/>>;/
+ <d<>;/
+ <d//>;/
+ <n'>;/
+ <n<>;/
+ <o'>;/
+ <o/>>;/
+ <o">;/
+ <o:>;/
+ <r<>;/
+ <u0>;/
+ <u'>;/
+ <u">;/
+ <u:>;/
+ <y'>;/
+ <t,>
+
+upper <A>;...;<Z>;/
+ <A;>;/
+ <L//>;/
+ <L<>;/
+ <S'>;/
+ <S<>;/
+ <S,>;/
+ <T<>;/
+ <Z'>;/
+ <Z<>;/
+ <Z.>;/
+ <R'>;/
+ <A'>;/
+ <A/>>;/
+ <A(>;/
+ <A:>;/
+ <L'>;/
+ <C'>;/
+ <C,>;/
+ <C<>;/
+ <E'>;/
+ <E;>;/
+ <E:>;/
+ <E<>;/
+ <I'>;/
+ <I/>>;/
+ <D<>;/
+ <D//>;/
+ <N'>;/
+ <N<>;/
+ <O'>;/
+ <O/>>;/
+ <O">;/
+ <O:>;/
+ <R<>;/
+ <U0>;/
+ <U'>;/
+ <U">;/
+ <U:>;/
+ <Y'>;/
+ <T,>
+
+lower <a>;...;<z>;/
+ <a;>;/
+ <l//>;/
+ <l<>;/
+ <s'>;/
+ <s<>;/
+ <s,>;/
+ <t<>;/
+ <z'>;/
+ <z<>;/
+ <z.>;/
+ <ss>;/
+ <r'>;/
+ <a'>;/
+ <a/>>;/
+ <a(>;/
+ <a:>;/
+ <l'>;/
+ <c'>;/
+ <c,>;/
+ <c<>;/
+ <e'>;/
+ <e;>;/
+ <e:>;/
+ <e<>;/
+ <i'>;/
+ <i/>>;/
+ <d<>;/
+ <d//>;/
+ <n'>;/
+ <n<>;/
+ <o'>;/
+ <o/>>;/
+ <o">;/
+ <o:>;/
+ <r<>;/
+ <u0>;/
+ <u'>;/
+ <u">;/
+ <u:>;/
+ <y'>;/
+ <t,>
+
+
+toupper (<a>,<A>);(<b>,<B>);(<c>,<C>);(<d>,<D>);(<e>,<E>);(<f>,<F>);/
+ (<g>,<G>);(<h>,<H>);(<i>,<I>);(<j>,<J>);(<k>,<K>);(<l>,<L>);/
+ (<m>,<M>);(<n>,<N>);(<o>,<O>);(<p>,<P>);(<q>,<Q>);(<r>,<R>);/
+ (<s>,<S>);(<t>,<T>);(<u>,<U>);(<v>,<V>);(<w>,<W>);(<x>,<X>);/
+ (<y>,<Y>);(<z>,<Z>);/
+ (<a;>,<A;>);/
+ (<l//>,<L//>);/
+ (<l<>,<L<>);/
+ (<s'>,<S'>);/
+ (<s<>,<S<>);/
+ (<s,>,<S,>);/
+ (<t<>,<T<>);/
+ (<z'>,<Z'>);/
+ (<z<>,<Z<>);/
+ (<z.>,<Z.>);/
+ (<r'>,<R'>);/
+ (<a'>,<A'>);/
+ (<a/>>,<A/>>);/
+ (<a(>,<A(>);/
+ (<a:>,<A:>);/
+ (<l'>,<L'>);/
+ (<c'>,<C'>);/
+ (<c,>,<C,>);/
+ (<c<>,<C<>);/
+ (<e'>,<E'>);/
+ (<e;>,<E;>);/
+ (<e:>,<E:>);/
+ (<e<>,<E<>);/
+ (<i'>,<I'>);/
+ (<i/>>,<I/>>);/
+ (<d<>,<D<>);/
+ (<d//>,<D//>);/
+ (<n'>,<N'>);/
+ (<n<>,<N<>);/
+ (<o'>,<O'>);/
+ (<o/>>,<O/>>);/
+ (<o">,<O">);/
+ (<o:>,<O:>);/
+ (<r<>,<R<>);/
+ (<u0>,<U0>);/
+ (<u'>,<U'>);/
+ (<u">,<U">);/
+ (<u:>,<U:>);/
+ (<y'>,<Y'>);/
+ (<t,>,<T,>)
+
+tolower (<A>,<a>);(<B>,<b>);(<C>,<c>);(<D>,<d>);(<E>,<e>);(<F>,<f>);/
+ (<G>,<g>);(<H>,<h>);(<I>,<i>);(<J>,<j>);(<K>,<k>);(<L>,<l>);/
+ (<M>,<m>);(<N>,<n>);(<O>,<o>);(<P>,<p>);(<Q>,<q>);(<R>,<r>);/
+ (<S>,<s>);(<T>,<t>);(<U>,<u>);(<V>,<v>);(<W>,<w>);(<X>,<x>);/
+ (<Y>,<y>);(<Z>,<z>);/
+ (<A;>,<a;>);/
+ (<L//>,<l//>);/
+ (<L<>,<l<>);/
+ (<S'>,<s'>);/
+ (<S<>,<s<>);/
+ (<S,>,<s,>);/
+ (<T<>,<t<>);/
+ (<Z'>,<z'>);/
+ (<Z<>,<z<>);/
+ (<Z.>,<z.>);/
+ (<R'>,<r'>);/
+ (<A'>,<a'>);/
+ (<A/>>,<a/>>);/
+ (<A(>,<a(>);/
+ (<A:>,<a:>);/
+ (<L'>,<l'>);/
+ (<C'>,<c'>);/
+ (<C,>,<c,>);/
+ (<C<>,<c<>);/
+ (<E'>,<e'>);/
+ (<E;>,<e;>);/
+ (<E:>,<e:>);/
+ (<E<>,<e<>);/
+ (<I'>,<i'>);/
+ (<I/>>,<i/>>);/
+ (<D<>,<d<>);/
+ (<D//>,<d//>);/
+ (<N'>,<n'>);/
+ (<N<>,<n<>);/
+ (<O'>,<o'>);/
+ (<O/>>,<o/>>);/
+ (<O">,<o">);/
+ (<O:>,<o:>);/
+ (<R<>,<r<>);/
+ (<u0>,<U0>);/
+ (<U'>,<u'>);/
+ (<U">,<u">);/
+ (<U:>,<u:>);/
+ (<Y'>,<y'>);/
+ (<T,>,<t,>)
+
+END LC_CTYPE
+
+%% LC_MESSAGES
+%% ekvivalenty yes/no
+%% -------------------------
+
+LC_MESSAGES
+
+yesexpr "<<(><a><A><y><Y><)/>><.><*>"
+noexpr "<<(><n><N><)/>><.><*>"
+yesstr "<a><n><o>"
+nostr "<n><e>"
+
+END LC_MESSAGES
+
+%% LC_MONETARY -- jde jen o penÃze
+%% -------------------------------------------------
+
+LC_MONETARY
+
+int_curr_symbol "<C><Z><K><SP>"
+currency_symbol "<K><c<>"
+mon_decimal_point "<,>"
+mon_thousands_sep "<SP>"
+mon_grouping 3;3
+positive_sign ""
+negative_sign "<->"
+int_frac_digits 2
+frac_digits 2
+p_cs_precedes 0
+p_sep_by_space 1
+n_cs_precedes 0
+n_sep_by_space 1
+p_sign_posn 1
+n_sign_posn 1
+
+END LC_MONETARY
+
+%% O èÃslech
+%% --------------
+
+LC_NUMERIC
+
+decimal_point "<,>"
+thousands_sep "<SP>"
+grouping 3;3
+
+END LC_NUMERIC
+
+%% Èas
+
+LC_TIME
+
+abday "<N><e>";/
+ "<P><o>";/
+ "<U'><t>";/
+ "<S><t>";/
+ "<C<><t>";/
+ "<P><a'>";/
+ "<S><o>"
+
+day "<N><e><d><e<><l><e>";/
+ "<P><o><n><d<><e><l><i'>";/
+ "<U'><t><e><r><y'>";/
+ "<S><t><r<><e><d><a>";/
+ "<C<><t><v><r><t><e><k>";/
+ "<P><a'><t><e><k>";/
+ "<S><o><b><o><t><a>"
+
+abmon "<L><e><d>";/
+ "<U'><n><o>";/
+ "<B><r<><e>";/
+ "<D><u><b>";/
+ "<K><v><e<>";/
+ "<C<><e><r>";/
+ "<C<><n><c>";/
+ "<S><r><p>";/
+ "<Z><a'><r<>";/
+ "<R<><i'><j>";/
+ "<L><i><s>";/
+ "<P><r><o>"
+
+mon "<L><e><d><e><n>";/
+ "<U'><n><o><r>";/
+ "<B><r<><e><z><e><n>";/
+ "<D><u><b><e><n>";/
+ "<K><v><e<><t><e><n>";/
+ "<C<><e><r><v><e><n>";/
+ "<C<><e><r><v><e><n><e><c>";/
+ "<S><r><p><e><n>";/
+ "<Z><a'><r<><i'>";/
+ "<R<><i'><j><e><n>";/
+ "<L><i><s><t><o><p><a><d>";/
+ "<P><r><o><s><i><n><e><c>"
+
+
+d_t_fmt "<%><a><SP><%><d><.><SP><%><B><SP><%><Y><SP><%><H><:><%><M><:><%><S><SP><%><Z>"
+%d_t_fmt "<%><d><.><%><m><.><%><Y><SP><%><T><SP><%><Z>"
+
+d_fmt "<%><d><.><%><m><.><%><Y>"
+%d_fmt "<%><d><.><%><m><.><%><Y>"
+
+t_fmt "<%><H><:><%><M><:><%><S>"
+%t_fmt "<%><T>"
+
+t_fmt_ampm "<%><I><:><%><M><:><%><S>"
+%t_fmt_ampm ""
+
+%am_pm "am";"pm"
+am_pm "";""
+
+% Zde nevÃm, co následujÃcà polo¾ky znamenajÃ
+% V pøÃpadì potøeby prosÃm opravte
+
+%era "<%><Y>"
+
+%era_year "<%><y>"
+
+%alt_digits "<0>";"<1>";"<2>";"<3>";"<4>";/
+% "<5>";"<6>";"<7>";"<8>"
+
+%era_d_fmt "<%><e><SP><%><B><SP><%><Y>"
+
+END LC_TIME
+
+%% END OF LOCALIZATION FILE for cs_CZ.ISO-8859-2
+%% Konec lokalizaènÃho souboru pro èeské prostøedÃ
escape_char /
%
% Croatian Language Locale for Croatia
-% Source: USM/MZT
-% Address: Kotnikova 6,
-% Ljubljana, Slovenia
-% Contact: Borka Jerman-Blaz<ic<
-% Email: jerman-blazic@ijs.si
-% Tel: +38 - 61 - 653225
-% Fax: none
+% Source: CARNet/SRCE
+% Address: Josipa Marohnica bb
+% Zagreb, Croatia
+% Contact: Tomislav Vujec
+% Email: Tomislav.Vujec@CARNet.hr
+% Tel: +385-1-616-41-94
+% Fax: +385-1-616-41-94
+% Based on original serbo-croate locale by Borka Jerman Blaz<ic<
% Language: hr
% Territory: HR
-% Revision: 4.3
-% Date: 1996-10-15
+% Revision: 1.0
+% Date: 1997-04-22
% Application: general
% Users: general
% Repertoiremap: mnemonic,ds
END LC_MESSAGES
LC_MONETARY
-int_curr_symbol "<H><R><D><SP>"
-currency_symbol "<H><R><D>"
-mon_decimal_point "<,>"
+int_curr_symbol "<H><R><K><SP>"
+currency_symbol "<k><n>"
+mon_decimal_point "<.>"
mon_thousands_sep "<SP>"
mon_grouping 3;3
positive_sign ""
negative_sign "<->"
-int_frac_digits 0
-frac_digits 0
+int_frac_digits 2
+frac_digits 2
p_cs_precedes 1
p_sep_by_space 1
n_cs_precedes 1
END LC_MONETARY
LC_NUMERIC
-decimal_point "<,>"
+decimal_point "<.>"
thousands_sep ""
grouping 0;0
END LC_NUMERIC
LC_TIME
-abday "<n><e><d>";"<p><o><n>";/
- "<t><o><r>";"<s><r><e>";/
- "<c<><e><t>";"<p><e><t>";/
- "<s><u><b>"
-day "<n><e><d><e><l><j><a>";/
- "<p><o><n><e><d><e><l><j><a><k>";/
- "<u><t><o><r><a><k>";/
- "<s><r><e><d><a>";/
- "<c<><e><t><v><r><t><a><k>";/
- "<p><e><t><a><k>";/
- "<s><u><b><o><t><a>"
-abmon "<j><a><n>";"<f><e><b>";/
- "<m><a><r>";"<a><p><r>";/
- "<m><a><j>";"<j><u><n>";/
- "<j><u><l>";"<a><u><g>";/
- "<s><e><p>";"<o><k><t>";/
- "<n><o><v>";"<d><e><c>"
-mon "<j><a><n><u><a><r>";/
- "<f><e><b><r><u><a><r>";/
- "<m><a><r><t>";/
- "<a><p><r><i><l>";/
- "<m><a><j>";/
- "<j><u><n>";/
- "<j><u><l>";/
- "<a><u><g><u><s><t>";/
- "<s><e><p><t><e><m><b><a><r>";/
- "<o><k><t><o><b><a><r>";/
- "<n><o><v><e><m><b><a><r>";/
- "<d><e><c><e><m><b><a><r>"
+abday "<N><e><d>";"<P><o><n>";/
+ "<U><t><o>";"<S><r><i>";/
+ "<C<><e><t>";"<P><e><t>";/
+ "<S><u><b>"
+day "<N><e><d><j><e><l><j><a>";/
+ "<P><o><n><e><d><j><e><l><j><a><k>";/
+ "<U><t><o><r><a><k>";/
+ "<S><r><i><j><e><d><a>";/
+ "<C<><e><t><v><r><t><a><k>";/
+ "<P><e><t><a><k>";/
+ "<S><u><b><o><t><a>"
+abmon "<S><i><j>";"<V><e><l>";/
+ "<O><z><u>";"<T><r><a>";/
+ "<S><v><i>";"<L><i><p>";/
+ "<S><r><p>";"<K><o><l>";/
+ "<R><u><j>";"<L><i><s>";/
+ "<S><t><u>";"<P><r><o>"
+mon "<S><i><j><e><c'><a><n><j>";/
+ "<V><e><l><j><a><c<><a>";/
+ "<O><z<><u><j><a><k>";/
+ "<T><r><a><v><a><n><j>";/
+ "<S><v><i><b><a><n><j>";/
+ "<L><i><p><a><n><j>";/
+ "<S><r><p><a><n><j>";/
+ "<K><o><l><o><v><o><z>";/
+ "<R><u><j><a><n>";/
+ "<L><i><s><t><o><p><a><d>";/
+ "<S><t><u><d><e><n><i>";/
+ "<P><r><o><s><i><n><a><c>"
d_t_fmt "<%><a><SP><%><d><SP><%><b><SP><%><Y><SP><%><T>"
-d_fmt "<%><Y><-><%><m><-><%><d>"
+d_fmt "<%><d><.><%><m><.><%><y>"
t_fmt "<%><T>"
am_pm "";""
t_fmt_ampm ""
others = utmpd
install-sbin = utmpd
-utmpd-routines := connection database error request xtmp
+utmpd-routines := utmpd connection database error request xtmp
+extra-objs := $(utmpd-routines:=.o)
-distribute := utmp-private.h utmpd/xtmp.h utmpd/utmpd.h utmpd/utmpd-private.h
+distribute := utmp-private.h programs/xtmp.h programs/utmpd.h \
+ programs/utmpd-private.h $(utmpd-routines:%=programs/%.c)
-vpath %.c utmpd
+subdir-dirs = programs
+vpath %.c programs
# Build the -lutil library with these extra functions.
extra-libs := libutil
--- /dev/null
+/* Copyright (C) 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
+#include "utmpd-private.h"
+
+
+/* Prototypes for the local functions. */
+static client_connection *alloc_connection (void);
+static void free_connection (client_connection *connection);
+static int set_nonblock_flag (int desc, int value);
+
+
+/* The head of the connection list. */
+static client_connection *connection_list = NULL;
+
+
+/* Accept connection on SOCK, with access permissions given by ACCESS.
+ Returns a pointer to a newly allocated client_connection if
+ successful, NULL if not. */
+client_connection *
+accept_connection (int sock, int access)
+{
+ client_connection *connection;
+
+ connection = alloc_connection ();
+ if (connection == NULL)
+ return NULL;
+
+ connection->sock = accept (sock, NULL, NULL);
+ connection->access = access;
+ if (connection->sock < 0)
+ {
+ free_connection (connection);
+ return NULL;
+ }
+
+ if (set_nonblock_flag (connection->sock, 1) < 0)
+ {
+ close_connection (connection);
+ return NULL;
+ }
+
+ return connection;
+}
+
+
+/* Close CONNECTION. */
+void
+close_connection (client_connection *connection)
+{
+ close (connection->sock);
+ free_connection (connection);
+}
+
+
+/* Return the connection for SOCK. */
+client_connection *
+find_connection (int sock)
+{
+ client_connection *connection;
+
+ for (connection = connection_list; connection;
+ connection = connection->next)
+ {
+ if (connection->sock == sock)
+ return connection;
+ }
+
+ return NULL;
+}
+
+
+static client_connection *
+alloc_connection (void)
+{
+ client_connection *connection;
+ size_t read_bufsize = 1024;
+ size_t write_bufsize = 1024;
+
+ connection = (client_connection *)malloc (sizeof (client_connection));
+ if (connection == NULL)
+ return NULL;
+
+ memset (connection, 0, sizeof (client_connection));
+
+ /* Allocate read buffer. */
+ connection->read_base = malloc (read_bufsize);
+ connection->read_ptr = connection->read_base;
+ connection->read_end = connection->read_base + read_bufsize;
+ if (connection->read_base == NULL)
+ {
+ free (connection);
+ return NULL;
+ }
+
+ /* Allocate write buffer. */
+ connection->write_base = malloc (write_bufsize);
+ connection->write_ptr = connection->write_base;
+ connection->write_end = connection->write_base + write_bufsize;
+ if (connection->write_base == NULL)
+ {
+ free (connection->read_base);
+ free (connection);
+ return NULL;
+ }
+
+ /* Link connection. */
+ connection->next = connection_list;
+ connection_list = connection;
+ if (connection->next)
+ connection->next->prev = connection;
+
+ return connection;
+}
+
+
+static void
+free_connection (client_connection *connection)
+{
+ /* Unlink connection. */
+ if (connection->next)
+ connection->next->prev = connection->prev;
+ if (connection->prev)
+ connection->prev->next = connection->next;
+
+ /* Take care of the head of the list. */
+ if (connection == connection_list)
+ connection_list = connection->next;
+
+ /* Free buffers. */
+ if (connection->read_base)
+ free (connection->read_base);
+ if (connection->write_base)
+ free (connection->write_base);
+
+ free (connection);
+}
+
+
+/* Set the `O_NONBLOCK' flag of DESC if VALUE is nonzero,
+ or clear the flag if VALUE is 0.
+ Return 0 on success, or -1 on error with `errno' set. */
+static int
+set_nonblock_flag (int desc, int value)
+{
+ int oldflags = fcntl (desc, F_GETFL, 0);
+ /* If reading the flags failed, return error indication now. */
+ if (oldflags == -1)
+ return -1;
+ /* Set just the flag we want to set. */
+ if (value != 0)
+ oldflags |= O_NONBLOCK;
+ else
+ oldflags &= ~O_NONBLOCK;
+ /* Store modified flag word in the descriptor. */
+ return fcntl (desc, F_SETFL, oldflags);
+}
--- /dev/null
+/* Copyright (C) 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <time.h>
+#include <unistd.h>
+#include <utmp.h>
+
+
+#include "utmpd-private.h"
+#include "xtmp.h"
+
+
+/* Prototypes for the local functions. */
+static int initialize_database (utmp_database *database);
+static int store_state_entry (utmp_database *database, int old_position,
+ const struct utmp *old_entry);
+static int store_process_entry (utmp_database *database, int old_position,
+ const struct utmp *old_entry);
+static int replace_entry (utmp_database *database, int old_position,
+ int new_position, const struct utmp *entry);
+static int store_entry (utmp_database *database, int position,
+ const struct utmp *entry);
+static int proc_utmp_eq (const struct utmp *entry, const struct utmp *match);
+static int get_mtime (const char *file, time_t *timer);
+
+
+/* Open the database specified by FILE and merge it with the
+ contents of the old format file specified by OLD_FILE. Returns a
+ pointer to a newly allocated structure describing the database, or
+ NULL on error. */
+utmp_database *
+open_database (const char *file, const char *old_file)
+{
+ utmp_database *database;
+
+ /* Allocate memory. */
+ database = (utmp_database *) malloc (sizeof (utmp_database));
+ if (database == NULL)
+ return NULL;
+
+ memset (database, 0, sizeof (utmp_database));
+
+ /* Open database. */
+ database->fd = open (file, O_RDWR);
+ if (database->fd < 0)
+ goto fail;
+
+ database->old_fd = open (old_file, O_RDWR);
+ if (database->old_fd < 0)
+ goto fail;
+
+ if ((file && !(database->file = strdup (file)))
+ || (old_file && !(database->old_file = strdup (old_file))))
+ goto fail;
+
+ if (initialize_database (database) < 0
+ || synchronize_database (database) < 0)
+ goto fail;
+
+ return database;
+
+fail:
+ close_database (database);
+ return NULL;
+}
+
+/* Synchronize DATABASE. */
+int
+synchronize_database (utmp_database *database)
+{
+ assert (database);
+
+ /* Check if there is a file in the old format, that we have to
+ synchronize with. */
+ if (database->old_file)
+ {
+ time_t curtime;
+ time_t mtime;
+
+ curtime = time (NULL);
+
+ if (get_mtime (database->old_file, &mtime) < 0)
+ return -1;
+
+ if (mtime >= database->mtime)
+ {
+ int position = 0;
+ struct utmp entry;
+ struct utmp old_entry;
+
+ while (1)
+ {
+ if (read_old_entry (database, position, &old_entry) < 0)
+ break;
+
+ if (read_entry (database, position, &entry) < 0
+ || !compare_entry (&old_entry, &entry))
+ {
+ if (write_entry (database, position, &old_entry) < 0)
+ return -1;
+ }
+
+ position++;
+ }
+
+ database->mtime = curtime;
+ }
+
+ }
+
+ return 0;
+}
+
+
+/* Close DATABASE. */
+void
+close_database (utmp_database *database)
+{
+ assert (database);
+
+ if (database->fd >= 0)
+ close (database->fd);
+
+ if (database->old_fd >= 0)
+ close (database->old_fd);
+
+ /* Free allocated memory. */
+ if (database->file)
+ free (database->file);
+ if (database->old_file)
+ free (database->old_file);
+ free (database);
+}
+
+
+/* Read the entry at POSITION in DATABASE and store the result in
+ ENTRY. Returns 0 if successful, -1 if not. */
+int
+read_entry (utmp_database *database, int position, struct utmp *entry)
+{
+ ssize_t nbytes;
+ off_t offset;
+
+ offset = position * sizeof (struct utmp);
+ if (lseek (database->fd, offset, SEEK_SET) < 0)
+ return -1;
+
+ nbytes = read (database->fd, entry, sizeof (struct utmp));
+ if (nbytes != sizeof (struct utmp))
+ return -1;
+
+ return 0;
+}
+
+
+/* Write ENTRY at POSITION in DATABASE. Returns 0 if successful, -1
+ on error. */
+int
+write_entry (utmp_database *database, int position,
+ const struct utmp *entry)
+{
+ int result = -1;
+ struct flock fl;
+ ssize_t nbytes;
+ off_t offset;
+
+ /* Try to lock the file. */
+ memset (&fl, 0, sizeof (struct flock));
+ fl.l_type = F_WRLCK;
+ fl.l_whence = SEEK_SET;
+ fcntl (database->fd, F_SETLKW, &fl);
+
+ offset = position * sizeof (struct utmp);
+ if (lseek (database->fd, offset, SEEK_SET) < 0)
+ goto fail;
+
+ nbytes = write (database->fd, entry, sizeof (struct utmp));
+ if (nbytes != sizeof (struct utmp))
+ {
+ ftruncate (database->fd, offset);
+ goto fail;
+ }
+
+ result = 0;
+
+fail:
+ /* And unlock the file. */
+ fl.l_type = F_UNLCK;
+ fcntl (database->fd, F_SETLKW, &fl);
+
+ return result;
+}
+
+
+/* Append ENTRY to DATABASE. Returns the position of the appended
+ entry if successful, or -1 on error. */
+int
+append_entry (utmp_database *database, const struct utmp *entry)
+{
+ int result = -1;
+ struct flock fl;
+ ssize_t nbytes;
+ off_t offset;
+
+ /* Try to lock the file. */
+ memset (&fl, 0, sizeof (struct flock));
+ fl.l_type = F_WRLCK;
+ fl.l_whence = SEEK_SET;
+ fcntl (database->fd, F_SETLKW, &fl);
+
+ offset = lseek (database->fd, 0, SEEK_END);
+ if (offset % sizeof (struct utmp) != 0)
+ {
+ offset -= offset % sizeof (struct utmp);
+ ftruncate (database->fd, offset);
+
+ if (lseek (database->fd, 0, SEEK_END) < 0)
+ goto fail;
+ }
+
+ nbytes = write (database->fd, entry, sizeof (struct utmp));
+ if (nbytes != sizeof (struct utmp))
+ {
+ ftruncate (database->fd, offset);
+ goto fail;
+ }
+
+ result = offset / sizeof (struct utmp);
+
+fail:
+ /* And unlock the file. */
+ fl.l_type = F_UNLCK;
+ fcntl (database->fd, F_SETLKW, &fl);
+
+ return result;
+}
+
+
+int
+read_old_entry (utmp_database *database, int position,
+ struct utmp *entry)
+{
+ struct xtmp old_entry;
+ ssize_t nbytes;
+ off_t offset;
+
+ offset = position * sizeof (struct xtmp);
+ if (lseek (database->old_fd, offset, SEEK_SET) < 0)
+ return -1;
+
+ nbytes = read (database->old_fd, &old_entry, sizeof (struct xtmp));
+ if (nbytes != sizeof (struct xtmp))
+ return -1;
+
+ xtmp_to_utmp (&old_entry, entry);
+ return 0;
+}
+
+
+int
+write_old_entry (utmp_database *database, int position,
+ const struct utmp *entry)
+{
+ struct xtmp old_entry;
+ ssize_t nbytes;
+ off_t offset;
+
+ utmp_to_xtmp (entry, &old_entry);
+
+ offset = position * sizeof (struct xtmp);
+ if (lseek (database->old_fd, offset, SEEK_SET) < 0)
+ return -1;
+
+ nbytes = write (database->old_fd, &old_entry, sizeof (struct xtmp));
+ if (nbytes != sizeof (struct xtmp))
+ return -1;
+
+ return 0;
+}
+
+
+/* Initialize DATABASE. */
+static int
+initialize_database (utmp_database *database)
+{
+ struct utmp entry;
+ int position = 0;
+
+ assert (database);
+
+ /* Check if there is a file in the old format to read. */
+ if (database->old_file)
+ {
+ while (1)
+ {
+ if (read_old_entry (database, position, &entry) < 0)
+ break;
+
+#if _HAVE_UT_TYPE - 0
+ /* If the login type is one of RUN_LVL, BOOT_TIME, OLD_TIME or
+ NEW_TIME, search for an entry of the same type in the
+ database, and replace it if the entry in the file is newer. */
+ if (entry.ut_type == RUN_LVL || entry.ut_type == BOOT_TIME
+ || entry.ut_type == OLD_TIME || entry.ut_type == NEW_TIME)
+ {
+ if (store_state_entry (database, position, &entry) < 0)
+ return -1;
+ }
+ else
+#endif
+ {
+ if (store_process_entry (database, position, &entry) < 0)
+ return -1;
+ }
+
+ /* Update position. */
+ position++;
+ }
+
+ while (1)
+ {
+ if (read_entry (database, position, &entry) < 0)
+ break;
+
+ if (write_old_entry (database, position, &entry) < 0)
+ return -1;
+
+ /* Update position. */
+ position++;
+ }
+ }
+
+ return 0;
+}
+
+
+static int
+store_state_entry (utmp_database *database, int old_position,
+ const struct utmp *old_entry)
+{
+ struct utmp new_entry;
+ int new_position = 0;
+ int found = 0;
+
+ assert (old_entry->ut_type == RUN_LVL
+ || old_entry->ut_type == BOOT_TIME
+ || old_entry->ut_type == OLD_TIME
+ || old_entry->ut_type == NEW_TIME);
+
+ while (!found)
+ {
+ /* Read the next entry. */
+ if (read_entry (database, new_position, &new_entry) < 0)
+ break;
+
+ if (old_entry->ut_type == new_entry.ut_type)
+ {
+ found = 1;
+ continue;
+ }
+
+ /* Update position. */
+ new_position++;
+ }
+
+ if (found)
+ {
+ const struct utmp *entry;
+
+ if (old_entry->ut_time > new_entry.ut_time)
+ entry = old_entry;
+ else
+ entry = &new_entry;
+
+ return replace_entry (database, old_position, new_position, entry);
+ }
+
+ return store_entry (database, old_position, old_entry);
+}
+
+
+static int
+store_process_entry (utmp_database *database, int old_position,
+ const struct utmp *old_entry)
+{
+ struct utmp new_entry;
+ int new_position = 0;
+ int found = 0;
+
+ while (!found)
+ {
+ /* Read the next entry. */
+ if (read_entry (database, new_position, &new_entry) < 0)
+ break;
+
+ if (proc_utmp_eq (old_entry, &new_entry))
+ {
+ found = 1;
+ continue;
+ }
+
+ /* Update position. */
+ new_position++;
+ }
+
+ if (found)
+ {
+ const struct utmp *entry;
+
+ if (old_entry->ut_time > new_entry.ut_time)
+ entry = old_entry;
+ else
+ entry = &new_entry;
+
+ return replace_entry (database, old_position, new_position, entry);
+ }
+
+ return store_entry (database, old_position, old_entry);
+}
+
+
+static int
+replace_entry (utmp_database *database, int old_position, int new_position,
+ const struct utmp *entry)
+{
+ struct utmp tmp;
+
+ if (read_entry (database, old_position, &tmp) < 0
+ || write_entry (database, old_position, entry) < 0
+ || write_entry (database, new_position, &tmp) < 0)
+ return -1;
+
+ return 0;
+}
+
+
+static int
+store_entry (utmp_database *database, int position,
+ const struct utmp *entry)
+{
+ struct utmp tmp;
+
+ if (read_entry (database, position, &tmp) < 0)
+ return write_entry (database, position, entry);
+
+ if (write_entry (database, position, entry) < 0
+ || append_entry (database, &tmp) < 0)
+ return -1;
+
+ return 0;
+}
+
+
+/* This function is identical to the one in login/utmp_file.c. */
+static int
+proc_utmp_eq (const struct utmp *entry, const struct utmp *match)
+{
+ return
+ (
+#if _HAVE_UT_TYPE - 0
+ (entry->ut_type == INIT_PROCESS
+ || entry->ut_type == LOGIN_PROCESS
+ || entry->ut_type == USER_PROCESS
+ || entry->ut_type == DEAD_PROCESS)
+ &&
+ (match->ut_type == INIT_PROCESS
+ || match->ut_type == LOGIN_PROCESS
+ || match->ut_type == USER_PROCESS
+ || match->ut_type == DEAD_PROCESS)
+ &&
+#endif
+#if _HAVE_UT_ID - 0
+ strncmp (entry->ut_id, match->ut_id, sizeof match->ut_id) == 0
+#else
+ strncmp (entry->ut_line, match->ut_line, sizeof match->ut_line) == 0
+#endif
+ );
+}
+
+
+/* Get modification time of FILE and put it in TIMER. returns 0 if
+ successful, -1 if not. */
+static int
+get_mtime (const char *file, time_t *timer)
+{
+ struct stat st;
+
+ if (stat (file, &st) < 0)
+ return -1;
+
+ *timer = st.st_mtime;
+
+ return 0;
+}
--- /dev/null
+/* Copyright (C) 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <errno.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <syslog.h>
+
+#include "utmpd-private.h"
+
+
+/* This variable indicates if we have forked. If set, we log messages
+ via the system logger. Otherwise we simply print the program name
+ and the message to standard error. */
+int forked = 0;
+
+
+/* Log error message MESSAGE, which is a printf-style format string
+ with optional args.
+ If ERRNUM is nonzero, also log its corresponding system error message.
+ Exit with status STATUS if it is nonzero. */
+void
+error (int status, int errnum, const char *message, ...)
+{
+ va_list ap;
+ char *buffer = NULL;
+
+ va_start (ap, message);
+ vasprintf (&buffer, message, ap);
+ va_end (ap);
+
+ if (forked)
+ {
+ if (errnum == 0)
+ syslog (LOG_ERR, "%s", buffer);
+ else
+ syslog (LOG_ERR, "%s: %s", buffer, strerror (errnum));
+ }
+ else
+ {
+ if (errnum == 0)
+ fprintf (stderr, "%s: %s\n", program_invocation_name, buffer);
+ else
+ fprintf (stderr, "%s: %s: %s\n", program_invocation_name, buffer,
+ strerror (errnum));
+ }
+
+ if (buffer)
+ free (buffer);
+
+ if (status)
+ exit (status);
+}
+
+/* Log warning message MESSAGE, which is a printf-style format string
+ with optional args.
+ If ERRNUM is nonzero, also log its corresponding system error message. */
+void
+warning (int errnum, const char *message, ...)
+{
+ va_list ap;
+ char *buffer = NULL;
+
+ va_start (ap, message);
+ vasprintf (&buffer, message, ap);
+ va_end (ap);
+
+ if (forked)
+ {
+ if (errnum == 0)
+ syslog (LOG_WARNING, "%s", buffer);
+ else
+ syslog (LOG_WARNING, "%s: %s", buffer, strerror (errnum));
+ }
+ else
+ {
+ if (errnum == 0)
+ printf ("%s: %s\n", program_invocation_name, buffer);
+ else
+ printf ("%s: %s: %s\n", program_invocation_name, buffer,
+ strerror (errnum));
+ }
+
+ if (buffer)
+ free (buffer);
+}
--- /dev/null
+/* Copyright (C) 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+#include <utmp.h>
+
+#include "utmpd.h"
+#include "utmpd-private.h"
+
+
+/* Prototypes for the local functions. */
+static int process_request (client_connection *connection);
+static int send_reply (client_connection *connect, const reply_header *reply);
+
+static int do_setutent (client_connection *connection);
+static int do_getutent (client_connection *connection);
+static int do_endutent (client_connection *connection);
+static int do_getutline (client_connection *connection);
+static int do_getutid (client_connection *connection);
+static int do_pututline (client_connection *connection);
+static int do_updwtmp (client_connection *connection);
+
+static int proc_utmp_eq (const struct utmp *entry, const struct utmp *match);
+static int internal_getut_r (client_connection *connection,
+ const struct utmp *id, struct utmp *buffer);
+
+
+/* Read data from the client on CONNECTION. */
+int
+read_data (client_connection *connection)
+{
+ ssize_t nbytes;
+
+ assert (connection);
+ assert ((connection->read_end - connection->read_ptr) > 0);
+
+ /* Read data. */
+ nbytes = read (connection->sock, connection->read_ptr,
+ connection->read_end - connection->read_ptr);
+ if (nbytes > 0)
+ {
+ size_t total_bytes;
+
+ /* Update read pointer. */
+ connection->read_ptr += nbytes;
+
+ /* Check if we have a complete request header. */
+ total_bytes = connection->read_ptr - connection->read_base;
+ if (total_bytes >= sizeof (request_header))
+ {
+ request_header *header;
+
+ /* Check if we have a complete request. */
+ header = (request_header *)connection->read_base;
+ if (total_bytes >= header->size)
+ {
+ /* Process the request. */
+ if (process_request (connection) < 0)
+ return -1;
+
+ /* Adjust read pointer, and flush buffer. */
+ connection->read_ptr -= header->size;
+ memmove (connection->read_base,
+ connection->read_base + header->size,
+ connection->read_ptr - connection->read_base);
+ }
+ }
+
+ return 0;
+ }
+
+ if (nbytes < 0)
+ error (0, errno, "cannot read from client");
+
+ return -1;
+}
+
+
+/* Write data to the client on CONNECTION. */
+int
+write_data (client_connection *connection)
+{
+ ssize_t nbytes;
+
+ assert (connection);
+ assert ((connection->write_ptr - connection->write_base) > 0);
+
+ /* Write data. */
+ nbytes = write (connection->sock, connection->write_base,
+ connection->write_ptr - connection->write_base);
+ if (nbytes > 0)
+ {
+ /* Adjust write pointer and flush buffer. */
+ connection->write_ptr -= nbytes;
+ memmove (connection->write_base, connection->write_base + nbytes,
+ connection->write_ptr - connection->write_base);
+
+ return 0;
+ }
+
+ if (nbytes < 0)
+ error (0, errno, "cannot write to client");
+
+ return -1;
+}
+
+
+/* Process the request received on CONNECTION. Returns 0 if
+ successful, -1 if not. */
+static int
+process_request (client_connection *connection)
+{
+ request_header *header;
+
+ assert (connection);
+ assert (connection->read_base);
+
+ header = (request_header *)connection->read_base;
+ if (header->version != UTMPD_VERSION)
+ {
+ warning (EINVAL, "invalid protocol version");
+ return -1;
+ }
+
+ switch (header->type)
+ {
+ case UTMPD_REQ_SETUTENT: return do_setutent (connection);
+ case UTMPD_REQ_GETUTENT: return do_getutent (connection);
+ case UTMPD_REQ_ENDUTENT: return do_endutent (connection);
+ case UTMPD_REQ_GETUTLINE: return do_getutline (connection);
+ case UTMPD_REQ_GETUTID: return do_getutid (connection);
+ case UTMPD_REQ_PUTUTLINE: return do_pututline (connection);
+ case UTMPD_REQ_UPDWTMP: return do_updwtmp (connection);
+ default:
+ warning (EINVAL, "invalid request type");
+ return -1;
+ }
+}
+
+
+/* Send the reply specified by HEADER to the client on CONNECTION.
+ Returns 0 if successful, -1 if not. */
+static int
+send_reply (client_connection *connection, const reply_header *reply)
+{
+ /* Check if the reply fits in the buffer. */
+ if ((size_t) (connection->write_end - connection->write_ptr) < reply->size)
+ {
+ error (0, 0, "buffer overflow");
+ return -1;
+ }
+
+ /* Copy reply to buffer, and adjust write pointer. */
+ memcpy (connection->write_ptr, reply, reply->size);
+ connection->write_ptr += reply->size;
+
+ return 0;
+}
+
+
+static int
+do_setutent (client_connection *connection)
+{
+ setutent_request *request;
+ setutent_reply reply;
+
+ request = (setutent_request *)connection->read_base;
+ if (request->header.size != sizeof (setutent_request))
+ {
+ warning (EINVAL, "invalid request size");
+ return -1;
+ }
+
+ /* Initialize reply. */
+ reply.header.version = UTMPD_VERSION;
+ reply.header.size = sizeof (setutent_reply);
+ reply.header.type = UTMPD_REQ_SETUTENT;
+
+ /* Select database. */
+ if (!strncmp (request->file, _PATH_UTMP, sizeof request->file))
+ connection->database = utmp_db;
+ else
+ {
+ errno = EINVAL;
+ goto return_error;
+ }
+
+ /* Initialize position pointer. */
+ connection->position = 0;
+
+#if _HAVE_UT_TYPE - 0
+ /* Make sure the entry won't match. */
+ connection->last_entry.ut_type = -1;
+#endif
+
+ reply.errnum = 0;
+ reply.result = 0;
+ return send_reply (connection, &reply.header);
+
+return_error:
+ reply.errnum = errno;
+ reply.result = -1;
+ return send_reply (connection, &reply.header);
+}
+
+
+static int
+do_getutent (client_connection *connection)
+{
+ getutent_request *request;
+ getutent_reply reply;
+
+ request = (getutent_request *)connection->read_base;
+ if (request->header.size != sizeof (getutent_request))
+ {
+ warning (EINVAL, "invalid request size");
+ return -1;
+ }
+
+ /* Initialize reply. */
+ reply.header.version = UTMPD_VERSION;
+ reply.header.size = sizeof (getutent_reply);
+ reply.header.type = UTMPD_REQ_GETUTENT;
+
+ if (connection->database == NULL || connection->position == -1)
+ {
+ errno = ESRCH;
+ goto return_error;
+ }
+
+ /* Make sure we're in synch with the ordinary file. */
+ if (synchronize_database (connection->database) < 0)
+ {
+ errno = ESRCH;
+ goto return_error;
+ }
+
+ /* Read the next entry from the database. */
+ if (read_entry (connection->database, connection->position,
+ &connection->last_entry) < 0)
+ {
+ connection->position = -1;
+ errno = ESRCH;
+ goto return_error;
+ }
+
+ /* Update position pointer. */
+ connection->position++;
+
+ memcpy (&reply.entry, &connection->last_entry, sizeof (struct utmp));
+ reply.errnum = 0;
+ reply.result = 0;
+ return send_reply (connection, (reply_header *)&reply);
+
+return_error:
+ memset (&reply.entry, 0, sizeof (struct utmp));
+ reply.errnum = errno;
+ reply.result = -1;
+ return send_reply (connection, &reply.header);
+}
+
+
+static int
+do_endutent (client_connection *connection)
+{
+ endutent_request *request;
+ endutent_reply reply;
+
+ request = (endutent_request *)connection->read_base;
+ if (request->header.size != sizeof (endutent_request))
+ {
+ warning (EINVAL, "invalid request size");
+ return -1;
+ }
+
+ /* Deselect database. */
+ connection->database = NULL;
+
+ /* Formulate reply. */
+ reply.header.version = UTMPD_VERSION;
+ reply.header.size = sizeof (endutent_reply);
+ reply.header.type = UTMPD_REQ_ENDUTENT;
+ reply.errnum = 0;
+ reply.result = 0;
+
+ return send_reply (connection, &reply.header);
+}
+
+
+static int
+do_getutline (client_connection *connection)
+{
+ getutline_request *request;
+ getutline_reply reply;
+
+ request = (getutline_request *)connection->read_base;
+ if (request->header.size != sizeof (getutline_request))
+ {
+ warning (EINVAL, "invalid request size");
+ return -1;
+ }
+
+ /* Initialize reply. */
+ reply.header.version = UTMPD_VERSION;
+ reply.header.size = sizeof (getutline_reply);
+ reply.header.type = UTMPD_REQ_GETUTLINE;
+
+ if (connection->database == NULL || connection->position == -1)
+ {
+ errno = ESRCH;
+ goto return_error;
+ }
+
+ /* Make sure we're in synch with the ordinary file. */
+ if (synchronize_database (connection->database) < 0)
+ {
+ errno = ESRCH;
+ goto return_error;
+ }
+
+ while (1)
+ {
+ /* Read the next entry. */
+ if (read_entry (connection->database, connection->position,
+ &connection->last_entry) < 0)
+ {
+ connection->position = -1;
+ errno = ESRCH;
+ goto return_error;
+ }
+ connection->position++;
+
+ /* Stop if we found a user or login entry. */
+ if (
+#if _HAVE_UT_TYPE - 0
+ (connection->last_entry.ut_type == USER_PROCESS
+ || connection->last_entry.ut_type == LOGIN_PROCESS)
+ &&
+#endif
+ !strncmp (request->line.ut_line, connection->last_entry.ut_line,
+ sizeof request->line.ut_line))
+ break;
+ }
+
+ memcpy (&reply.entry, &connection->last_entry, sizeof (struct utmp));
+ reply.errnum = 0;
+ reply.result = 0;
+ return send_reply (connection, &reply.header);
+
+return_error:
+ memset (&reply.entry, 0, sizeof (struct utmp));
+ reply.errnum = errno;
+ reply.result = -1;
+ return send_reply (connection, &reply.header);
+}
+
+
+static int
+do_getutid (client_connection *connection)
+{
+ getutid_request *request;
+ getutid_reply reply;
+
+ request = (getutid_request *)connection->read_base;
+ if (request->header.size != sizeof (getutid_request))
+ {
+ warning (EINVAL, "invalid request size");
+ return -1;
+ }
+
+ /* Initialize reply. */
+ reply.header.version = UTMPD_VERSION;
+ reply.header.size = sizeof (getutid_reply);
+ reply.header.type = UTMPD_REQ_GETUTID;
+
+ if (connection->database == NULL || connection->position == -1)
+ {
+ errno = ESRCH;
+ goto return_error;
+ }
+
+ /* Make sure we're in synch with the ordinary file. */
+ if (synchronize_database (connection->database) < 0)
+ {
+ errno = ESRCH;
+ goto return_error;
+ }
+
+ if (internal_getut_r (connection, &request->id,
+ &connection->last_entry) < 0)
+ {
+ errno = ESRCH;
+ goto return_error;
+ }
+
+ reply.errnum = 0;
+ reply.result = 0;
+ memcpy (&reply.entry, &connection->last_entry, sizeof (struct utmp));
+ return send_reply (connection, &reply.header);
+
+return_error:
+ memset (&reply.entry, 0, sizeof (struct utmp));
+ reply.errnum = errno;
+ reply.result = -1;
+ return send_reply (connection, &reply.header);
+}
+
+
+static int
+do_pututline (client_connection *connection)
+{
+ pututline_request *request;
+ pututline_reply reply;
+ struct utmp buffer;
+ int found;
+
+ request = (pututline_request *)connection->read_base;
+ if (request->header.size != sizeof (pututline_request))
+ {
+ warning (EINVAL, "invalid request size");
+ return -1;
+ }
+
+ /* Initialize reply. */
+ reply.header.version = UTMPD_VERSION;
+ reply.header.size = sizeof (pututline_reply);
+ reply.header.type = UTMPD_REQ_PUTUTLINE;
+
+ if (!(connection->access & W_OK))
+ {
+ errno = EPERM;
+ goto return_error;
+ }
+
+ if (connection->database == NULL || connection->position == -1)
+ {
+ errno = ESRCH;
+ goto return_error;
+ }
+
+ /* Make sure we're in synch with the ordinary file. */
+ if (synchronize_database (connection->database) < 0)
+ {
+ errno = ESRCH;
+ goto return_error;
+ }
+
+ /* Find the correct place to insert the data. */
+ if (connection->position > 0
+ && (
+#if _HAVE_UT_TYPE - 0
+ (connection->last_entry.ut_type == request->utmp.ut_type
+ && (connection->last_entry.ut_type == RUN_LVL
+ || connection->last_entry.ut_type == BOOT_TIME
+ || connection->last_entry.ut_type == OLD_TIME
+ || connection->last_entry.ut_type == NEW_TIME))
+ ||
+#endif
+ proc_utmp_eq (&connection->last_entry, &request->utmp)))
+ found = 1;
+ else
+ found = internal_getut_r (connection, &request->utmp, &buffer);
+
+ if (found < 0)
+ {
+ /* We append the next entry. */
+ connection->position =
+ append_entry (connection->database, &request->utmp);
+ if (connection->position < 0)
+ goto return_error;
+ }
+ else
+ {
+ /* We replace the just read entry. */
+ connection->position--;
+ if (write_entry (connection->database, connection->position,
+ &request->utmp) < 0)
+ goto return_error;
+ }
+
+ /* Write the entry to the compatibility file. */
+ write_old_entry (connection->database, connection->position, &request->utmp);
+
+ /* Update position pointer. */
+ connection->position++;
+
+ reply.errnum = 0;
+ reply.result = 0;
+ return send_reply (connection, &reply.header);
+
+return_error:
+ reply.errnum = errno;
+ reply.result = -1;
+ return send_reply (connection, &reply.header);
+}
+
+
+static int
+do_updwtmp (client_connection *connection)
+{
+ updwtmp_request *request;
+ updwtmp_reply reply;
+ utmp_database *database;
+
+ request = (updwtmp_request *)connection->read_base;
+ if (request->header.size != sizeof (updwtmp_request))
+ {
+ warning (EINVAL, "invalid request size");
+ return -1;
+ }
+
+ /* Initialize reply. */
+ reply.header.version = UTMPD_VERSION;
+ reply.header.size = sizeof (updwtmp_reply);
+ reply.header.type = UTMPD_REQ_UPDWTMP;
+
+ if (!(connection->access & W_OK))
+ {
+ errno = EPERM;
+ goto return_error;
+ }
+
+ /* Select database. */
+ if (!strncmp (request->file, _PATH_UTMP, sizeof request->file))
+ database = utmp_db;
+ else
+ {
+ errno = EINVAL;
+ goto return_error;
+ }
+
+ /* Make sure we're in synch with the ordinary file. */
+ if (synchronize_database (database) < 0)
+ {
+ errno = ESRCH;
+ goto return_error;
+ }
+
+ /* Append the entry. */
+ if (append_entry (database, &request->utmp) < 0)
+ goto return_error;
+
+ reply.errnum = 0;
+ reply.result = 0;
+ return send_reply (connection, &reply.header);
+
+return_error:
+ reply.errnum = errno;
+ reply.result = -1;
+ return send_reply (connection, &reply.header);
+}
+
+
+/* This function is identical to the one in login/utmp_file.c. */
+static int
+proc_utmp_eq (const struct utmp *entry, const struct utmp *match)
+{
+ return
+ (
+#if _HAVE_UT_TYPE - 0
+ (entry->ut_type == INIT_PROCESS
+ || entry->ut_type == LOGIN_PROCESS
+ || entry->ut_type == USER_PROCESS
+ || entry->ut_type == DEAD_PROCESS)
+ &&
+ (match->ut_type == INIT_PROCESS
+ || match->ut_type == LOGIN_PROCESS
+ || match->ut_type == USER_PROCESS
+ || match->ut_type == DEAD_PROCESS)
+ &&
+#endif
+#if _HAVE_UT_ID - 0
+ strncmp (entry->ut_id, match->ut_id, sizeof match->ut_id) == 0
+#else
+ strncmp (entry->ut_line, match->ut_line, sizeof match->ut_line) == 0
+#endif
+ );
+}
+
+
+/* This function is derived from the one in login/utmp_file.c. */
+static int
+internal_getut_r (client_connection *connection,
+ const struct utmp *id, struct utmp *buffer)
+{
+#if _HAVE_UT_TYPE - 0
+ if (id->ut_type == RUN_LVL || id->ut_type == BOOT_TIME
+ || id->ut_type == OLD_TIME || id->ut_type == NEW_TIME)
+ {
+ /* Search for next entry with type RUN_LVL, BOOT_TIME,
+ OLD_TIME, or NEW_TIME. */
+
+ while (1)
+ {
+ /* Read the next entry. */
+ if (read_entry (connection->database, connection->position,
+ buffer) < 0)
+ {
+ connection->position = -1;
+ return -1;
+ }
+ connection->position++;
+
+ if (id->ut_type == buffer->ut_type)
+ break;
+ }
+ }
+ else
+#endif /* _HAVE_UT_TYPE */
+ {
+ /* Search for the next entry with the specified ID and with type
+ INIT_PROCESS, LOGIN_PROCESS, USER_PROCESS, or DEAD_PROCESS. */
+
+ while (1)
+ {
+ /* Read the next entry. */
+ if (read_entry (connection->database, connection->position,
+ buffer) < 0)
+ {
+ connection->position = -1;
+ return -1;
+ }
+ connection->position++;
+
+ if (proc_utmp_eq (buffer, id))
+ break;
+ }
+ }
+
+ return 0;
+}
--- /dev/null
+/* Copyright (C) 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _UTMPD_PRIVATE_H
+#define _UTMPD_PRIVATE_H 1
+
+#include <time.h>
+#include <utmp.h>
+
+
+/* The number of connections we allow. */
+#ifndef MAX_CONNECTIONS
+#define MAX_CONNECTIONS 16
+#endif
+
+
+typedef struct utmp_database
+{
+ int fd;
+ int old_fd;
+ char *file;
+ char *old_file;
+ time_t mtime;
+} utmp_database;
+
+
+/* The databases we handle. */
+extern utmp_database *utmp_db;
+extern utmp_database *wtmp_db;
+
+
+typedef struct client_connection
+{
+ int sock;
+ /* Access permissions. */
+ int access;
+
+ /* Read pointer. */
+ void *read_base;
+ void *read_ptr;
+ void *read_end;
+
+ /* Write buffer. */
+ void *write_base;
+ void *write_ptr;
+ void *write_end;
+
+ /* Database to use for this connection. */
+ utmp_database *database;
+ /* Position pointer. */
+ int position;
+
+ /* Last read entry. */
+ struct utmp last_entry;
+
+ /* Pointers to the next and previous connections in the list. */
+ struct client_connection *next;
+ struct client_connection *prev;
+} client_connection;
+
+
+/* This variable indicates if we have forked. If set, we log messages
+ via the system logger. Otherwise we simply print the program name
+ and the message to standard error. */
+extern int forked;
+
+
+/* Database functions. */
+utmp_database *open_database (const char *file, const char *old_file);
+int synchronize_database (utmp_database *database);
+void close_database (utmp_database *database);
+int read_entry (utmp_database *database, int position, struct utmp *entry);
+int write_entry (utmp_database *database, int position,
+ const struct utmp *entry);
+int append_entry (utmp_database *database, const struct utmp *entry);
+int read_old_entry (utmp_database *database, int position, struct utmp *entry);
+int write_old_entry (utmp_database *database, int position,
+ const struct utmp *entry);
+
+/* Connection oriented functions. */
+client_connection *accept_connection (int sock, int access);
+client_connection *find_connection (int sock);
+void close_connection (client_connection *connection);
+int read_data (client_connection *connection);
+int write_data (client_connection *connection);
+
+void error (int status, int errnum, const char *message, ...);
+void warning (int errnum, const char *message, ...);
+
+#endif /* utmpd-private.h */
+
--- /dev/null
+/* Copyright (C) 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <libintl.h>
+#include <pwd.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <string.h>
+#include <sys/select.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/un.h>
+#include <syslog.h>
+#include <unistd.h>
+
+#include "utmpd.h"
+#include "utmpd-private.h"
+
+/* Get libc version number. */
+#include "../../version.h"
+
+#define PACKAGE "libc"
+
+/* Long options. */
+static const struct option long_options[] =
+{
+ { "debug", no_argument, NULL, 'd' },
+ { "help", no_argument, NULL, 'h' },
+ { "version", no_argument, NULL, 'V' },
+ { NULL, 0, NULL, 0}
+};
+
+/* The UTMP database. */
+utmp_database *utmp_db;
+
+/* The socket for read only requests. */
+int ro_sock = -1;
+
+/* The socket for read/write requests. */
+int rw_sock = -1;
+
+
+/* Prototypes for the local functions. */
+static void usage (int status) __attribute__ ((noreturn));
+static void drop_priviliges (void);
+static int make_socket (const char *name);
+static void handle_requests (void) __attribute__ ((noreturn));
+static void termination_handler (int signum);
+static int check_pid (const char *file);
+static int write_pid (const char *file);
+
+
+int
+main (int argc, char *argv[])
+{
+ mode_t mask;
+ int debug;
+ int do_help;
+ int do_version;
+ int opt;
+
+ /* Initialize local variables. */
+ debug = 0;
+ do_help = 0;
+ do_version = 0;
+
+ while ((opt = getopt_long (argc, argv, "dhV", long_options, NULL)) != -1)
+ switch (opt)
+ {
+ case '\0': /* Long option. */
+ break;
+ case 'h':
+ do_help = 1;
+ break;
+ case 'd':
+ debug = 1;
+ break;
+ case 'V':
+ do_version = 1;
+ break;
+ default:
+ usage (EXIT_FAILURE);
+ }
+
+ /* Version information is reequested. */
+ if (do_version)
+ {
+ printf ("utmpd (GNU %s) %s\n", PACKAGE, VERSION);
+ printf (gettext ("\
+Copyright (C) %s Free Software Foundation, Inc.\n\
+This is free software; see the source for copying conditions. There is NO\n\
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
+"), "1997");
+ printf (gettext ("Written by %s.\n"), "Mark Kettenis");
+
+ exit (EXIT_SUCCESS);
+ }
+
+ /* Help is requested. */
+ if (do_help)
+ usage (EXIT_SUCCESS);
+
+ signal (SIGINT, termination_handler);
+ signal (SIGTERM, termination_handler);
+
+ /* Check if we are already running. */
+ if (check_pid (_PATH_UTMPDPID))
+ error (EXIT_FAILURE, 0, "already running");
+
+ /* Open UTMP database. */
+ utmp_db = open_database (_PATH_UTMP "x", _PATH_UTMP);
+ if (utmp_db == NULL)
+ error (EXIT_FAILURE, errno, "%s", _PATH_UTMP);
+
+ /* Create sockets, with the right permissions. */
+ mask = umask (S_IXUSR | S_IXGRP | S_IXOTH);
+ ro_sock = make_socket (_PATH_UTMPD_RO);
+ umask (S_IXUSR | S_IRWXG | S_IRWXO);
+ rw_sock = make_socket (_PATH_UTMPD_RW);
+ umask (mask);
+
+ /* Set the sockets up to accept connections. */
+ if (listen (ro_sock, MAX_CONNECTIONS) < 0
+ || listen (rw_sock, MAX_CONNECTIONS) < 0)
+ error (EXIT_FAILURE, errno, "cannot enable socket to accept connections");
+
+ /* Behave like a daemon. */
+ if (!debug)
+ {
+ openlog ("utmpd", LOG_CONS | LOG_ODELAY, LOG_DAEMON);
+
+ if (daemon (0, 0) < 0)
+ error (EXIT_FAILURE, errno, "cannot auto-background");
+ forked = 1;
+
+ if (write_pid (_PATH_UTMPDPID) < 0)
+ warning (errno, "%s", _PATH_UTMPDPID);
+ }
+
+ /* Drop priviliges. */
+ drop_priviliges ();
+
+ /* Handle incoming requests. */
+ handle_requests ();
+}
+
+
+/* Display usage information and exit. */
+static void
+usage (int status)
+{
+ if (status != EXIT_SUCCESS)
+ fprintf (stderr, gettext ("Try `%s --help' for more information.\n"),
+ program_invocation_name);
+ else
+ {
+ printf (gettext ("\
+Usage: %s [OPTION]...\n\
+ -d, --debug do not fork and display messages on the current tty\n\
+ -h, --help display this help and exit\n\
+ -V, --version output version information and exit\n"),
+ program_invocation_name);
+ fputs (gettext ("\
+Report bugs to <kettenis@phys.uva.nl>.\n"),
+ stdout);
+ }
+
+ exit (status);
+}
+
+
+/* Drop priviliges. */
+static void
+drop_priviliges (void)
+{
+ struct passwd *pw;
+
+ pw = getpwnam ("daemon");
+ if (pw)
+ {
+ seteuid (pw->pw_uid);
+ setegid (pw->pw_gid);
+ }
+}
+
+
+/* Make a socket in the file namespace using the filename NAME as the
+ socket's address. */
+static int
+make_socket (const char *name)
+{
+ struct sockaddr_un addr;
+ size_t size;
+ int sock;
+
+ /* Create the socket. */
+ sock = socket (PF_UNIX, SOCK_STREAM, 0);
+ if (sock < 0)
+ error (EXIT_FAILURE, errno, "cannot create socket");
+
+ /* Bind a name to the socket. */
+ addr.sun_family = AF_UNIX;
+ strcpy (addr.sun_path, name);
+
+ /* The size of the address is the offset of the start
+ of the filename, plus its length, plus one for the
+ terminating null byte. */
+ size = (offsetof (struct sockaddr_un, sun_path)
+ + strlen (addr.sun_path));
+
+ if (bind (sock, (struct sockaddr *) &addr, size) < 0)
+ error (EXIT_FAILURE, errno, "%s", name);
+
+ return sock;
+}
+
+
+/* Hanlde incoming requests. */
+static
+void handle_requests (void)
+{
+ client_connection *connection;
+ fd_set active_read_fd_set;
+ fd_set active_write_fd_set;
+ fd_set read_fd_set;
+ fd_set write_fd_set;
+ int fd;
+
+ /* Initialize the set of active sockets. */
+ FD_ZERO (&active_read_fd_set);
+ FD_ZERO (&active_write_fd_set);
+ FD_SET (rw_sock, &active_read_fd_set);
+ FD_SET (ro_sock, &active_read_fd_set);
+
+ while (1)
+ {
+ /* Block until input arrives on one or more active sockets. */
+ read_fd_set = active_read_fd_set;
+ write_fd_set = active_write_fd_set;
+ if (select (FD_SETSIZE, &read_fd_set, &write_fd_set, NULL, NULL) < 0)
+ error (EXIT_FAILURE, errno, "cannot get input on sockets");
+
+ /* Service all the sockets with input pending. */
+ for (fd = 0; fd < FD_SETSIZE; fd++)
+ {
+ if (FD_ISSET (fd, &read_fd_set))
+ {
+ if (fd == ro_sock || fd == rw_sock)
+ {
+ int access = ((fd == rw_sock) ? (R_OK | W_OK) : R_OK);
+
+ connection = accept_connection (fd, access);
+ if (connection == NULL)
+ error (0, errno, "cannot accept connection");
+
+ FD_SET (connection->sock, &active_read_fd_set);
+ }
+ else
+ {
+ connection = find_connection (fd);
+ if (connection == NULL)
+ error (EXIT_FAILURE, 0, "cannot find connection");
+
+ if (read_data (connection) < 0)
+ {
+ close_connection (connection);
+ FD_CLR (fd, &active_read_fd_set);
+ FD_CLR (fd, &active_write_fd_set);
+ }
+
+ if (connection->write_ptr > connection->write_base)
+ FD_SET (fd, &active_write_fd_set);
+ }
+ }
+ if (FD_ISSET (fd, &write_fd_set) &&
+ fd != rw_sock && fd != ro_sock)
+ {
+ connection = find_connection (fd);
+ if (connection == NULL)
+ error (EXIT_FAILURE, 0, "cannot find connection");
+
+ if (write_data (connection) < 0)
+ {
+ close_connection (connection);
+ FD_CLR (fd, &active_read_fd_set);
+ FD_CLR (fd, &active_write_fd_set);
+ }
+
+ if (connection->write_ptr == connection->write_base)
+ FD_CLR (fd, &active_write_fd_set);
+ }
+ }
+ }
+}
+
+
+/* Cleanup. */
+static void
+termination_handler (int signum)
+{
+ /* Close sockets. */
+ close (ro_sock);
+ close (rw_sock);
+
+ /* Restore user id. */
+ seteuid (getuid ());
+
+ /* Clean up the files created by `bind'. */
+ unlink (_PATH_UTMPD_RO);
+ unlink (_PATH_UTMPD_RW);
+
+ if (utmp_db)
+ close_database (utmp_db);
+
+ /* Clean up pid file. */
+ unlink (_PATH_UTMPDPID);
+
+ exit (EXIT_SUCCESS);
+}
+
+
+/* Returns 1 if the process in pid file FILE is running, 0 if not. */
+static int
+check_pid (const char *file)
+{
+ FILE *fp;
+
+ fp = fopen (_PATH_UTMPDPID, "r");
+ if (fp)
+ {
+ pid_t pid;
+
+ fscanf (fp, "%d", &pid);
+ fclose (fp);
+
+ if (kill (pid, 0) == 0)
+ return 1;
+ }
+
+ return 0;
+}
+
+/* Write the current process id to the file FILE. Returns 0 if
+ successful, -1 if not. */
+static int
+write_pid (const char *file)
+{
+ FILE *fp;
+
+ fp = fopen (_PATH_UTMPDPID, "w");
+ if (fp == NULL)
+ return -1;
+
+ fprintf (fp, "%d\n", getpid ());
+ if (ferror (fp))
+ return -1;
+
+ fclose (fp);
+
+ return 0;
+}
+
--- /dev/null
+/* Copyright (C) 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _UTMPD_H
+#define _UTMPD_H 1
+
+/* This is an *internal* header. */
+
+#include <limits.h>
+#include <stddef.h>
+#include <utmp.h>
+
+
+/* Paths to daemon sockets. */
+#define _PATH_UTMPD_RO "/var/run/utmpd.ro"
+#define _PATH_UTMPD_RW "/var/run/utmpd.rw"
+
+
+/* Path to PID file. */
+#define _PATH_UTMPDPID "/var/run/utmpd.pid"
+
+
+/* Version number of the daemon interface. */
+#define UTMPD_VERSION 1
+
+
+/* Services provided. */
+typedef enum
+{
+ UTMPD_REQ_SETUTENT,
+ UTMPD_REQ_GETUTENT,
+ UTMPD_REQ_ENDUTENT,
+ UTMPD_REQ_GETUTLINE,
+ UTMPD_REQ_GETUTID,
+ UTMPD_REQ_PUTUTLINE,
+ UTMPD_REQ_UPDWTMP
+} request_type;
+
+
+/* Header common to all requests. */
+typedef struct
+{
+ /* Version number of the daemon interface. */
+ int version;
+ /* Number of bytes in this request. */
+ size_t size;
+ /* Service requested. */
+ request_type type;
+} request_header;
+
+typedef struct
+{
+ request_header header;
+ /* File to use. */
+ char file[_POSIX_PATH_MAX + 1];
+} setutent_request;
+
+typedef struct
+{
+ request_header header;
+} getutent_request, endutent_request;
+
+typedef struct
+{
+ request_header header;
+ /* Entry to match. */
+ struct utmp line;
+} getutline_request;
+
+typedef struct
+{
+ request_header header;
+ /* Entry to match. */
+ struct utmp id;
+} getutid_request;
+
+typedef struct
+{
+ request_header header;
+ /* Entry to write. */
+ struct utmp utmp;
+} pututline_request;
+
+typedef struct
+{
+ request_header header;
+ /* File to use. */
+ char file[_POSIX_PATH_MAX + 1];
+ /* Entry to write. */
+ struct utmp utmp;
+} updwtmp_request;
+
+
+/* Header common to all replies. */
+typedef struct
+{
+ /* Version number of the daemon interface. */
+ int version;
+ /* Number of bytes in this reply. */
+ size_t size;
+ /* Answer to the request. */
+ request_type type;
+} reply_header;
+
+typedef struct
+{
+ reply_header header;
+ /* Error code. */
+ int errnum;
+ /* Return value. */
+ int result;
+} setutent_reply, endutent_reply, pututline_reply, updwtmp_reply;
+
+typedef struct
+{
+ reply_header header;
+ /* Found entry. */
+ struct utmp entry;
+ /* Error code. */
+ int errnum;
+ /* Return value. */
+ int result;
+} getutent_reply, getutline_reply, getutid_reply;
+
+#endif /* utmpd.h */
--- /dev/null
+/* utmpdump - dump utmp-like files.
+ Copyright (C) 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <errno.h>
+#include <error.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <unistd.h>
+#include <utmp.h>
+
+void
+print_entry (struct utmp *up)
+{
+ printf ("[%d] [%05d] [%-4.4s] [%-8.8s] [%-12.12s] [%-15.15s] [%ld]\n",
+ up->ut_type, up->ut_pid, up->ut_id, up->ut_user,
+ up->ut_line, 4 + ctime (&up->ut_time), up->ut_tv.tv_usec);
+}
+
+int
+main (int argc, char *argv[])
+{
+ struct utmp *up;
+
+ if (argc > 1)
+ utmpname (argv[1]);
+
+ setutent ();
+
+ while ((up = getutent ()))
+ print_entry (up);
+
+ endutent ();
+
+ return EXIT_SUCCESS;
+}
--- /dev/null
+/* Copyright (C) 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <utmp.h>
+
+#include "xtmp.h"
+
+/* Convert the entry XT to the new utmp format and store it in UT.
+ Fields in UT that were not present in the old utmp format are
+ initialized to zero. */
+void
+xtmp_to_utmp (const struct xtmp *xtmp, struct utmp *utmp)
+{
+ memset (utmp, 0, sizeof (struct utmp));
+#if _HAVE_XT_TYPE - 0
+ utmp->ut_type = xtmp->xt_type;
+#endif
+#if _HAVE_XT_PID - 0
+ utmp->ut_pid = xtmp->xt_pid;
+#endif
+ strncpy (utmp->ut_line, xtmp->xt_line, XT_LINESIZE);
+#if _HAVE_XT_ID - 0
+ strncpy (utmp->ut_id, xtmp->xt_id, sizeof xtmp->xt_id);
+#endif
+ utmp->ut_time = xtmp->xt_time;
+ strncpy (utmp->ut_user, xtmp->xt_user, XT_NAMESIZE);
+#if _HAVE_XT_HOST - 0
+ strncpy (utmp->ut_host, xtmp->xt_host, XT_HOSTSIZE);
+#endif
+ utmp->ut_addr = xtmp->xt_addr;
+}
+
+/* Convert the entry UTMP to the old utmp format and store it in XTMP. */
+void
+utmp_to_xtmp (const struct utmp *utmp, struct xtmp *xtmp)
+{
+ memset (xtmp, 0, sizeof (struct xtmp));
+#if _HAVE_XT_TYPE - 0
+ xtmp->xt_type = utmp->ut_type;
+#endif
+#if _HAVE_XT_PID - 0
+ xtmp->xt_pid = utmp->ut_pid;
+#endif
+ strncpy (xtmp->xt_line, utmp->ut_line, XT_LINESIZE);
+ xtmp->xt_line[XT_LINESIZE] = '\0';
+#if _HAVE_XT_ID - 0
+ strncpy (xtmp->xt_id, utmp->ut_id, sizeof xtmp->xt_id);
+#endif
+ xtmp->xt_time = utmp->ut_time;
+ strncpy (xtmp->xt_user, utmp->ut_user, XT_NAMESIZE);
+#if _HAVE_XT_HOST - 0
+ strncpy (xtmp->xt_host, utmp->ut_host, XT_HOSTSIZE);
+ xtmp->xt_host[XT_HOSTSIZE] = '\0';
+#endif
+ xtmp->xt_addr = utmp->ut_addr;
+}
+
+/* Compare an old style entry XTMP with a new style entry UTMP. The
+ function returns 1 if the information that is in both old and new
+ style entries is identical. Otherwise this function returns 0. */
+int
+compare_entry (const struct utmp *xtmp, const struct utmp *utmp)
+{
+ return
+ (
+#if _HAVE_XT_TYPE - 0
+ xtmp->ut_type == utmp->ut_type
+#endif
+#if _HAVE_XT_PID - 0
+ && xtmp->ut_pid == utmp->ut_pid
+#endif
+ && !strncmp (xtmp->ut_line, utmp->ut_line, XT_LINESIZE - 1)
+#if _HAVE_XT_ID - 0
+ && !strncmp (xtmp->ut_id, utmp->ut_id, sizeof utmp->ut_id)
+#endif
+ && xtmp->ut_time == utmp->ut_time
+ && !strncmp (xtmp->ut_user, utmp->ut_user, XT_NAMESIZE)
+#if _HAVE_XT_HOST - 0
+ && !strncmp (xtmp->ut_host, utmp->ut_host, XT_HOSTSIZE - 1)
+#endif
+ && xtmp->ut_addr == utmp->ut_addr);
+}
--- /dev/null
+/* The `struct xtmp' type, describing the old linux utmp format.
+ Copyright (C) 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _XTMP_H
+#define _XTMP_H 1
+#include <features.h>
+
+#include <sys/time.h>
+#include <sys/types.h>
+
+
+#define XT_LINESIZE 12
+#define XT_NAMESIZE 8
+#define XT_HOSTSIZE 16
+
+struct xtmp
+{
+ short int xt_type; /* Type of login. */
+ pid_t xt_pid; /* Pid of login process. */
+ char xt_line[XT_LINESIZE]; /* NUL-terminated devicename of tty. */
+ char xt_id[4]; /* Inittab id. */
+ time_t xt_time; /* Time entry was made. */
+ char xt_user[XT_NAMESIZE]; /* Username (not NUL terminated). */
+ char xt_host[XT_HOSTSIZE]; /* Hostname for remote login. */
+ long xt_addr; /* Internet adress of remote host. */
+};
+
+#define _HAVE_XT_TYPE 1
+#define _HAVE_XT_PID 1
+#define _HAVE_XT_ID 1
+#define _HAVE_XT_HOST 1
+
+
+extern void xtmp_to_utmp (const struct xtmp *xtmp, struct utmp *utmp);
+extern void utmp_to_xtmp (const struct utmp *utmp, struct xtmp *xtmp);
+extern int compare_entry (const struct utmp *xtmp,
+ const struct utmp *utmp);
+
+#endif /* xtmp.h */
+++ /dev/null
-/* Copyright (C) 1997 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the GNU C Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
-
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/socket.h>
-#include <unistd.h>
-
-#include "utmpd-private.h"
-
-
-/* Prototypes for the local functions. */
-static client_connection *alloc_connection (void);
-static void free_connection (client_connection *connection);
-static int set_nonblock_flag (int desc, int value);
-
-
-/* The head of the connection list. */
-static client_connection *connection_list = NULL;
-
-
-/* Accept connection on SOCK, with access permissions given by ACCESS.
- Returns a pointer to a newly allocated client_connection if
- successful, NULL if not. */
-client_connection *
-accept_connection (int sock, int access)
-{
- client_connection *connection;
-
- connection = alloc_connection ();
- if (connection == NULL)
- return NULL;
-
- connection->sock = accept (sock, NULL, NULL);
- connection->access = access;
- if (connection->sock < 0)
- {
- free_connection (connection);
- return NULL;
- }
-
- if (set_nonblock_flag (connection->sock, 1) < 0)
- {
- close_connection (connection);
- return NULL;
- }
-
- return connection;
-}
-
-
-/* Close CONNECTION. */
-void
-close_connection (client_connection *connection)
-{
- close (connection->sock);
- free_connection (connection);
-}
-
-
-/* Return the connection for SOCK. */
-client_connection *
-find_connection (int sock)
-{
- client_connection *connection;
-
- for (connection = connection_list; connection;
- connection = connection->next)
- {
- if (connection->sock == sock)
- return connection;
- }
-
- return NULL;
-}
-
-
-static client_connection *
-alloc_connection (void)
-{
- client_connection *connection;
- size_t read_bufsize = 1024;
- size_t write_bufsize = 1024;
-
- connection = (client_connection *)malloc (sizeof (client_connection));
- if (connection == NULL)
- return NULL;
-
- memset (connection, 0, sizeof (client_connection));
-
- /* Allocate read buffer. */
- connection->read_base = malloc (read_bufsize);
- connection->read_ptr = connection->read_base;
- connection->read_end = connection->read_base + read_bufsize;
- if (connection->read_base == NULL)
- {
- free (connection);
- return NULL;
- }
-
- /* Allocate write buffer. */
- connection->write_base = malloc (write_bufsize);
- connection->write_ptr = connection->write_base;
- connection->write_end = connection->write_base + write_bufsize;
- if (connection->write_base == NULL)
- {
- free (connection->read_base);
- free (connection);
- return NULL;
- }
-
- /* Link connection. */
- connection->next = connection_list;
- connection_list = connection;
- if (connection->next)
- connection->next->prev = connection;
-
- return connection;
-}
-
-
-static void
-free_connection (client_connection *connection)
-{
- /* Unlink connection. */
- if (connection->next)
- connection->next->prev = connection->prev;
- if (connection->prev)
- connection->prev->next = connection->next;
-
- /* Take care of the head of the list. */
- if (connection == connection_list)
- connection_list = connection->next;
-
- /* Free buffers. */
- if (connection->read_base)
- free (connection->read_base);
- if (connection->write_base)
- free (connection->write_base);
-
- free (connection);
-}
-
-
-/* Set the `O_NONBLOCK' flag of DESC if VALUE is nonzero,
- or clear the flag if VALUE is 0.
- Return 0 on success, or -1 on error with `errno' set. */
-static int
-set_nonblock_flag (int desc, int value)
-{
- int oldflags = fcntl (desc, F_GETFL, 0);
- /* If reading the flags failed, return error indication now. */
- if (oldflags == -1)
- return -1;
- /* Set just the flag we want to set. */
- if (value != 0)
- oldflags |= O_NONBLOCK;
- else
- oldflags &= ~O_NONBLOCK;
- /* Store modified flag word in the descriptor. */
- return fcntl (desc, F_SETFL, oldflags);
-}
+++ /dev/null
-/* Copyright (C) 1997 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the GNU C Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
-
-#include <assert.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/stat.h>
-#include <time.h>
-#include <unistd.h>
-#include <utmp.h>
-
-
-#include "utmpd-private.h"
-#include "xtmp.h"
-
-
-/* Prototypes for the local functions. */
-static int initialize_database (utmp_database *database);
-static int store_state_entry (utmp_database *database, int old_position,
- const struct utmp *old_entry);
-static int store_process_entry (utmp_database *database, int old_position,
- const struct utmp *old_entry);
-static int replace_entry (utmp_database *database, int old_position,
- int new_position, const struct utmp *entry);
-static int store_entry (utmp_database *database, int position,
- const struct utmp *entry);
-static int proc_utmp_eq (const struct utmp *entry, const struct utmp *match);
-static int get_mtime (const char *file, time_t *timer);
-
-
-/* Open the database specified by FILE and merge it with the
- contents of the old format file specified by OLD_FILE. Returns a
- pointer to a newly allocated structure describing the database, or
- NULL on error. */
-utmp_database *
-open_database (const char *file, const char *old_file)
-{
- utmp_database *database;
-
- /* Allocate memory. */
- database = (utmp_database *) malloc (sizeof (utmp_database));
- if (database == NULL)
- return NULL;
-
- memset (database, 0, sizeof (utmp_database));
-
- /* Open database. */
- database->fd = open (file, O_RDWR);
- if (database->fd < 0)
- goto fail;
-
- database->old_fd = open (old_file, O_RDWR);
- if (database->old_fd < 0)
- goto fail;
-
- if ((file && !(database->file = strdup (file)))
- || (old_file && !(database->old_file = strdup (old_file))))
- goto fail;
-
- if (initialize_database (database) < 0
- || synchronize_database (database) < 0)
- goto fail;
-
- return database;
-
-fail:
- close_database (database);
- return NULL;
-}
-
-/* Synchronize DATABASE. */
-int
-synchronize_database (utmp_database *database)
-{
- assert (database);
-
- /* Check if there is a file in the old format, that we have to
- synchronize with. */
- if (database->old_file)
- {
- time_t curtime;
- time_t mtime;
-
- curtime = time (NULL);
-
- if (get_mtime (database->old_file, &mtime) < 0)
- return -1;
-
- if (mtime >= database->mtime)
- {
- int position = 0;
- struct utmp entry;
- struct utmp old_entry;
-
- while (1)
- {
- if (read_old_entry (database, position, &old_entry) < 0)
- break;
-
- if (read_entry (database, position, &entry) < 0
- || !compare_entry (&old_entry, &entry))
- {
- if (write_entry (database, position, &old_entry) < 0)
- return -1;
- }
-
- position++;
- }
-
- database->mtime = curtime;
- }
-
- }
-
- return 0;
-}
-
-
-/* Close DATABASE. */
-void
-close_database (utmp_database *database)
-{
- assert (database);
-
- if (database->fd >= 0)
- close (database->fd);
-
- if (database->old_fd >= 0)
- close (database->old_fd);
-
- /* Free allocated memory. */
- if (database->file)
- free (database->file);
- if (database->old_file)
- free (database->old_file);
- free (database);
-}
-
-
-/* Read the entry at POSITION in DATABASE and store the result in
- ENTRY. Returns 0 if successful, -1 if not. */
-int
-read_entry (utmp_database *database, int position, struct utmp *entry)
-{
- ssize_t nbytes;
- off_t offset;
-
- offset = position * sizeof (struct utmp);
- if (lseek (database->fd, offset, SEEK_SET) < 0)
- return -1;
-
- nbytes = read (database->fd, entry, sizeof (struct utmp));
- if (nbytes != sizeof (struct utmp))
- return -1;
-
- return 0;
-}
-
-
-/* Write ENTRY at POSITION in DATABASE. Returns 0 if successful, -1
- on error. */
-int
-write_entry (utmp_database *database, int position,
- const struct utmp *entry)
-{
- int result = -1;
- struct flock fl;
- ssize_t nbytes;
- off_t offset;
-
- /* Try to lock the file. */
- memset (&fl, 0, sizeof (struct flock));
- fl.l_type = F_WRLCK;
- fl.l_whence = SEEK_SET;
- fcntl (database->fd, F_SETLKW, &fl);
-
- offset = position * sizeof (struct utmp);
- if (lseek (database->fd, offset, SEEK_SET) < 0)
- goto fail;
-
- nbytes = write (database->fd, entry, sizeof (struct utmp));
- if (nbytes != sizeof (struct utmp))
- {
- ftruncate (database->fd, offset);
- goto fail;
- }
-
- result = 0;
-
-fail:
- /* And unlock the file. */
- fl.l_type = F_UNLCK;
- fcntl (database->fd, F_SETLKW, &fl);
-
- return result;
-}
-
-
-/* Append ENTRY to DATABASE. Returns the position of the appended
- entry if successful, or -1 on error. */
-int
-append_entry (utmp_database *database, const struct utmp *entry)
-{
- int result = -1;
- struct flock fl;
- ssize_t nbytes;
- off_t offset;
-
- /* Try to lock the file. */
- memset (&fl, 0, sizeof (struct flock));
- fl.l_type = F_WRLCK;
- fl.l_whence = SEEK_SET;
- fcntl (database->fd, F_SETLKW, &fl);
-
- offset = lseek (database->fd, 0, SEEK_END);
- if (offset % sizeof (struct utmp) != 0)
- {
- offset -= offset % sizeof (struct utmp);
- ftruncate (database->fd, offset);
-
- if (lseek (database->fd, 0, SEEK_END) < 0)
- goto fail;
- }
-
- nbytes = write (database->fd, entry, sizeof (struct utmp));
- if (nbytes != sizeof (struct utmp))
- {
- ftruncate (database->fd, offset);
- goto fail;
- }
-
- result = offset / sizeof (struct utmp);
-
-fail:
- /* And unlock the file. */
- fl.l_type = F_UNLCK;
- fcntl (database->fd, F_SETLKW, &fl);
-
- return result;
-}
-
-
-int
-read_old_entry (utmp_database *database, int position,
- struct utmp *entry)
-{
- struct xtmp old_entry;
- ssize_t nbytes;
- off_t offset;
-
- offset = position * sizeof (struct xtmp);
- if (lseek (database->old_fd, offset, SEEK_SET) < 0)
- return -1;
-
- nbytes = read (database->old_fd, &old_entry, sizeof (struct xtmp));
- if (nbytes != sizeof (struct xtmp))
- return -1;
-
- xtmp_to_utmp (&old_entry, entry);
- return 0;
-}
-
-
-int
-write_old_entry (utmp_database *database, int position,
- const struct utmp *entry)
-{
- struct xtmp old_entry;
- ssize_t nbytes;
- off_t offset;
-
- utmp_to_xtmp (entry, &old_entry);
-
- offset = position * sizeof (struct xtmp);
- if (lseek (database->old_fd, offset, SEEK_SET) < 0)
- return -1;
-
- nbytes = write (database->old_fd, &old_entry, sizeof (struct xtmp));
- if (nbytes != sizeof (struct xtmp))
- return -1;
-
- return 0;
-}
-
-
-/* Initialize DATABASE. */
-static int
-initialize_database (utmp_database *database)
-{
- struct utmp entry;
- int position = 0;
-
- assert (database);
-
- /* Check if there is a file in the old format to read. */
- if (database->old_file)
- {
- while (1)
- {
- if (read_old_entry (database, position, &entry) < 0)
- break;
-
-#if _HAVE_UT_TYPE - 0
- /* If the login type is one of RUN_LVL, BOOT_TIME, OLD_TIME or
- NEW_TIME, search for an entry of the same type in the
- database, and replace it if the entry in the file is newer. */
- if (entry.ut_type == RUN_LVL || entry.ut_type == BOOT_TIME
- || entry.ut_type == OLD_TIME || entry.ut_type == NEW_TIME)
- {
- if (store_state_entry (database, position, &entry) < 0)
- return -1;
- }
- else
-#endif
- {
- if (store_process_entry (database, position, &entry) < 0)
- return -1;
- }
-
- /* Update position. */
- position++;
- }
-
- while (1)
- {
- if (read_entry (database, position, &entry) < 0)
- break;
-
- if (write_old_entry (database, position, &entry) < 0)
- return -1;
-
- /* Update position. */
- position++;
- }
- }
-
- return 0;
-}
-
-
-static int
-store_state_entry (utmp_database *database, int old_position,
- const struct utmp *old_entry)
-{
- struct utmp new_entry;
- int new_position = 0;
- int found = 0;
-
- assert (old_entry->ut_type == RUN_LVL
- || old_entry->ut_type == BOOT_TIME
- || old_entry->ut_type == OLD_TIME
- || old_entry->ut_type == NEW_TIME);
-
- while (!found)
- {
- /* Read the next entry. */
- if (read_entry (database, new_position, &new_entry) < 0)
- break;
-
- if (old_entry->ut_type == new_entry.ut_type)
- {
- found = 1;
- continue;
- }
-
- /* Update position. */
- new_position++;
- }
-
- if (found)
- {
- const struct utmp *entry;
-
- if (old_entry->ut_time > new_entry.ut_time)
- entry = old_entry;
- else
- entry = &new_entry;
-
- return replace_entry (database, old_position, new_position, entry);
- }
-
- return store_entry (database, old_position, old_entry);
-}
-
-
-static int
-store_process_entry (utmp_database *database, int old_position,
- const struct utmp *old_entry)
-{
- struct utmp new_entry;
- int new_position = 0;
- int found = 0;
-
- while (!found)
- {
- /* Read the next entry. */
- if (read_entry (database, new_position, &new_entry) < 0)
- break;
-
- if (proc_utmp_eq (old_entry, &new_entry))
- {
- found = 1;
- continue;
- }
-
- /* Update position. */
- new_position++;
- }
-
- if (found)
- {
- const struct utmp *entry;
-
- if (old_entry->ut_time > new_entry.ut_time)
- entry = old_entry;
- else
- entry = &new_entry;
-
- return replace_entry (database, old_position, new_position, entry);
- }
-
- return store_entry (database, old_position, old_entry);
-}
-
-
-static int
-replace_entry (utmp_database *database, int old_position, int new_position,
- const struct utmp *entry)
-{
- struct utmp tmp;
-
- if (read_entry (database, old_position, &tmp) < 0
- || write_entry (database, old_position, entry) < 0
- || write_entry (database, new_position, &tmp) < 0)
- return -1;
-
- return 0;
-}
-
-
-static int
-store_entry (utmp_database *database, int position,
- const struct utmp *entry)
-{
- struct utmp tmp;
-
- if (read_entry (database, position, &tmp) < 0)
- return write_entry (database, position, entry);
-
- if (write_entry (database, position, entry) < 0
- || append_entry (database, &tmp) < 0)
- return -1;
-
- return 0;
-}
-
-
-/* This function is identical to the one in login/utmp_file.c. */
-static int
-proc_utmp_eq (const struct utmp *entry, const struct utmp *match)
-{
- return
- (
-#if _HAVE_UT_TYPE - 0
- (entry->ut_type == INIT_PROCESS
- || entry->ut_type == LOGIN_PROCESS
- || entry->ut_type == USER_PROCESS
- || entry->ut_type == DEAD_PROCESS)
- &&
- (match->ut_type == INIT_PROCESS
- || match->ut_type == LOGIN_PROCESS
- || match->ut_type == USER_PROCESS
- || match->ut_type == DEAD_PROCESS)
- &&
-#endif
-#if _HAVE_UT_ID - 0
- strncmp (entry->ut_id, match->ut_id, sizeof match->ut_id) == 0
-#else
- strncmp (entry->ut_line, match->ut_line, sizeof match->ut_line) == 0
-#endif
- );
-}
-
-
-/* Get modification time of FILE and put it in TIMER. returns 0 if
- successful, -1 if not. */
-static int
-get_mtime (const char *file, time_t *timer)
-{
- struct stat st;
-
- if (stat (file, &st) < 0)
- return -1;
-
- *timer = st.st_mtime;
-
- return 0;
-}
+++ /dev/null
-/* Copyright (C) 1997 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the GNU C Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
-
-#include <errno.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <syslog.h>
-
-#include "utmpd-private.h"
-
-
-/* This variable indicates if we have forked. If set, we log messages
- via the system logger. Otherwise we simply print the program name
- and the message to standard error. */
-int forked = 0;
-
-
-/* Log error message MESSAGE, which is a printf-style format string
- with optional args.
- If ERRNUM is nonzero, also log its corresponding system error message.
- Exit with status STATUS if it is nonzero. */
-void
-error (int status, int errnum, const char *message, ...)
-{
- va_list ap;
- char *buffer = NULL;
-
- va_start (ap, message);
- vasprintf (&buffer, message, ap);
- va_end (ap);
-
- if (forked)
- {
- if (errnum == 0)
- syslog (LOG_ERR, "%s", buffer);
- else
- syslog (LOG_ERR, "%s: %s", buffer, strerror (errnum));
- }
- else
- {
- if (errnum == 0)
- fprintf (stderr, "%s: %s\n", program_invocation_name, buffer);
- else
- fprintf (stderr, "%s: %s: %s\n", program_invocation_name, buffer,
- strerror (errnum));
- }
-
- if (buffer)
- free (buffer);
-
- if (status)
- exit (status);
-}
-
-/* Log warning message MESSAGE, which is a printf-style format string
- with optional args.
- If ERRNUM is nonzero, also log its corresponding system error message. */
-void
-warning (int errnum, const char *message, ...)
-{
- va_list ap;
- char *buffer = NULL;
-
- va_start (ap, message);
- vasprintf (&buffer, message, ap);
- va_end (ap);
-
- if (forked)
- {
- if (errnum == 0)
- syslog (LOG_WARNING, "%s", buffer);
- else
- syslog (LOG_WARNING, "%s: %s", buffer, strerror (errnum));
- }
- else
- {
- if (errnum == 0)
- printf ("%s: %s\n", program_invocation_name, buffer);
- else
- printf ("%s: %s: %s\n", program_invocation_name, buffer,
- strerror (errnum));
- }
-
- if (buffer)
- free (buffer);
-}
+++ /dev/null
-/* Copyright (C) 1997 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the GNU C Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
-
-#include <assert.h>
-#include <errno.h>
-#include <string.h>
-#include <unistd.h>
-#include <utmp.h>
-
-#include "utmpd.h"
-#include "utmpd-private.h"
-
-
-/* Prototypes for the local functions. */
-static int process_request (client_connection *connection);
-static int send_reply (client_connection *connect, const reply_header *reply);
-
-static int do_setutent (client_connection *connection);
-static int do_getutent (client_connection *connection);
-static int do_endutent (client_connection *connection);
-static int do_getutline (client_connection *connection);
-static int do_getutid (client_connection *connection);
-static int do_pututline (client_connection *connection);
-static int do_updwtmp (client_connection *connection);
-
-static int proc_utmp_eq (const struct utmp *entry, const struct utmp *match);
-static int internal_getut_r (client_connection *connection,
- const struct utmp *id, struct utmp *buffer);
-
-
-/* Read data from the client on CONNECTION. */
-int
-read_data (client_connection *connection)
-{
- ssize_t nbytes;
-
- assert (connection);
- assert ((connection->read_end - connection->read_ptr) > 0);
-
- /* Read data. */
- nbytes = read (connection->sock, connection->read_ptr,
- connection->read_end - connection->read_ptr);
- if (nbytes > 0)
- {
- size_t total_bytes;
-
- /* Update read pointer. */
- connection->read_ptr += nbytes;
-
- /* Check if we have a complete request header. */
- total_bytes = connection->read_ptr - connection->read_base;
- if (total_bytes >= sizeof (request_header))
- {
- request_header *header;
-
- /* Check if we have a complete request. */
- header = (request_header *)connection->read_base;
- if (total_bytes >= header->size)
- {
- /* Process the request. */
- if (process_request (connection) < 0)
- return -1;
-
- /* Adjust read pointer, and flush buffer. */
- connection->read_ptr -= header->size;
- memmove (connection->read_base,
- connection->read_base + header->size,
- connection->read_ptr - connection->read_base);
- }
- }
-
- return 0;
- }
-
- if (nbytes < 0)
- error (0, errno, "cannot read from client");
-
- return -1;
-}
-
-
-/* Write data to the client on CONNECTION. */
-int
-write_data (client_connection *connection)
-{
- ssize_t nbytes;
-
- assert (connection);
- assert ((connection->write_ptr - connection->write_base) > 0);
-
- /* Write data. */
- nbytes = write (connection->sock, connection->write_base,
- connection->write_ptr - connection->write_base);
- if (nbytes > 0)
- {
- /* Adjust write pointer and flush buffer. */
- connection->write_ptr -= nbytes;
- memmove (connection->write_base, connection->write_base + nbytes,
- connection->write_ptr - connection->write_base);
-
- return 0;
- }
-
- if (nbytes < 0)
- error (0, errno, "cannot write to client");
-
- return -1;
-}
-
-
-/* Process the request received on CONNECTION. Returns 0 if
- successful, -1 if not. */
-static int
-process_request (client_connection *connection)
-{
- request_header *header;
-
- assert (connection);
- assert (connection->read_base);
-
- header = (request_header *)connection->read_base;
- if (header->version != UTMPD_VERSION)
- {
- warning (EINVAL, "invalid protocol version");
- return -1;
- }
-
- switch (header->type)
- {
- case UTMPD_REQ_SETUTENT: return do_setutent (connection);
- case UTMPD_REQ_GETUTENT: return do_getutent (connection);
- case UTMPD_REQ_ENDUTENT: return do_endutent (connection);
- case UTMPD_REQ_GETUTLINE: return do_getutline (connection);
- case UTMPD_REQ_GETUTID: return do_getutid (connection);
- case UTMPD_REQ_PUTUTLINE: return do_pututline (connection);
- case UTMPD_REQ_UPDWTMP: return do_updwtmp (connection);
- default:
- warning (EINVAL, "invalid request type");
- return -1;
- }
-}
-
-
-/* Send the reply specified by HEADER to the client on CONNECTION.
- Returns 0 if successful, -1 if not. */
-static int
-send_reply (client_connection *connection, const reply_header *reply)
-{
- /* Check if the reply fits in the buffer. */
- if ((size_t) (connection->write_end - connection->write_ptr) < reply->size)
- {
- error (0, 0, "buffer overflow");
- return -1;
- }
-
- /* Copy reply to buffer, and adjust write pointer. */
- memcpy (connection->write_ptr, reply, reply->size);
- connection->write_ptr += reply->size;
-
- return 0;
-}
-
-
-static int
-do_setutent (client_connection *connection)
-{
- setutent_request *request;
- setutent_reply reply;
-
- request = (setutent_request *)connection->read_base;
- if (request->header.size != sizeof (setutent_request))
- {
- warning (EINVAL, "invalid request size");
- return -1;
- }
-
- /* Initialize reply. */
- reply.header.version = UTMPD_VERSION;
- reply.header.size = sizeof (setutent_reply);
- reply.header.type = UTMPD_REQ_SETUTENT;
-
- /* Select database. */
- if (!strncmp (request->file, _PATH_UTMP, sizeof request->file))
- connection->database = utmp_db;
- else
- {
- errno = EINVAL;
- goto return_error;
- }
-
- /* Initialize position pointer. */
- connection->position = 0;
-
-#if _HAVE_UT_TYPE - 0
- /* Make sure the entry won't match. */
- connection->last_entry.ut_type = -1;
-#endif
-
- reply.errnum = 0;
- reply.result = 0;
- return send_reply (connection, &reply.header);
-
-return_error:
- reply.errnum = errno;
- reply.result = -1;
- return send_reply (connection, &reply.header);
-}
-
-
-static int
-do_getutent (client_connection *connection)
-{
- getutent_request *request;
- getutent_reply reply;
-
- request = (getutent_request *)connection->read_base;
- if (request->header.size != sizeof (getutent_request))
- {
- warning (EINVAL, "invalid request size");
- return -1;
- }
-
- /* Initialize reply. */
- reply.header.version = UTMPD_VERSION;
- reply.header.size = sizeof (getutent_reply);
- reply.header.type = UTMPD_REQ_GETUTENT;
-
- if (connection->database == NULL || connection->position == -1)
- {
- errno = ESRCH;
- goto return_error;
- }
-
- /* Make sure we're in synch with the ordinary file. */
- if (synchronize_database (connection->database) < 0)
- {
- errno = ESRCH;
- goto return_error;
- }
-
- /* Read the next entry from the database. */
- if (read_entry (connection->database, connection->position,
- &connection->last_entry) < 0)
- {
- connection->position = -1;
- errno = ESRCH;
- goto return_error;
- }
-
- /* Update position pointer. */
- connection->position++;
-
- memcpy (&reply.entry, &connection->last_entry, sizeof (struct utmp));
- reply.errnum = 0;
- reply.result = 0;
- return send_reply (connection, (reply_header *)&reply);
-
-return_error:
- memset (&reply.entry, 0, sizeof (struct utmp));
- reply.errnum = errno;
- reply.result = -1;
- return send_reply (connection, &reply.header);
-}
-
-
-static int
-do_endutent (client_connection *connection)
-{
- endutent_request *request;
- endutent_reply reply;
-
- request = (endutent_request *)connection->read_base;
- if (request->header.size != sizeof (endutent_request))
- {
- warning (EINVAL, "invalid request size");
- return -1;
- }
-
- /* Deselect database. */
- connection->database = NULL;
-
- /* Formulate reply. */
- reply.header.version = UTMPD_VERSION;
- reply.header.size = sizeof (endutent_reply);
- reply.header.type = UTMPD_REQ_ENDUTENT;
- reply.errnum = 0;
- reply.result = 0;
-
- return send_reply (connection, &reply.header);
-}
-
-
-static int
-do_getutline (client_connection *connection)
-{
- getutline_request *request;
- getutline_reply reply;
-
- request = (getutline_request *)connection->read_base;
- if (request->header.size != sizeof (getutline_request))
- {
- warning (EINVAL, "invalid request size");
- return -1;
- }
-
- /* Initialize reply. */
- reply.header.version = UTMPD_VERSION;
- reply.header.size = sizeof (getutline_reply);
- reply.header.type = UTMPD_REQ_GETUTLINE;
-
- if (connection->database == NULL || connection->position == -1)
- {
- errno = ESRCH;
- goto return_error;
- }
-
- /* Make sure we're in synch with the ordinary file. */
- if (synchronize_database (connection->database) < 0)
- {
- errno = ESRCH;
- goto return_error;
- }
-
- while (1)
- {
- /* Read the next entry. */
- if (read_entry (connection->database, connection->position,
- &connection->last_entry) < 0)
- {
- connection->position = -1;
- errno = ESRCH;
- goto return_error;
- }
- connection->position++;
-
- /* Stop if we found a user or login entry. */
- if (
-#if _HAVE_UT_TYPE - 0
- (connection->last_entry.ut_type == USER_PROCESS
- || connection->last_entry.ut_type == LOGIN_PROCESS)
- &&
-#endif
- !strncmp (request->line.ut_line, connection->last_entry.ut_line,
- sizeof request->line.ut_line))
- break;
- }
-
- memcpy (&reply.entry, &connection->last_entry, sizeof (struct utmp));
- reply.errnum = 0;
- reply.result = 0;
- return send_reply (connection, &reply.header);
-
-return_error:
- memset (&reply.entry, 0, sizeof (struct utmp));
- reply.errnum = errno;
- reply.result = -1;
- return send_reply (connection, &reply.header);
-}
-
-
-static int
-do_getutid (client_connection *connection)
-{
- getutid_request *request;
- getutid_reply reply;
-
- request = (getutid_request *)connection->read_base;
- if (request->header.size != sizeof (getutid_request))
- {
- warning (EINVAL, "invalid request size");
- return -1;
- }
-
- /* Initialize reply. */
- reply.header.version = UTMPD_VERSION;
- reply.header.size = sizeof (getutid_reply);
- reply.header.type = UTMPD_REQ_GETUTID;
-
- if (connection->database == NULL || connection->position == -1)
- {
- errno = ESRCH;
- goto return_error;
- }
-
- /* Make sure we're in synch with the ordinary file. */
- if (synchronize_database (connection->database) < 0)
- {
- errno = ESRCH;
- goto return_error;
- }
-
- if (internal_getut_r (connection, &request->id,
- &connection->last_entry) < 0)
- {
- errno = ESRCH;
- goto return_error;
- }
-
- reply.errnum = 0;
- reply.result = 0;
- memcpy (&reply.entry, &connection->last_entry, sizeof (struct utmp));
- return send_reply (connection, &reply.header);
-
-return_error:
- memset (&reply.entry, 0, sizeof (struct utmp));
- reply.errnum = errno;
- reply.result = -1;
- return send_reply (connection, &reply.header);
-}
-
-
-static int
-do_pututline (client_connection *connection)
-{
- pututline_request *request;
- pututline_reply reply;
- struct utmp buffer;
- int found;
-
- request = (pututline_request *)connection->read_base;
- if (request->header.size != sizeof (pututline_request))
- {
- warning (EINVAL, "invalid request size");
- return -1;
- }
-
- /* Initialize reply. */
- reply.header.version = UTMPD_VERSION;
- reply.header.size = sizeof (pututline_reply);
- reply.header.type = UTMPD_REQ_PUTUTLINE;
-
- if (!(connection->access & W_OK))
- {
- errno = EPERM;
- goto return_error;
- }
-
- if (connection->database == NULL || connection->position == -1)
- {
- errno = ESRCH;
- goto return_error;
- }
-
- /* Make sure we're in synch with the ordinary file. */
- if (synchronize_database (connection->database) < 0)
- {
- errno = ESRCH;
- goto return_error;
- }
-
- /* Find the correct place to insert the data. */
- if (connection->position > 0
- && (
-#if _HAVE_UT_TYPE - 0
- (connection->last_entry.ut_type == request->utmp.ut_type
- && (connection->last_entry.ut_type == RUN_LVL
- || connection->last_entry.ut_type == BOOT_TIME
- || connection->last_entry.ut_type == OLD_TIME
- || connection->last_entry.ut_type == NEW_TIME))
- ||
-#endif
- proc_utmp_eq (&connection->last_entry, &request->utmp)))
- found = 1;
- else
- found = internal_getut_r (connection, &request->utmp, &buffer);
-
- if (found < 0)
- {
- /* We append the next entry. */
- connection->position =
- append_entry (connection->database, &request->utmp);
- if (connection->position < 0)
- goto return_error;
- }
- else
- {
- /* We replace the just read entry. */
- connection->position--;
- if (write_entry (connection->database, connection->position,
- &request->utmp) < 0)
- goto return_error;
- }
-
- /* Write the entry to the compatibility file. */
- write_old_entry (connection->database, connection->position, &request->utmp);
-
- /* Update position pointer. */
- connection->position++;
-
- reply.errnum = 0;
- reply.result = 0;
- return send_reply (connection, &reply.header);
-
-return_error:
- reply.errnum = errno;
- reply.result = -1;
- return send_reply (connection, &reply.header);
-}
-
-
-static int
-do_updwtmp (client_connection *connection)
-{
- updwtmp_request *request;
- updwtmp_reply reply;
- utmp_database *database;
-
- request = (updwtmp_request *)connection->read_base;
- if (request->header.size != sizeof (updwtmp_request))
- {
- warning (EINVAL, "invalid request size");
- return -1;
- }
-
- /* Initialize reply. */
- reply.header.version = UTMPD_VERSION;
- reply.header.size = sizeof (updwtmp_reply);
- reply.header.type = UTMPD_REQ_UPDWTMP;
-
- if (!(connection->access & W_OK))
- {
- errno = EPERM;
- goto return_error;
- }
-
- /* Select database. */
- if (!strncmp (request->file, _PATH_UTMP, sizeof request->file))
- database = utmp_db;
- else
- {
- errno = EINVAL;
- goto return_error;
- }
-
- /* Make sure we're in synch with the ordinary file. */
- if (synchronize_database (database) < 0)
- {
- errno = ESRCH;
- goto return_error;
- }
-
- /* Append the entry. */
- if (append_entry (database, &request->utmp) < 0)
- goto return_error;
-
- reply.errnum = 0;
- reply.result = 0;
- return send_reply (connection, &reply.header);
-
-return_error:
- reply.errnum = errno;
- reply.result = -1;
- return send_reply (connection, &reply.header);
-}
-
-
-/* This function is identical to the one in login/utmp_file.c. */
-static int
-proc_utmp_eq (const struct utmp *entry, const struct utmp *match)
-{
- return
- (
-#if _HAVE_UT_TYPE - 0
- (entry->ut_type == INIT_PROCESS
- || entry->ut_type == LOGIN_PROCESS
- || entry->ut_type == USER_PROCESS
- || entry->ut_type == DEAD_PROCESS)
- &&
- (match->ut_type == INIT_PROCESS
- || match->ut_type == LOGIN_PROCESS
- || match->ut_type == USER_PROCESS
- || match->ut_type == DEAD_PROCESS)
- &&
-#endif
-#if _HAVE_UT_ID - 0
- strncmp (entry->ut_id, match->ut_id, sizeof match->ut_id) == 0
-#else
- strncmp (entry->ut_line, match->ut_line, sizeof match->ut_line) == 0
-#endif
- );
-}
-
-
-/* This function is derived from the one in login/utmp_file.c. */
-static int
-internal_getut_r (client_connection *connection,
- const struct utmp *id, struct utmp *buffer)
-{
-#if _HAVE_UT_TYPE - 0
- if (id->ut_type == RUN_LVL || id->ut_type == BOOT_TIME
- || id->ut_type == OLD_TIME || id->ut_type == NEW_TIME)
- {
- /* Search for next entry with type RUN_LVL, BOOT_TIME,
- OLD_TIME, or NEW_TIME. */
-
- while (1)
- {
- /* Read the next entry. */
- if (read_entry (connection->database, connection->position,
- buffer) < 0)
- {
- connection->position = -1;
- return -1;
- }
- connection->position++;
-
- if (id->ut_type == buffer->ut_type)
- break;
- }
- }
- else
-#endif /* _HAVE_UT_TYPE */
- {
- /* Search for the next entry with the specified ID and with type
- INIT_PROCESS, LOGIN_PROCESS, USER_PROCESS, or DEAD_PROCESS. */
-
- while (1)
- {
- /* Read the next entry. */
- if (read_entry (connection->database, connection->position,
- buffer) < 0)
- {
- connection->position = -1;
- return -1;
- }
- connection->position++;
-
- if (proc_utmp_eq (buffer, id))
- break;
- }
- }
-
- return 0;
-}
+++ /dev/null
-/* Copyright (C) 1997 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the GNU C Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
-
-#ifndef _UTMPD_PRIVATE_H
-#define _UTMPD_PRIVATE_H 1
-
-#include <time.h>
-#include <utmp.h>
-
-
-/* The number of connections we allow. */
-#ifndef MAX_CONNECTIONS
-#define MAX_CONNECTIONS 16
-#endif
-
-
-typedef struct utmp_database
-{
- int fd;
- int old_fd;
- char *file;
- char *old_file;
- time_t mtime;
-} utmp_database;
-
-
-/* The databases we handle. */
-extern utmp_database *utmp_db;
-extern utmp_database *wtmp_db;
-
-
-typedef struct client_connection
-{
- int sock;
- /* Access permissions. */
- int access;
-
- /* Read pointer. */
- void *read_base;
- void *read_ptr;
- void *read_end;
-
- /* Write buffer. */
- void *write_base;
- void *write_ptr;
- void *write_end;
-
- /* Database to use for this connection. */
- utmp_database *database;
- /* Position pointer. */
- int position;
-
- /* Last read entry. */
- struct utmp last_entry;
-
- /* Pointers to the next and previous connections in the list. */
- struct client_connection *next;
- struct client_connection *prev;
-} client_connection;
-
-
-/* This variable indicates if we have forked. If set, we log messages
- via the system logger. Otherwise we simply print the program name
- and the message to standard error. */
-extern int forked;
-
-
-/* Database functions. */
-utmp_database *open_database (const char *file, const char *old_file);
-int synchronize_database (utmp_database *database);
-void close_database (utmp_database *database);
-int read_entry (utmp_database *database, int position, struct utmp *entry);
-int write_entry (utmp_database *database, int position,
- const struct utmp *entry);
-int append_entry (utmp_database *database, const struct utmp *entry);
-int read_old_entry (utmp_database *database, int position, struct utmp *entry);
-int write_old_entry (utmp_database *database, int position,
- const struct utmp *entry);
-
-/* Connection oriented functions. */
-client_connection *accept_connection (int sock, int access);
-client_connection *find_connection (int sock);
-void close_connection (client_connection *connection);
-int read_data (client_connection *connection);
-int write_data (client_connection *connection);
-
-void error (int status, int errnum, const char *message, ...);
-void warning (int errnum, const char *message, ...);
-
-#endif /* utmpd-private.h */
-
+++ /dev/null
-/* Copyright (C) 1997 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the GNU C Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
-
-#include <errno.h>
-#include <fcntl.h>
-#include <getopt.h>
-#include <libintl.h>
-#include <pwd.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <string.h>
-#include <sys/select.h>
-#include <sys/socket.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/un.h>
-#include <syslog.h>
-#include <unistd.h>
-
-#include "utmpd.h"
-#include "utmpd-private.h"
-
-/* Get libc version number. */
-#include "../../version.h"
-
-#define PACKAGE "libc"
-
-/* Long options. */
-static const struct option long_options[] =
-{
- { "debug", no_argument, NULL, 'd' },
- { "help", no_argument, NULL, 'h' },
- { "version", no_argument, NULL, 'V' },
- { NULL, 0, NULL, 0}
-};
-
-/* The UTMP database. */
-utmp_database *utmp_db;
-
-/* The socket for read only requests. */
-int ro_sock = -1;
-
-/* The socket for read/write requests. */
-int rw_sock = -1;
-
-
-/* Prototypes for the local functions. */
-static void usage (int status) __attribute__ ((noreturn));
-static void drop_priviliges (void);
-static int make_socket (const char *name);
-static void handle_requests (void) __attribute__ ((noreturn));
-static void termination_handler (int signum);
-static int check_pid (const char *file);
-static int write_pid (const char *file);
-
-
-int
-main (int argc, char *argv[])
-{
- mode_t mask;
- int debug;
- int do_help;
- int do_version;
- int opt;
-
- /* Initialize local variables. */
- debug = 0;
- do_help = 0;
- do_version = 0;
-
- while ((opt = getopt_long (argc, argv, "dhV", long_options, NULL)) != -1)
- switch (opt)
- {
- case '\0': /* Long option. */
- break;
- case 'h':
- do_help = 1;
- break;
- case 'd':
- debug = 1;
- break;
- case 'V':
- do_version = 1;
- break;
- default:
- usage (EXIT_FAILURE);
- }
-
- /* Version information is reequested. */
- if (do_version)
- {
- printf ("utmpd (GNU %s) %s\n", PACKAGE, VERSION);
- printf (gettext ("\
-Copyright (C) %s Free Software Foundation, Inc.\n\
-This is free software; see the source for copying conditions. There is NO\n\
-warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
-"), "1997");
- printf (gettext ("Written by %s.\n"), "Mark Kettenis");
-
- exit (EXIT_SUCCESS);
- }
-
- /* Help is requested. */
- if (do_help)
- usage (EXIT_SUCCESS);
-
- signal (SIGINT, termination_handler);
- signal (SIGTERM, termination_handler);
-
- /* Check if we are already running. */
- if (check_pid (_PATH_UTMPDPID))
- error (EXIT_FAILURE, 0, "already running");
-
- /* Open UTMP database. */
- utmp_db = open_database (_PATH_UTMP "x", _PATH_UTMP);
- if (utmp_db == NULL)
- error (EXIT_FAILURE, errno, "%s", _PATH_UTMP);
-
- /* Create sockets, with the right permissions. */
- mask = umask (S_IXUSR | S_IXGRP | S_IXOTH);
- ro_sock = make_socket (_PATH_UTMPD_RO);
- umask (S_IXUSR | S_IRWXG | S_IRWXO);
- rw_sock = make_socket (_PATH_UTMPD_RW);
- umask (mask);
-
- /* Set the sockets up to accept connections. */
- if (listen (ro_sock, MAX_CONNECTIONS) < 0
- || listen (rw_sock, MAX_CONNECTIONS) < 0)
- error (EXIT_FAILURE, errno, "cannot enable socket to accept connections");
-
- /* Behave like a daemon. */
- if (!debug)
- {
- openlog ("utmpd", LOG_CONS | LOG_ODELAY, LOG_DAEMON);
-
- if (daemon (0, 0) < 0)
- error (EXIT_FAILURE, errno, "cannot auto-background");
- forked = 1;
-
- if (write_pid (_PATH_UTMPDPID) < 0)
- warning (errno, "%s", _PATH_UTMPDPID);
- }
-
- /* Drop priviliges. */
- drop_priviliges ();
-
- /* Handle incoming requests. */
- handle_requests ();
-}
-
-
-/* Display usage information and exit. */
-static void
-usage (int status)
-{
- if (status != EXIT_SUCCESS)
- fprintf (stderr, gettext ("Try `%s --help' for more information.\n"),
- program_invocation_name);
- else
- {
- printf (gettext ("\
-Usage: %s [OPTION]...\n\
- -d, --debug do not fork and display messages on the current tty\n\
- -h, --help display this help and exit\n\
- -V, --version output version information and exit\n"),
- program_invocation_name);
- fputs (gettext ("\
-Report bugs to <kettenis@phys.uva.nl>.\n"),
- stdout);
- }
-
- exit (status);
-}
-
-
-/* Drop priviliges. */
-static void
-drop_priviliges (void)
-{
- struct passwd *pw;
-
- pw = getpwnam ("daemon");
- if (pw)
- {
- seteuid (pw->pw_uid);
- setegid (pw->pw_gid);
- }
-}
-
-
-/* Make a socket in the file namespace using the filename NAME as the
- socket's address. */
-static int
-make_socket (const char *name)
-{
- struct sockaddr_un addr;
- size_t size;
- int sock;
-
- /* Create the socket. */
- sock = socket (PF_UNIX, SOCK_STREAM, 0);
- if (sock < 0)
- error (EXIT_FAILURE, errno, "cannot create socket");
-
- /* Bind a name to the socket. */
- addr.sun_family = AF_UNIX;
- strcpy (addr.sun_path, name);
-
- /* The size of the address is the offset of the start
- of the filename, plus its length, plus one for the
- terminating null byte. */
- size = (offsetof (struct sockaddr_un, sun_path)
- + strlen (addr.sun_path));
-
- if (bind (sock, (struct sockaddr *) &addr, size) < 0)
- error (EXIT_FAILURE, errno, "%s", name);
-
- return sock;
-}
-
-
-/* Hanlde incoming requests. */
-static
-void handle_requests (void)
-{
- client_connection *connection;
- fd_set active_read_fd_set;
- fd_set active_write_fd_set;
- fd_set read_fd_set;
- fd_set write_fd_set;
- int fd;
-
- /* Initialize the set of active sockets. */
- FD_ZERO (&active_read_fd_set);
- FD_ZERO (&active_write_fd_set);
- FD_SET (rw_sock, &active_read_fd_set);
- FD_SET (ro_sock, &active_read_fd_set);
-
- while (1)
- {
- /* Block until input arrives on one or more active sockets. */
- read_fd_set = active_read_fd_set;
- write_fd_set = active_write_fd_set;
- if (select (FD_SETSIZE, &read_fd_set, &write_fd_set, NULL, NULL) < 0)
- error (EXIT_FAILURE, errno, "cannot get input on sockets");
-
- /* Service all the sockets with input pending. */
- for (fd = 0; fd < FD_SETSIZE; fd++)
- {
- if (FD_ISSET (fd, &read_fd_set))
- {
- if (fd == ro_sock || fd == rw_sock)
- {
- int access = ((fd == rw_sock) ? (R_OK | W_OK) : R_OK);
-
- connection = accept_connection (fd, access);
- if (connection == NULL)
- error (0, errno, "cannot accept connection");
-
- FD_SET (connection->sock, &active_read_fd_set);
- }
- else
- {
- connection = find_connection (fd);
- if (connection == NULL)
- error (EXIT_FAILURE, 0, "cannot find connection");
-
- if (read_data (connection) < 0)
- {
- close_connection (connection);
- FD_CLR (fd, &active_read_fd_set);
- FD_CLR (fd, &active_write_fd_set);
- }
-
- if (connection->write_ptr > connection->write_base)
- FD_SET (fd, &active_write_fd_set);
- }
- }
- if (FD_ISSET (fd, &write_fd_set) &&
- fd != rw_sock && fd != ro_sock)
- {
- connection = find_connection (fd);
- if (connection == NULL)
- error (EXIT_FAILURE, 0, "cannot find connection");
-
- if (write_data (connection) < 0)
- {
- close_connection (connection);
- FD_CLR (fd, &active_read_fd_set);
- FD_CLR (fd, &active_write_fd_set);
- }
-
- if (connection->write_ptr == connection->write_base)
- FD_CLR (fd, &active_write_fd_set);
- }
- }
- }
-}
-
-
-/* Cleanup. */
-static void
-termination_handler (int signum)
-{
- /* Close sockets. */
- close (ro_sock);
- close (rw_sock);
-
- /* Restore user id. */
- seteuid (getuid ());
-
- /* Clean up the files created by `bind'. */
- unlink (_PATH_UTMPD_RO);
- unlink (_PATH_UTMPD_RW);
-
- if (utmp_db)
- close_database (utmp_db);
-
- /* Clean up pid file. */
- unlink (_PATH_UTMPDPID);
-
- exit (EXIT_SUCCESS);
-}
-
-
-/* Returns 1 if the process in pid file FILE is running, 0 if not. */
-static int
-check_pid (const char *file)
-{
- FILE *fp;
-
- fp = fopen (_PATH_UTMPDPID, "r");
- if (fp)
- {
- pid_t pid;
-
- fscanf (fp, "%d", &pid);
- fclose (fp);
-
- if (kill (pid, 0) == 0)
- return 1;
- }
-
- return 0;
-}
-
-/* Write the current process id to the file FILE. Returns 0 if
- successful, -1 if not. */
-static int
-write_pid (const char *file)
-{
- FILE *fp;
-
- fp = fopen (_PATH_UTMPDPID, "w");
- if (fp == NULL)
- return -1;
-
- fprintf (fp, "%d\n", getpid ());
- if (ferror (fp))
- return -1;
-
- fclose (fp);
-
- return 0;
-}
-
+++ /dev/null
-/* Copyright (C) 1997 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the GNU C Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
-
-#ifndef _UTMPD_H
-#define _UTMPD_H 1
-
-/* This is an *internal* header. */
-
-#include <limits.h>
-#include <stddef.h>
-#include <utmp.h>
-
-
-/* Paths to daemon sockets. */
-#define _PATH_UTMPD_RO "/var/run/utmpd.ro"
-#define _PATH_UTMPD_RW "/var/run/utmpd.rw"
-
-
-/* Path to PID file. */
-#define _PATH_UTMPDPID "/var/run/utmpd.pid"
-
-
-/* Version number of the daemon interface. */
-#define UTMPD_VERSION 1
-
-
-/* Services provided. */
-typedef enum
-{
- UTMPD_REQ_SETUTENT,
- UTMPD_REQ_GETUTENT,
- UTMPD_REQ_ENDUTENT,
- UTMPD_REQ_GETUTLINE,
- UTMPD_REQ_GETUTID,
- UTMPD_REQ_PUTUTLINE,
- UTMPD_REQ_UPDWTMP
-} request_type;
-
-
-/* Header common to all requests. */
-typedef struct
-{
- /* Version number of the daemon interface. */
- int version;
- /* Number of bytes in this request. */
- size_t size;
- /* Service requested. */
- request_type type;
-} request_header;
-
-typedef struct
-{
- request_header header;
- /* File to use. */
- char file[_POSIX_PATH_MAX + 1];
-} setutent_request;
-
-typedef struct
-{
- request_header header;
-} getutent_request, endutent_request;
-
-typedef struct
-{
- request_header header;
- /* Entry to match. */
- struct utmp line;
-} getutline_request;
-
-typedef struct
-{
- request_header header;
- /* Entry to match. */
- struct utmp id;
-} getutid_request;
-
-typedef struct
-{
- request_header header;
- /* Entry to write. */
- struct utmp utmp;
-} pututline_request;
-
-typedef struct
-{
- request_header header;
- /* File to use. */
- char file[_POSIX_PATH_MAX + 1];
- /* Entry to write. */
- struct utmp utmp;
-} updwtmp_request;
-
-
-/* Header common to all replies. */
-typedef struct
-{
- /* Version number of the daemon interface. */
- int version;
- /* Number of bytes in this reply. */
- size_t size;
- /* Answer to the request. */
- request_type type;
-} reply_header;
-
-typedef struct
-{
- reply_header header;
- /* Error code. */
- int errnum;
- /* Return value. */
- int result;
-} setutent_reply, endutent_reply, pututline_reply, updwtmp_reply;
-
-typedef struct
-{
- reply_header header;
- /* Found entry. */
- struct utmp entry;
- /* Error code. */
- int errnum;
- /* Return value. */
- int result;
-} getutent_reply, getutline_reply, getutid_reply;
-
-#endif /* utmpd.h */
+++ /dev/null
-/* Copyright (C) 1997 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the GNU C Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
-
-#include <fcntl.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <utmp.h>
-
-#include "xtmp.h"
-
-/* Convert the entry XT to the new utmp format and store it in UT.
- Fields in UT that were not present in the old utmp format are
- initialized to zero. */
-void
-xtmp_to_utmp (const struct xtmp *xtmp, struct utmp *utmp)
-{
- memset (utmp, 0, sizeof (struct utmp));
-#if _HAVE_XT_TYPE - 0
- utmp->ut_type = xtmp->xt_type;
-#endif
-#if _HAVE_XT_PID - 0
- utmp->ut_pid = xtmp->xt_pid;
-#endif
- strncpy (utmp->ut_line, xtmp->xt_line, XT_LINESIZE);
-#if _HAVE_XT_ID - 0
- strncpy (utmp->ut_id, xtmp->xt_id, sizeof xtmp->xt_id);
-#endif
- utmp->ut_time = xtmp->xt_time;
- strncpy (utmp->ut_user, xtmp->xt_user, XT_NAMESIZE);
-#if _HAVE_XT_HOST - 0
- strncpy (utmp->ut_host, xtmp->xt_host, XT_HOSTSIZE);
-#endif
- utmp->ut_addr = xtmp->xt_addr;
-}
-
-/* Convert the entry UTMP to the old utmp format and store it in XTMP. */
-void
-utmp_to_xtmp (const struct utmp *utmp, struct xtmp *xtmp)
-{
- memset (xtmp, 0, sizeof (struct xtmp));
-#if _HAVE_XT_TYPE - 0
- xtmp->xt_type = utmp->ut_type;
-#endif
-#if _HAVE_XT_PID - 0
- xtmp->xt_pid = utmp->ut_pid;
-#endif
- strncpy (xtmp->xt_line, utmp->ut_line, XT_LINESIZE);
- xtmp->xt_line[XT_LINESIZE] = '\0';
-#if _HAVE_XT_ID - 0
- strncpy (xtmp->xt_id, utmp->ut_id, sizeof xtmp->xt_id);
-#endif
- xtmp->xt_time = utmp->ut_time;
- strncpy (xtmp->xt_user, utmp->ut_user, XT_NAMESIZE);
-#if _HAVE_XT_HOST - 0
- strncpy (xtmp->xt_host, utmp->ut_host, XT_HOSTSIZE);
- xtmp->xt_host[XT_HOSTSIZE] = '\0';
-#endif
- xtmp->xt_addr = utmp->ut_addr;
-}
-
-/* Compare an old style entry XTMP with a new style entry UTMP. The
- function returns 1 if the information that is in both old and new
- style entries is identical. Otherwise this function returns 0. */
-int
-compare_entry (const struct utmp *xtmp, const struct utmp *utmp)
-{
- return
- (
-#if _HAVE_XT_TYPE - 0
- xtmp->ut_type == utmp->ut_type
-#endif
-#if _HAVE_XT_PID - 0
- && xtmp->ut_pid == utmp->ut_pid
-#endif
- && !strncmp (xtmp->ut_line, utmp->ut_line, XT_LINESIZE - 1)
-#if _HAVE_XT_ID - 0
- && !strncmp (xtmp->ut_id, utmp->ut_id, sizeof utmp->ut_id)
-#endif
- && xtmp->ut_time == utmp->ut_time
- && !strncmp (xtmp->ut_user, utmp->ut_user, XT_NAMESIZE)
-#if _HAVE_XT_HOST - 0
- && !strncmp (xtmp->ut_host, utmp->ut_host, XT_HOSTSIZE - 1)
-#endif
- && xtmp->ut_addr == utmp->ut_addr);
-}
+++ /dev/null
-/* The `struct xtmp' type, describing the old linux utmp format.
- Copyright (C) 1997 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the GNU C Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
-
-#ifndef _XTMP_H
-#define _XTMP_H 1
-#include <features.h>
-
-#include <sys/time.h>
-#include <sys/types.h>
-
-
-#define XT_LINESIZE 12
-#define XT_NAMESIZE 8
-#define XT_HOSTSIZE 16
-
-struct xtmp
-{
- short int xt_type; /* Type of login. */
- pid_t xt_pid; /* Pid of login process. */
- char xt_line[XT_LINESIZE]; /* NUL-terminated devicename of tty. */
- char xt_id[4]; /* Inittab id. */
- time_t xt_time; /* Time entry was made. */
- char xt_user[XT_NAMESIZE]; /* Username (not NUL terminated). */
- char xt_host[XT_HOSTSIZE]; /* Hostname for remote login. */
- long xt_addr; /* Internet adress of remote host. */
-};
-
-#define _HAVE_XT_TYPE 1
-#define _HAVE_XT_PID 1
-#define _HAVE_XT_ID 1
-#define _HAVE_XT_HOST 1
-
-
-extern void xtmp_to_utmp (const struct xtmp *xtmp, struct utmp *utmp);
-extern void utmp_to_xtmp (const struct utmp *utmp, struct xtmp *xtmp);
-extern int compare_entry (const struct utmp *xtmp,
- const struct utmp *utmp);
-
-#endif /* xtmp.h */
+++ /dev/null
-/* utmpdump - dump utmp-like files.
- Copyright (C) 1997 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the GNU C Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
-
-#include <errno.h>
-#include <error.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <time.h>
-#include <unistd.h>
-#include <utmp.h>
-
-void
-print_entry (struct utmp *up)
-{
- printf ("[%d] [%05d] [%-4.4s] [%-8.8s] [%-12.12s] [%-15.15s] [%ld]\n",
- up->ut_type, up->ut_pid, up->ut_id, up->ut_user,
- up->ut_line, 4 + ctime (&up->ut_time), up->ut_tv.tv_usec);
-}
-
-int
-main (int argc, char *argv[])
-{
- struct utmp *up;
-
- if (argc > 1)
- utmpname (argv[1]);
-
- setutent ();
-
- while ((up = getutent ()))
- print_entry (up);
-
- endutent ();
-
- return EXIT_SUCCESS;
-}
standards each function or symbol comes from.
@menu
-* ISO C:: The international standard for the C
+* ISO C:: The international standard for the C
programming language.
* POSIX:: The ISO/IEC 9945 (aka IEEE 1003) standards
for operating systems.
* Berkeley Unix:: BSD and SunOS.
* SVID:: The System V Interface Description.
+* XPG:: The X/Open Portability Guide.
@end menu
@node ISO C, POSIX, , Standards and Portability
to write programs to work portably under multiple C dialects, but does
not aim for completeness.
+
@node POSIX, Berkeley Unix, ISO C, Standards and Portability
@subsection POSIX (The Portable Operating System Interface)
@cindex POSIX
@cindex POSIX.1
@cindex IEEE Std 1003.1
+@cindex ISO/IEC 9945-1
@cindex POSIX.2
@cindex IEEE Std 1003.2
+@cindex ISO/IEC 9945-2
-The GNU library is also compatible with the IEEE @dfn{POSIX} family of
+The GNU library is also compatible with the ISO @dfn{POSIX} family of
standards, known more formally as the @dfn{Portable Operating System
-Interface for Computer Environments}. POSIX is derived mostly from
-various versions of the Unix operating system.
+Interface for Computer Environments} (ISO/IEC 9945). They were also
+published as ANSI/IEEE Std 1003. POSIX is derived mostly from various
+versions of the Unix operating system.
The library facilities specified by the POSIX standards are a superset
of those required by @w{ISO C}; POSIX specifies additional features for
system environments.@refill
The GNU C library implements all of the functions specified in
-@cite{IEEE Std 1003.1-1990, the POSIX System Application Program
+@cite{ISO/IEC 9945-1:1996, the POSIX System Application Program
Interface}, commonly referred to as POSIX.1. The primary extensions to
the @w{ISO C} facilities specified by this standard include file system
interface primitives (@pxref{File System Interface}), device-specific
terminal control functions (@pxref{Low-Level Terminal Interface}), and
process control functions (@pxref{Processes}).
-Some facilities from @cite{IEEE Std 1003.2-1992, the POSIX Shell and
+Some facilities from @cite{ISO/IEC 9945-2:1993, the POSIX Shell and
Utilities standard} (POSIX.2) are also implemented in the GNU library.
These include utilities for dealing with regular expressions and other
pattern matching facilities (@pxref{Pattern Matching}).
@code{select} function (@pxref{Waiting for I/O}), the BSD signal
functions (@pxref{BSD Signal Handling}), and sockets (@pxref{Sockets}).
-@node SVID, , Berkeley Unix, Standards and Portability
+@node SVID, XPG, Berkeley Unix, Standards and Portability
@subsection SVID (The System V Interface Description)
@cindex SVID
@cindex System V Unix
the AT&T Unix System V operating system. It is to some extent a
superset of the POSIX standard (@pxref{POSIX}).
-The GNU C library defines some of the facilities required by the SVID
+The GNU C library defines most of the facilities required by the SVID
that are not also required by the @w{ISO C} or POSIX standards, for
compatibility with System V Unix and other Unix systems (such as
SunOS) which include these facilities. However, many of the more
obscure and less generally useful facilities required by the SVID are
not included. (In fact, Unix System V itself does not provide them all.)
-@c !!! mention sysv ipc/shmem when it is there.
+The supported facilities from System V include the methods for
+inter-process communication and shared memory, the @code{hsearch} and
+@code{drand48} families of functions, @code{fmtmsg} and several of the
+mathematical functions.
+
+@node XPG, , SVID, Standards and Portability
+@subsection XPG (The X/Open Portability Guide)
+
+The X/Open Portability Guide, published by the X/Open Company, Ltd., is
+a more general standard than POSIX. X/Open owns the Unix copyright and
+the XPG specifies the requirements for systems which are intended to be
+a Unix system.
+
+The GNU C library complies to the X/Open Portability Guide, Issue 4.2,
+with the with all extensions common to XSI (X/Open System Interface)
+compliant systems and also all X/Open UNIX extensions.
+
+The additions on top of POSIX are mainly derived from functionality
+available in @w{System V} and BSD systems. Some of the really bad
+mistakes in @w{System V} systems were corrected, though. Since
+fulfilling the XPG standard with the Unix extensions is a
+precondition for getting the Unix brand chances are good that the
+functionality is available on commercial systems.
@node Using the Library, Roadmap to the Manual, Standards and Portability, Introduction
@smallexample
#include <stdlib.h>
-int f (int *i) @{ return (abs (++*i)); @}
+int f (int *i) @{ return abs (++*i); @}
@end smallexample
@noindent
@smallexample
#include <stdlib.h>
-int g (int *i) @{ return ((abs)(++*i)); @}
+int g (int *i) @{ return (abs) (++*i); @}
#undef abs
-int h (int *i) @{ return (abs (++*i)); @}
+int h (int *i) @{ return abs (++*i); @}
@end smallexample
Since macro definitions that double for a function behave in
* Finding Tokens in a String:: Splitting a string into tokens by looking
for delimiters.
* Encode Binary Data:: Encoding and Decoding of Binary Data.
+* Argz and Envz Vectors:: Null-separated string vectors.
@end menu
@node Representation of Strings
this function does not modify the buffer pointer. Every call consumes 6
characters.
@end deftypefun
+
+@node Argz and Envz Vectors
+@section Argz and Envz Vectors
+
+@cindex argz vectors
+@cindex string vectors, null-character separated
+@cindex argument vectors, null-character separated
+@dfn{argz vectors} are vectors of strings in a contiguous block of
+memory, each element separated from its neighbors by null-characters
+(@code{'\0'}).
+
+@cindex envz vectors
+@cindex environment vectors, null-character separated
+@dfn{Envz vectors} are an extension of argz vectors where each element is a
+name-value pair, separated by a @code{'='} character (as in a unix
+environment).
+
+@menu
+* Argz Functions:: Operations on argz vectors.
+* Envz Functions:: Additional operations on environment vectors.
+@end menu
+
+@node Argz Functions, Envz Functions, , Argz and Envz Vectors
+@subsection Argz Functions
+
+Each argz vector is represented by a pointer to the first element, of
+type @code{char *}, and a size, of type @code{size_t}, both of which can
+be initialized to @code{0} to represent an empty argz vector. All argz
+functions accept either a pointer and a size argument, or pointers to
+them, if they will be modified.
+
+The argz functions use @code{malloc}/@code{realloc} to allocate/grow
+argz vectors, and so any argz vector creating using these functions may
+be freed by using @code{free}; conversely, any argz function that may
+grow a string expects that string to have been allocated using
+@code{malloc} (those argz functions that only examine their arguments or
+modify them in place will work on any sort of memory).
+@xref{Unconstrained Allocation}.
+
+All argz functions that do memory allocation have a return type of
+@code{error_t}, and return @code{0} for success, and @code{ENOMEM} if an
+allocation error occurs.
+
+@pindex argz.h
+These functions are declared in the standard include file @file{argz.h}.
+
+@deftypefun {error_t} argz_create (char *const @var{argv}[], char **@var{argz}, size_t *@var{argz_len})
+The @code{argz_create} function converts the unix-style argument vector
+@var{argv} (a vector of pointers to normal C strings, terminated by
+@code{(char *)0}; @pxref{Program Arguments}) into an argz vector with
+the same elements, which is returned in @var{argz} and @var{argz_len}.
+@end deftypefun
+
+@deftypefun {error_t} argz_create_sep (const char *@var{string}, int @var{sep}, char **@var{argz}, size_t *@var{argz_len})
+The @code{argz_create_sep} function converts the null-terminated string
+@var{string} into an argz vector (returned in @var{argz} and
+@var{argz_len}) by splitting it into elements at every occurance of the
+character @var{sep}.
+@end deftypefun
+
+@deftypefun {size_t} argz_count (const char *@var{argz}, size_t @var{arg_len})
+Returns the number of elements in the argz vector @var{argz} and
+@var{argz_len}.
+@end deftypefun
+
+@deftypefun {void} argz_extract (char *@var{argz}, size_t @var{argz_len}, char **@var{argv})
+The @code{argz_extract} function converts the argz vector @var{argz} and
+@var{argz_len} into a unix-style argument vector stored in @var{argv},
+by putting pointers to every element in @var{argz} into successive
+positions in @var{argv}, followed by a terminator of @code{0}.
+@var{Argv} must be pre-allocated with enough space to hold all the
+elements in @var{argz} plus the terminating @code{(char *)0}
+(@code{(argz_count (@var{argz}, @var{argz_len}) + 1) * sizeof (char *)}
+bytes should be enough). Note that the string pointers stored into
+@var{argv} point into @var{argz}---they are not copies---and so
+@var{argz} must be copied if it will be changed while @var{argv} is
+still active. This function is useful for passing the elements in
+@var{argz} to an exec function (@pxref{Executing a File}).
+@end deftypefun
+
+@deftypefun {void} argz_stringify (char *@var{argz}, size_t @var{len}, int @var{sep})
+The @code{argz_stringify} converts @var{argz} into a normal string with
+the elements separated by the character @var{sep}, by replacing each
+@code{'\0'} inside @var{argz} (except the last one, which terminates the
+string) with @var{sep}. This is handy for printing @var{argz} in a
+readable manner.
+@end deftypefun
+
+@deftypefun {error_t} argz_add (char **@var{argz}, size_t *@var{argz_len}, const char *@var{str})
+The @code{argz_add} function adds the string @var{str} to the end of the
+argz vector @code{*@var{argz}}, and updates @code{*@var{argz}} and
+@code{*@var{argz_len}} accordingly.
+@end deftypefun
+
+@deftypefun {error_t} argz_add_sep (char **@var{argz}, size_t *@var{argz_len}, const char *@var{str}, int @var{delim})
+The @code{argz_add_sep} function is similar to @code{argz_add}, but
+@var{str} is split into separate elements in the result at occurances of
+the character @var{delim}. This is useful, for instance, for
+adding the components of a unix search path to an argz vector, by using
+a value of @code{':'} for @var{delim}.
+@end deftypefun
+
+@deftypefun {error_t} argz_append (char **@var{argz}, size_t *@var{argz_len}, const char *@var{buf}, size_t @var{buf_len})
+The @code{argz_append} function appends @var{buf_len} bytes starting at
+@var{buf} to the argz vector @code{*@var{argz}}, reallocating
+@code{*@var{argz}} to accommodate it, and adding @var{buf_len} to
+@code{*@var{argz_len}}.
+@end deftypefun
+
+@deftypefun {error_t} argz_delete (char **@var{argz}, size_t *@var{argz_len}, char *@var{entry})
+If @var{entry} points to the beginning of one of the elements in the
+argz vector @code{*@var{argz}}, the @code{argz_delete} function will
+remove this entry and reallocate @code{*@var{argz}}, modifying
+@code{*@var{argz}} and @code{*@var{argz_len}} accordingly. Note that as
+destructive argz functions usually reallocate their argz argument,
+pointers into argz vectors such as @var{entry} will then become invalid.
+@end deftypefun
+
+@deftypefun {error_t} argz_insert (char **@var{argz}, size_t *@var{argz_len}, char *@var{before}, const char *@var{entry})
+The @code{argz_insert} function inserts the string @var{entry} into the
+argz vector @code{*@var{argz}} at a point just before the existing
+element pointed to by @var{before}, reallocating @code{*@var{argz}} and
+updating @code{*@var{argz}} and @code{*@var{argz_len}}. If @var{before}
+is @code{0}, @var{entry} is added to the end instead (as if by
+@code{argz_add}). Since the first element is in fact the same as
+@code{*@var{argz}}, passing in @code{*@var{argz}} as the value of
+@var{before} will result in @var{entry} being inserted at the beginning.
+@end deftypefun
+
+@deftypefun {char *} argz_next (char *@var{argz}, size_t @var{argz_len}, const char *@var{entry})
+The @code{argz_next} function provides a convenient way of iterating
+over the elements in the argz vector @var{argz}. It returns a pointer
+to the next element in @var{argz} after the element @var{entry}, or
+@code{0} if there are no elements following @var{entry}. If @var{entry}
+is @code{0}, the first element of @var{argz} is returned.
+
+This behavior suggests two styles of iteration:
+
+@smallexample
+ char *entry = 0;
+ while ((entry = argz_next (@var{argz}, @var{argz_len}, entry)))
+ @var{action};
+@end smallexample
+
+(the double parentheses are necessary to make some C compilers shut up
+about what they consider a questionable @code{while}-test) and:
+
+@smallexample
+ char *entry;
+ for (entry = @var{argz};
+ entry;
+ entry = argz_next (@var{argz}, @var{argz_len}, entry))
+ @var{action};
+@end smallexample
+
+Note that the latter depends on @var{argz} having a value of @code{0} if
+it is empty (rather than a pointer to an empty block of memory); this
+invariant is maintained for argz vectors created by the functions here.
+@end deftypefun
+
+@node Envz Functions, , Argz Functions, Argz and Envz Vectors
+@subsection Envz Functions
+
+Envz vectors are just argz vectors with additional constraints on the form
+of each element; as such, argz functions can also be used on them, where it
+makes sense.
+
+Each element in an envz vector is a name-value pair, separated by a @code{'='}
+character; if multiple @code{'='} characters are present in an element, those
+after the first are considered part of the value, and treated like all other
+non-@code{'\0'} characters.
+
+If @emph{no} @code{'='} characters are present in an element, that element is
+considered the name of a ``null'' entry, as distinct from an entry with an
+empty value: @code{envz_get} will return @code{0} if given the name of null
+entry, whereas an entry with an empty value would result in a value of
+@code{""}; @code{envz_entry} will still find such entries, however. Null
+entries can be removed with @code{envz_strip} function.
+
+As with argz functions, envz functions that may allocate memory (and thus
+fail) have a return type of @code{error_t}, and return either @code{0} or
+@code{ENOMEM}.
+
+@pindex envz.h
+These functions are declared in the standard include file @file{envz.h}.
+
+@deftypefun {char *} envz_entry (const char *@var{envz}, size_t @var{envz_len}, const char *@var{name})
+The @code{envz_entry} function finds the entry in @var{envz} with the name
+@var{name}, and returns a pointer to the whole entry---that is, the argz
+element which begins with @var{name} followed by a @code{'='} character. If
+there is no entry with that name, @code{0} is returned.
+@end deftypefun
+
+@deftypefun {char *} envz_get (const char *@var{envz}, size_t @var{envz_len}, const char *@var{name})
+The @code{envz_get} function finds the entry in @var{envz} with the name
+@var{name} (like @code{envz_entry}), and returns a pointer to the value
+portion of that entry (following the @code{'='}). If there is no entry with
+that name (or only a null entry), @code{0} is returned.
+@end deftypefun
+
+@deftypefun {error_t} envz_add (char **@var{envz}, size_t *@var{envz_len}, const char *@var{name}, const char *@var{value})
+The @code{envz_add} function adds an entry to @code{*@var{envz}}
+(updating @code{*@var{envz}} and @code{*@var{envz_len}}) with the name
+@var{name}, and value @var{value}. If an entry with the same name
+already exists in @var{envz}, it is removed first. If @var{value} is
+@code{0}, then the new entry will the special null type of entry
+(mentioned above).
+@end deftypefun
+
+@deftypefun {error_t} envz_merge (char **@var{envz}, size_t *@var{envz_len}, const char *@var{envz2}, size_t @var{envz2_len}, int @var{override})
+The @code{envz_merge} function adds each entry in @var{envz2} to @var{envz},
+as if with @code{envz_add}, updating @code{*@var{envz}} and
+@code{*@var{envz_len}}. If @var{override} is true, then values in @var{envz2}
+will supersede those with the same name in @var{envz}, otherwise not.
+
+Null entries are treated just like other entries in this respect, so a null
+entry in @var{envz} can prevent an entry of the same name in @var{envz2} from
+being added to @var{envz}, if @var{override} is false.
+@end deftypefun
+
+@deftypefun {void} envz_strip (char **@var{envz}, size_t *@var{envz_len})
+The @code{envz_strip} function removes any null entries from @var{envz},
+updating @code{*@var{envz}} and @code{*@var{envz_len}}.
+@end deftypefun
md5-routines := crypt-entry md5-crypt md5
libcrypt-routines := $(md5-routines)
+onlymd5-routines := onlymd5-entry md5-crypt md5
+distribute += onlymd5-entry
+
include ../Makeconfig
rpath-link := $(common-objpfx)md5-crypt:$(rpath-link)
define o-iterator-doit
$(objpfx)$(patsubst %,$(libtype$o),md5crypt): \
- $(md5-routines:%=$(objpfx)%$o); $$(build-extra-lib)
+ $(onlymd5-routines:%=$(objpfx)%$o); $$(build-extra-lib)
endef
object-suffixes-left = $(object-suffixes)
include $(patsubst %,$(..)o-iterator.mk,$(object-suffixes))
# This ensures they will load libc.so for needed symbols if loaded by
# a statically-linked program that hasn't already loaded it.
$(objpfx)libcrypt.so: $(common-objpfx)libc.so
+$(objpfx)libmd5crypt.so: $(common-objpfx)libc.so
/* Prototypes for local functions. */
-extern char *md5_crypt_r __P ((const char *key, const char *salt, char *buffer,
- int buflen));
+extern char *__md5_crypt_r __P ((const char *key, const char *salt,
+ char *buffer, int buflen));
+extern char *md5_crypt_r __P ((const char *key, const char *salt,
+ char *buffer, int buflen));
extern char *md5_crypt __P ((const char *key, const char *salt));
/* This entry point is equivalent to the `crypt' function in Unix
libcs. */
char *
-md5_crypt_r (key, salt, buffer, buflen)
+__md5_crypt_r (key, salt, buffer, buflen)
const char *key;
const char *salt;
char *buffer;
/* Now we can construct the result string. It consists of three
parts. */
- cp = stpncpy (buffer, md5_salt_prefix, MAX (0, buflen));
+ cp = __stpncpy (buffer, md5_salt_prefix, MAX (0, buflen));
buflen -= sizeof (md5_salt_prefix);
- cp = stpncpy (cp, salt, MIN ((size_t) buflen, salt_len));
+ cp = __stpncpy (cp, salt, MIN ((size_t) buflen, salt_len));
buflen -= MIN ((size_t) buflen, salt_len);
if (buflen > 0)
return buffer;
}
+weak_alias (__md5_crypt_r, md5_crypt_r)
char *
-md5_crypt (key, salt)
+__md5_crypt (key, salt)
const char *key;
const char *salt;
{
return NULL;
}
- return md5_crypt_r (key, salt, buffer, buflen);
+ return __md5_crypt_r (key, salt, buffer, buflen);
}
+weak_alias (__md5_crypt, md5_crypt)
/* md5.c - Functions to compute MD5 message digest of files or memory blocks
according to the definition of MD5 in RFC 1321 from April 1992.
- Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
# if __BYTE_ORDER == __BIG_ENDIAN
# define WORDS_BIGENDIAN 1
# endif
+/* We need to keep the namespace clean so define the MD5 function
+ protected using leading __ and use weak aliases. */
+# define md5_init_ctx __md5_init_ctx
+# define md5_process_block __md5_process_block
+# define md5_process_bytes __md5_process_bytes
+# define md5_finish_ctx __md5_finish_ctx
+# define md5_read_ctx __md5_read_ctx
+# define md5_stream __md5_stream
+# define md5_buffer __md5_buffer
#endif
#ifdef WORDS_BIGENDIAN
ctx->C = C;
ctx->D = D;
}
+
+
+#ifdef _LIBC
+/* Define weak aliases. */
+# undef md5_init_ctx
+weak_alias (__md5_init_ctx, md5_init_ctx)
+# undef md5_process_block
+weak_alias (__md5_process_block, md5_process_block)
+# undef md5_process_bytes
+weak_alias (__md5_process_bytes, md5_process_bytes)
+# undef md5_finish_ctx
+weak_alias (__md5_finish_ctx, md5_finish_ctx)
+# undef md5_read_ctx
+weak_alias (__md5_read_ctx, md5_read_ctx)
+# undef md5_stream
+weak_alias (__md5_stream, md5_stream)
+# undef md5_buffer
+weak_alias (__md5_buffer, md5_buffer)
+#endif
-/* md5.h - Declaration of functions and data types used for MD5 sum
- computing library functions.
- Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+/* Declaration of functions and data types used for MD5 sum computing
+ library functions.
+ Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
/* Initialize structure containing state of computation.
(RFC 1321, 3.3: Step 3) */
+extern void __md5_init_ctx __P ((struct md5_ctx *ctx));
extern void md5_init_ctx __P ((struct md5_ctx *ctx));
/* Starting with the result of former calls of this function (or the
initialization function update the context for the next LEN bytes
starting at BUFFER.
It is necessary that LEN is a multiple of 64!!! */
+extern void __md5_process_block __P ((const void *buffer, size_t len,
+ struct md5_ctx *ctx));
extern void md5_process_block __P ((const void *buffer, size_t len,
struct md5_ctx *ctx));
initialization function update the context for the next LEN bytes
starting at BUFFER.
It is NOT required that LEN is a multiple of 64. */
+extern void __md5_process_bytes __P ((const void *buffer, size_t len,
+ struct md5_ctx *ctx));
extern void md5_process_bytes __P ((const void *buffer, size_t len,
struct md5_ctx *ctx));
IMPORTANT: On some systems it is required that RESBUF is correctly
aligned for a 32 bits value. */
+extern void *__md5_finish_ctx __P ((struct md5_ctx *ctx, void *resbuf));
extern void *md5_finish_ctx __P ((struct md5_ctx *ctx, void *resbuf));
IMPORTANT: On some systems it is required that RESBUF is correctly
aligned for a 32 bits value. */
+extern void *__md5_read_ctx __P ((const struct md5_ctx *ctx, void *resbuf));
extern void *md5_read_ctx __P ((const struct md5_ctx *ctx, void *resbuf));
/* Compute MD5 message digest for bytes read from STREAM. The
resulting message digest number will be written into the 16 bytes
beginning at RESBLOCK. */
+extern int __md5_stream __P ((FILE *stream, void *resblock));
extern int md5_stream __P ((FILE *stream, void *resblock));
/* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
result is always in little endian byte order, so that a byte-wise
output yields to the wanted ASCII representation of the message
digest. */
-extern void *md5_buffer __P ((const char *buffer, size_t len, void *resblock));
+extern void *__md5_buffer __P ((const char *buffer, size_t len,
+ void *resblock));
+extern void *md5_buffer __P ((const char *buffer, size_t len,
+ void *resblock));
#endif
--- /dev/null
+#include <sysdeps/generic/crypt-entry.c>
/* Get implementation for some internal functions. */
#include "../resolv/mapv4v6addr.h"
-#include "../resolv/mapv4v6hostent.h"
#define ENTNAME hostent
/* These are not #ifdef __USE_POSIX2 because they are
in the theoretically application-owned namespace. */
-#define _POSIX2_C_VERSION 199912L /* Invalid until 1003.2 is done. */
+#define _POSIX2_C_VERSION 199209L /* Invalid until 1003.2 is done. */
/* If defined, the implementation supports the
C Language Bindings Option. */
int __severity, __const char *__text,
__const char *__action, __const char *__tag));
+#ifdef __USE_SVID
/* Add or remove severity level. */
extern int addseverity __P ((int __severity, __const char *__string));
+#endif
__END_DECLS
};
static void
-findkind (const char **mark, token * tokp)
+findkind (const char **mark, token *tokp)
{
int len;
- token *s;
+ const token *s;
const char *str;
char *tmp;
static const char *
toktostr (tok_kind kind)
{
- token *sp;
+ const token *sp;
for (sp = tokstrings; sp->kind != TOK_EOF && sp->kind != kind; sp++);
- return (sp->str);
+ return sp->str;
}
static void
#include <stdlib.h>
void
-__bb_init_func (bb)
- struct __bb *bb;
+__bb_init_func (struct __bb *bb)
{
struct gmonparam *p = &_gmonparam;
/* Prototypes for the MD5 encryption replacement functions. */
-extern char *md5_crypt_r (const char *key, const char *salt, char *buffer,
- int buflen);
-extern char *md5_crypt (const char *key, const char *salt);
+extern char *__md5_crypt_r (const char *key, const char *salt, char *buffer,
+ int buflen);
+extern char *__md5_crypt (const char *key, const char *salt);
/* We recognize an intended call of the MD5 crypt replacement function
by the first 3 characters of the salt string. If they match the
MD5 magic string we want MD5 encryption replacement. */
char *
-crypt_r (key, salt, data)
+__crypt_r (key, salt, data)
const char *key;
const char *salt;
struct crypt_data *data;
{
if (strncmp (md5_salt_prefix, salt, sizeof (md5_salt_prefix) - 1) == 0)
- return md5_crypt_r (key, salt, (char *) data, sizeof (struct crypt_data));
+ return __md5_crypt_r (key, salt, (char *) data,
+ sizeof (struct crypt_data));
/* We don't have DES encryption. */
__set_errno (EOPNOTSUPP);
return NULL;
}
+weak_alias (__crypt_r, crypt_r)
/* The same here, only we call the non-reentrant version. */
const char *salt;
{
if (strncmp (md5_salt_prefix, salt, sizeof (md5_salt_prefix) - 1) == 0)
- return md5_crypt (key, salt);
+ return __md5_crypt (key, salt);
/* We don't have DES encryption. */
__set_errno (EOPNOTSUPP);
close - close 1 __libc_close __close close
dup - dup 1 __dup dup
dup2 - dup2 2 __dup2 dup2
-fchdir - fchdir 1 fchdir
+fchdir - fchdir 1 __fchdir fchdir
fcntl - fcntl 3 __libc_fcntl __fcntl fcntl
fstatfs - fstatfs 2 __fstatfs fstatfs
fsync - fsync 1 __libc_fsync fsync
typedef long int __clock_t;
/* One element in the file descriptor mask array. */
-typedef unsigned int __fd_mask;
+typedef unsigned long int __fd_mask;
/* Due to incaution, we may have gotten these from a kernel header file. */
#undef __FD_SETSIZE
*/
#ifndef _INTTYPES_H
+
#define _INTTYPES_H 1
+#include <features.h>
/* Exact integral types. */
#define UINTPTR_MAX (4294967295U)
-/* Macros for creating constants. */
-#define __CONCAT__(A, B) A ## B
-
/* Signed. */
#define INT8_C(c) ((int8_t) c)
#define INT16_C(c) ((int16_t) c)
#define INT32_C(c) ((int32_t) c)
-#define INT64_C(c) ((int64_t) __CONCAT__ (c,ll))
+#define INT64_C(c) ((int64_t) __CONCAT (c,ll))
/* Unsigned. */
-#define UINT8_C(c) ((uint8_t) __CONCAT__ (c,u))
-#define UINT16_C(c) ((uint16_t) __CONCAT__ (c,u))
-#define UINT32_C(c) ((uint32_t) __CONCAT__ (c,u))
-#define UINT64_C(c) ((uint64_t) __CONCAT__ (c,ull))
+#define UINT8_C(c) ((uint8_t) __CONCAT (c,u))
+#define UINT16_C(c) ((uint16_t) __CONCAT (c,u))
+#define UINT32_C(c) ((uint32_t) __CONCAT (c,u))
+#define UINT64_C(c) ((uint64_t) __CONCAT (c,ull))
/* Maximal type. */
-#define INTMAX_C(c) ((intmax_t) __CONCAT__ (c,ll))
-#define UINTMAX_C(c) ((uintmax_t) __CONCAT__ (c,ull))
+#define INTMAX_C(c) ((intmax_t) __CONCAT (c,ll))
+#define UINTMAX_C(c) ((uintmax_t) __CONCAT (c,ull))
/* Macros for printing format specifiers. */
*/
#ifndef _INTTYPES_H
+
#define _INTTYPES_H 1
+#include <features.h>
/* Exact integral types. */
#define UINTPTR_MAX (18446744073709551615uL)
-/* Macros for creating constants. */
-#define __CONCAT__(A, B) A ## B
-
/* Signed. */
#define INT8_C(c) ((int8_t) c)
#define INT16_C(c) ((int16_t) c)
#define INT32_C(c) ((int32_t) c)
-#define INT64_C(c) ((int64_t) __CONCAT__ (c,l))
+#define INT64_C(c) ((int64_t) __CONCAT (c,l))
/* Unsigned. */
-#define UINT8_C(c) ((uint8_t) __CONCAT__ (c,u))
-#define UINT16_C(c) ((uint16_t) __CONCAT__ (c,u))
-#define UINT32_C(c) ((uint32_t) __CONCAT__ (c,u))
-#define UINT64_C(c) ((uint64_t) __CONCAT__ (c,ul))
+#define UINT8_C(c) ((uint8_t) __CONCAT (c,u))
+#define UINT16_C(c) ((uint16_t) __CONCAT (c,u))
+#define UINT32_C(c) ((uint32_t) __CONCAT (c,u))
+#define UINT64_C(c) ((uint64_t) __CONCAT (c,ul))
/* Maximal type. */
-#define INTMAX_C(c) ((intmax_t) __CONCAT__ (c,ll))
-#define UINTMAX_C(c) ((uintmax_t) __CONCAT__ (c,ul))
+#define INTMAX_C(c) ((intmax_t) __CONCAT (c,l))
+#define UINTMAX_C(c) ((uintmax_t) __CONCAT (c,ul))
/* Macros for printing format specifiers. */
/* Macros for printing `intfast_t' and `uintfast_t'. */
-#define PRIdFAST "d"
-#define PRIoFAST "o"
-#define PRIxFAST "x"
-#define PRIuFAST "u"
+#define PRIdFAST "ld"
+#define PRIoFAST "lo"
+#define PRIxFAST "lx"
+#define PRIuFAST "lu"
/* Macros for printing `intptr_t' and `uintptr_t'. */
/* Macros for scaning `intfast_t' and `uintfast_t'. */
-#define SCNdFAST "d"
-#define SCNiFAST "i"
-#define SCNoFAST "o"
-#define SCNxFAST "x"
+#define SCNdFAST "ld"
+#define SCNiFAST "li"
+#define SCNoFAST "lo"
+#define SCNxFAST "lx"
/* Macros for scaning `intptr_t' and `uintptr_t'. */
#define SCNdPTR "ld"
test-tz-ENV = TZDIR=$(objpfx)testdata
-$(objpfx)tzselect: tzselect.ksh
+$(objpfx)tzselect: tzselect.ksh $(common-objpfx)config.make
sed -e 's%@KSH@%$(KSH)%g' \
-e 's%@TZDIR@%$(zonedir)%g' < $< > $@.new
chmod 555 $@.new