~xnox/ubuntu/quantal/shadow/clear-locks

« back to all changes in this revision

Viewing changes to lib/gshadow.c

  • Committer: Bazaar Package Importer
  • Author(s): Nicolas Valcárcel Scerpella (Canonical)
  • Date: 2009-11-07 04:55:18 UTC
  • mfrom: (1.1.8 upstream) (18.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20091107045518-qqclg1lhinz6zv1i
Tags: 1:4.1.4.2-1ubuntu1
* Merged with debian unstable. Remaning changes (LP: #477299):
  - Ubuntu specific:
    + debian/login.defs: use SHA512 by default for password crypt routine.
  - debian/patches/495_stdout-encrypted-password: chpasswd can report
    password hashes on stdout (Debian bug 505640).
  - Rework 495_stdout-encrypted-password to cope with chpasswd using PAM.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * Copyright (c) 1990 - 1994, Julianne Frances Haugh
3
3
 * Copyright (c) 1996 - 1998, Marek Michałkiewicz
4
4
 * Copyright (c) 2005       , Tomasz Kłoczko
5
 
 * Copyright (c) 2008       , Nicolas François
 
5
 * Copyright (c) 2008 - 2009, Nicolas François
6
6
 * All rights reserved.
7
7
 *
8
8
 * Redistribution and use in source and binary forms, with or without
35
35
/* Newer versions of Linux libc already have shadow support.  */
36
36
#if defined(SHADOWGRP) && !defined(HAVE_SHADOWGRP)      /*{ */
37
37
 
38
 
#ident "$Id: gshadow.c 2773 2009-04-23 11:53:55Z nekral-guest $"
 
38
#ident "$Id: gshadow.c 3020 2009-06-12 17:50:24Z nekral-guest $"
39
39
 
40
40
#include <stdio.h>
41
41
#include "prototypes.h"
42
42
#include "defines.h"
43
43
static /*@null@*/FILE *shadow;
44
 
static char sgrbuf[BUFSIZ * 4];
45
44
static /*@null@*//*@only@*/char **members = NULL;
46
45
static size_t nmembers = 0;
47
46
static /*@null@*//*@only@*/char **admins = NULL;
131
130
 
132
131
/*@observer@*//*@null@*/struct sgrp *sgetsgent (const char *string)
133
132
{
 
133
        static char *sgrbuf = NULL;
 
134
        static size_t sgrbuflen = 0;
 
135
 
134
136
        char *fields[FIELDS];
135
137
        char *cp;
136
138
        int i;
137
 
 
138
 
        strncpy (sgrbuf, string, sizeof sgrbuf - 1);
139
 
        sgrbuf[sizeof sgrbuf - 1] = '\0';
 
139
        size_t len = strlen (string) + 1;
 
140
 
 
141
        if (len > sgrbuflen) {
 
142
                char *buf = (char *) realloc (sgrbuf, sizeof (char) * len);
 
143
                if (NULL == buf) {
 
144
                        return NULL;
 
145
                }
 
146
                sgrbuf = buf;
 
147
                sgrbuflen = len;
 
148
        }
 
149
 
 
150
        strncpy (sgrbuf, string, len);
 
151
        sgrbuf[len-1] = '\0';
140
152
 
141
153
        cp = strrchr (sgrbuf, '\n');
142
154
        if (NULL != cp) {
161
173
         * the line is invalid.
162
174
         */
163
175
 
164
 
        if ((NULL != cp) || (i != FIELDS))
 
176
        if ((NULL != cp) || (i != FIELDS)) {
165
177
#ifdef  USE_NIS
166
178
                if (!IS_NISCHAR (fields[0][0])) {
167
179
                        return 0;
171
183
#else
172
184
                return 0;
173
185
#endif
 
186
        }
174
187
 
175
188
        sgroup.sg_name = fields[0];
176
189
        sgroup.sg_passwd = fields[1];
199
212
 
200
213
/*@observer@*//*@null@*/struct sgrp *fgetsgent (/*@null@*/FILE * fp)
201
214
{
202
 
        char buf[sizeof sgrbuf];
 
215
        static size_t buflen = 0;
 
216
        static char *buf = NULL;
 
217
 
203
218
        char *cp;
 
219
        struct sgrp *ret;
 
220
 
 
221
        if (0 == buflen) {
 
222
                buf = (char *) malloc (BUFSIZ);
 
223
                if (NULL == buf) {
 
224
                        return NULL;
 
225
                }
 
226
        }
204
227
 
205
228
        if (NULL == fp) {
206
 
                return (0);
 
229
                return NULL;
207
230
        }
208
231
 
209
232
#ifdef  USE_NIS
210
 
        while (fgetsx (buf, (int) sizeof buf, fp) != (char *) 0)
 
233
        while (fgetsx (buf, (int) sizeof buf, fp) == buf)
211
234
#else
212
 
        if (fgetsx (buf, (int) sizeof buf, fp) != (char *) 0)
 
235
        if (fgetsx (buf, (int) sizeof buf, fp) == buf)
213
236
#endif
214
237
        {
215
 
                cp = strchr (buf, '\n');
 
238
                while (   ((cp = strrchr (buf, '\n')) == NULL)
 
239
                       && (feof (fp) == 0)) {
 
240
                        size_t len;
 
241
 
 
242
                        cp = (char *) realloc (buf, buflen*2);
 
243
                        if (NULL == cp) {
 
244
                                return NULL;
 
245
                        }
 
246
                        buf = cp;
 
247
                        buflen *= 2;
 
248
 
 
249
                        len = strlen (buf);
 
250
                        if (fgetsx (&buf[len],
 
251
                                    (int) (buflen - len),
 
252
                                    fp) != &buf[len]) {
 
253
                                return NULL;
 
254
                        }
 
255
                }
 
256
                cp = strrchr (buf, '\n');
216
257
                if (NULL != cp) {
217
258
                        *cp = '\0';
218
259
                }
223
264
#endif
224
265
                return (sgetsgent (buf));
225
266
        }
226
 
        return 0;
 
267
        return NULL;
227
268
}
228
269
 
229
270
/*
235
276
#ifdef  USE_NIS
236
277
        bool nis_1_group = false;
237
278
        struct sgrp *val;
238
 
        char buf[BUFSIZ];
239
279
#endif
240
280
        if (NULL == shadow) {
241
281
                setsgent ();
334
374
        struct sgrp *sgrp;
335
375
 
336
376
#ifdef  USE_NIS
337
 
        char buf[BUFSIZ];
338
377
        static char save_name[16];
339
378
        int nis_disabled = 0;
340
379
#endif