2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* Copyright 1990 - 1994, Julianne Frances Haugh
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of Julianne F. Haugh nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY JULIE HAUGH AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL JULIE HAUGH OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
#ifdef SHADOWGRP /*{ */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
#include "rcsid.h"
|
2007-10-07 17:16:07 +05:30
|
|
|
RCSID ("$Id: gspack.c,v 1.4 2005/03/31 05:14:49 kloczek Exp $")
|
2007-10-07 17:14:02 +05:30
|
|
|
#include <stdio.h>
|
|
|
|
#include "defines.h"
|
|
|
|
/*
|
|
|
|
* sgr_pack - convert a shadow group structure to a packed
|
|
|
|
* shadow group record
|
|
|
|
*
|
|
|
|
* sgr_pack takes the shadow group structure and packs
|
|
|
|
* the components in a record. this record will be
|
|
|
|
* unpacked later by sgr_unpack.
|
|
|
|
*/
|
2007-10-07 17:16:07 +05:30
|
|
|
int sgr_pack (const struct sgrp *sgrp, char *buf)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
char *cp;
|
|
|
|
int i;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* The name and password are both easy - append each string
|
|
|
|
* to the buffer. These are always the first two strings
|
|
|
|
* in a record.
|
|
|
|
*/
|
|
|
|
|
|
|
|
cp = buf;
|
|
|
|
strcpy (cp, sgrp->sg_name);
|
|
|
|
cp += strlen (cp) + 1;
|
|
|
|
|
|
|
|
strcpy (cp, sgrp->sg_passwd);
|
|
|
|
cp += strlen (cp) + 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The arrays of administrators and members are slightly
|
|
|
|
* harder. Each element is appended as a string, with a
|
|
|
|
* final '\0' appended to serve as a blank string. The
|
|
|
|
* number of elements is not known in advance, so the
|
|
|
|
* entire collection of administrators must be scanned to
|
|
|
|
* find the start of the members.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
for (i = 0; sgrp->sg_adm[i]; i++) {
|
2007-10-07 17:14:02 +05:30
|
|
|
strcpy (cp, sgrp->sg_adm[i]);
|
|
|
|
cp += strlen (cp) + 1;
|
|
|
|
}
|
|
|
|
*cp++ = '\0';
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
for (i = 0; sgrp->sg_mem[i]; i++) {
|
2007-10-07 17:14:02 +05:30
|
|
|
strcpy (cp, sgrp->sg_mem[i]);
|
|
|
|
cp += strlen (cp) + 1;
|
|
|
|
}
|
|
|
|
*cp++ = '\0';
|
|
|
|
|
|
|
|
return cp - buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sgr_unpack - convert a packed shadow group record to an
|
|
|
|
* unpacked record
|
|
|
|
*
|
|
|
|
* sgr_unpack converts a record which was packed by sgr_pack
|
|
|
|
* into the normal shadow group structure format.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
int sgr_unpack (char *buf, int len, struct sgrp *sgrp)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
char *org = buf;
|
|
|
|
int i;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* The name and password are both easy - they are the first
|
|
|
|
* two strings in the record.
|
|
|
|
*/
|
|
|
|
|
|
|
|
sgrp->sg_name = buf;
|
|
|
|
buf += strlen (buf) + 1;
|
|
|
|
if (buf - org > len)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
sgrp->sg_passwd = buf;
|
|
|
|
buf += strlen (buf) + 1;
|
|
|
|
if (buf - org > len)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The administrators and members are slightly more difficult.
|
|
|
|
* The arrays are lists of strings. Each list is terminated
|
|
|
|
* by a string of length zero. This string is detected by
|
|
|
|
* looking for an initial character of '\0'.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
for (i = 0; *buf && i < 1024; i++) {
|
2007-10-07 17:14:02 +05:30
|
|
|
sgrp->sg_adm[i] = buf;
|
|
|
|
buf += strlen (buf) + 1;
|
|
|
|
|
|
|
|
if (buf - org > len)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
sgrp->sg_adm[i] = (char *) 0;
|
2007-10-07 17:16:07 +05:30
|
|
|
if (!*buf)
|
2007-10-07 17:14:02 +05:30
|
|
|
buf++;
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
for (i = 0; *buf && i < 1024; i++) {
|
2007-10-07 17:14:02 +05:30
|
|
|
sgrp->sg_mem[i] = buf;
|
|
|
|
buf += strlen (buf) + 1;
|
|
|
|
|
|
|
|
if (buf - org > len)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
sgrp->sg_mem[i] = (char *) 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2007-10-07 17:16:07 +05:30
|
|
|
#endif /*} */
|