Back to index

glibc  2.9
utmpx32.c
Go to the documentation of this file.
00001 /* Copyright (C) 2008 Free Software Foundation, Inc.
00002    Contributed by Andreas Krebbel <Andreas.Krebbel@de.ibm.com>.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <sys/types.h>
00021 #include <utmp.h>
00022 #include <errno.h>
00023 #include <libc-symbols.h>
00024 
00025 #include "utmp32.h"
00026 #include "utmp-convert.h"
00027 
00028 #include "utmpx32.h"
00029 #include "utmpx-convert.h"
00030 
00031 /* Allocate a static buffer to be returned to the caller.  As well as
00032    with the existing version of these functions the caller has to be
00033    aware that the contents of this buffer will change with subsequent
00034    calls.  */
00035 #define ALLOCATE_UTMPX32_OUT(OUT)                \
00036   static struct utmpx32 *OUT = NULL;                    \
00037                                                  \
00038   if (OUT == NULL)                               \
00039     {                                            \
00040       OUT = malloc (sizeof (struct utmpx32));           \
00041       if (OUT == NULL)                                  \
00042        return NULL;                              \
00043     }
00044 
00045 /* Perform a lookup for a utmpx entry matching FIELD using function
00046    FUNC.  FIELD is converted to a 64 bit utmpx and the result is
00047    converted back to 32 bit utmpx.  */
00048 #define ACCESS_UTMPX_ENTRY(FUNC, FIELD)                 \
00049   struct utmpx in64;                             \
00050   struct utmpx *out64;                                  \
00051   ALLOCATE_UTMPX32_OUT (out32);                         \
00052                                                  \
00053   utmpx_convert32to64 (FIELD, &in64);                   \
00054   out64 = FUNC (&in64);                                 \
00055                                                  \
00056   if (out64 == NULL)                             \
00057     return NULL;                                 \
00058                                                  \
00059   utmpx_convert64to32 (out64, out32);                   \
00060                                                  \
00061   return out32;
00062 
00063 
00064 /* Get the next entry from the user accounting database.  */
00065 struct utmpx32 *
00066 getutxent32 (void)
00067 {
00068   struct utmpx *out64;
00069   ALLOCATE_UTMPX32_OUT (out32);
00070 
00071   out64 = getutxent ();
00072   if (!out64)
00073     return NULL;
00074 
00075   utmpx_convert64to32 (out64, out32);
00076   return out32;
00077 
00078 }
00079 symbol_version (getutxent32, getutxent, GLIBC_2.1);
00080 
00081 /* Get the user accounting database entry corresponding to ID.  */
00082 struct utmpx32 *
00083 getutxid32 (const struct utmpx32 *id)
00084 {
00085   ACCESS_UTMPX_ENTRY (getutxid, id);
00086 }
00087 symbol_version (getutxid32, getutxid, GLIBC_2.1);
00088 
00089 /* Get the user accounting database entry corresponding to LINE.  */
00090 struct utmpx32 *
00091 getutxline32 (const struct utmpx32 *line)
00092 {
00093   ACCESS_UTMPX_ENTRY (getutxline, line);
00094 }
00095 symbol_version (getutxline32, getutxline, GLIBC_2.1);
00096 
00097 /* Write the entry UTMPX into the user accounting database.  */
00098 struct utmpx32 *
00099 pututxline32 (const struct utmpx32 *utmpx)
00100 {
00101   ACCESS_UTMPX_ENTRY (pututxline, utmpx);
00102 }
00103 symbol_version (pututxline32, pututxline, GLIBC_2.1);
00104 
00105 /* Append entry UTMP to the wtmpx-like file WTMPX_FILE.  */
00106 void
00107 updwtmpx32 (const char *wtmpx_file, const struct utmpx32 *utmpx)
00108 {
00109   struct utmpx in64;
00110 
00111   utmpx_convert32to64 (utmpx, &in64);
00112   updwtmpx (wtmpx_file, &in64);
00113 }
00114 symbol_version (updwtmpx32, updwtmpx, GLIBC_2.1);
00115 
00116 /* Copy the information in UTMPX to UTMP.  */
00117 void
00118 getutmp32 (const struct utmpx32 *utmpx, struct utmp32 *utmp)
00119 {
00120   struct utmpx in64;
00121   struct utmp out64;
00122 
00123   utmpx_convert32to64 (utmpx, &in64);
00124   getutmp (&in64, &out64);
00125   utmp_convert64to32 (&out64, utmp);
00126 }
00127 symbol_version (getutmp32, getutmp, GLIBC_2.1.1);
00128 
00129 /* Copy the information in UTMP to UTMPX.  */
00130 void
00131 getutmpx32 (const struct utmp32 *utmp, struct utmpx32 *utmpx)
00132 {
00133   struct utmp in64;
00134   struct utmpx out64;
00135 
00136   utmp_convert32to64 (utmp, &in64);
00137   getutmpx (&in64, &out64);
00138   utmpx_convert64to32 (&out64, utmpx);
00139 }
00140 symbol_version (getutmpx32, getutmpx, GLIBC_2.1.1);