Back to index

glibc  2.9
sgetspent_r.c
Go to the documentation of this file.
00001 /* Copyright (C) 1996, 1997, 1998, 2005 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #include <ctype.h>
00020 #include <errno.h>
00021 #include <shadow.h>
00022 #include <stdio.h>
00023 #include <string.h>
00024 
00025 /* Define a line parsing function using the common code
00026    used in the nss_files module.  */
00027 
00028 #define STRUCTURE    spwd
00029 #define ENTNAME             spent
00030 struct spent_data {};
00031 
00032 /* Predicate which always returns false, needed below.  */
00033 #define FALSEP(arg) 0
00034 
00035 
00036 #include <nss/nss_files/files-parse.c>
00037 LINE_PARSER
00038 (,
00039  STRING_FIELD (result->sp_namp, ISCOLON, 0);
00040  if (line[0] == '\0'
00041      && (result->sp_namp[0] == '+' || result->sp_namp[0] == '-'))
00042    {
00043      result->sp_pwdp = NULL;
00044      result->sp_lstchg = 0;
00045      result->sp_min = 0;
00046      result->sp_max = 0;
00047      result->sp_warn = -1l;
00048      result->sp_inact = -1l;
00049      result->sp_expire = -1l;
00050      result->sp_flag = ~0ul;
00051    }
00052  else
00053    {
00054      STRING_FIELD (result->sp_pwdp, ISCOLON, 0);
00055      INT_FIELD_MAYBE_NULL (result->sp_lstchg, ISCOLON, 0, 10, (long int),
00056                         (long int) -1);
00057      INT_FIELD_MAYBE_NULL (result->sp_min, ISCOLON, 0, 10, (long int),
00058                         (long int) -1);
00059      INT_FIELD_MAYBE_NULL (result->sp_max, ISCOLON, 0, 10, (long int),
00060                         (long int) -1);
00061      while (isspace (*line))
00062        ++line;
00063      if (*line == '\0')
00064        {
00065         /* The old form.  */
00066         result->sp_warn = -1l;
00067         result->sp_inact = -1l;
00068         result->sp_expire = -1l;
00069         result->sp_flag = ~0ul;
00070        }
00071      else
00072        {
00073         INT_FIELD_MAYBE_NULL (result->sp_warn, ISCOLON, 0, 10, (long int),
00074                             (long int) -1);
00075         INT_FIELD_MAYBE_NULL (result->sp_inact, ISCOLON, 0, 10, (long int),
00076                             (long int) -1);
00077         INT_FIELD_MAYBE_NULL (result->sp_expire, ISCOLON, 0, 10, (long int),
00078                             (long int) -1);
00079         if (*line != '\0')
00080           INT_FIELD_MAYBE_NULL (result->sp_flag, FALSEP, 0, 10,
00081                              (unsigned long int), ~0ul)
00082         else
00083           result->sp_flag = ~0ul;
00084        }
00085    }
00086  )
00087 
00088 
00089 /* Read one shadow entry from the given stream.  */
00090 int
00091 __sgetspent_r (const char *string, struct spwd *resbuf, char *buffer,
00092               size_t buflen, struct spwd **result)
00093 {
00094   int parse_result = parse_line (strncpy (buffer, string, buflen),
00095                              resbuf, NULL, 0, &errno);
00096   *result = parse_result > 0 ? resbuf : NULL;
00097 
00098   return *result == NULL ? errno : 0;
00099 }
00100 weak_alias (__sgetspent_r, sgetspent_r)