- consolidated password helpers into bb_pwd.c

This commit is contained in:
Bernhard Reutner-Fischer 2005-09-20 21:08:10 +00:00
parent d5bd137a24
commit f56b8e4b00
6 changed files with 0 additions and 305 deletions

View File

@ -1,30 +0,0 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdlib.h>
extern unsigned long get_ug_id(const char *s, long (*my_getxxnam)(const char *))
{
unsigned long r;
char *p;
r = strtoul(s, &p, 10);
if (*p || (s == p)) {
r = my_getxxnam(s);
}
return r;
}

View File

@ -1,57 +0,0 @@
/* vi: set sw=4 ts=4: */
/*
* Utility routines.
*
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* Hacked by Tito Ragusa (c) 2004 <farmatito@tiscali.it> to make it more
* flexible :
*
* if bufsize is > 0 char *group cannot be set to NULL.
* On success groupname is written on static allocated buffer group
* (and a pointer to it is returned).
* On failure gid as string is written to static allocated buffer
* group and NULL is returned.
* if bufsize is = 0 char *group can be set to NULL.
* On success groupname is returned.
* On failure NULL is returned.
* if bufsize is < 0 char *group can be set to NULL.
* On success groupname is returned.
* On failure an error message is printed and the program exits.
*/
#include "libbb.h"
#include "grp_.h"
/* gets a groupname given a gid */
char * my_getgrgid(char *group, long gid, int bufsize)
{
struct group *mygroup = getgrgid(gid);
return my_getug(group, (mygroup) ? mygroup->gr_name : (char *)mygroup, gid, bufsize, 'g');
}
/* END CODE */
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/

View File

@ -1,49 +0,0 @@
/* vi: set sw=4 ts=4: */
/*
* Utility routines.
*
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include <string.h>
#include "libbb.h"
#include "pwd_.h"
#include "grp_.h"
/* returns a gid given a group name */
long my_getgrnam(const char *name)
{
struct group *mygroup;
mygroup = getgrnam(name);
if (mygroup==NULL)
bb_error_msg_and_die("unknown group name: %s", name);
return (mygroup->gr_gid);
}
/* END CODE */
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/

View File

@ -1,49 +0,0 @@
/* vi: set sw=4 ts=4: */
/*
* Utility routines.
*
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include <string.h>
#include "libbb.h"
#include "pwd_.h"
#include "grp_.h"
/* returns a uid given a username */
long my_getpwnam(const char *name)
{
struct passwd *myuser;
myuser = getpwnam(name);
if (myuser==NULL)
bb_error_msg_and_die("unknown user name: %s", name);
return myuser->pw_uid;
}
/* END CODE */
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/

View File

@ -1,56 +0,0 @@
/* vi: set sw=4 ts=4: */
/*
* Utility routines.
*
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* Hacked by Tito Ragusa (c) 2004 <farmatito@tiscali.it> to make it more
* flexible :
*
* if bufsize is > 0 char *name can not be set to NULL.
* On success username is written on the static allocated buffer name
* (and a pointer to it is returned).
* On failure uid as string is written to the static allocated buffer name
* and NULL is returned.
* if bufsize is = 0 char *name can be set to NULL.
* On success username is returned.
* On failure NULL is returned.
* if bufsize is < 0 char *name can be set to NULL
* On success username is returned.
* On failure an error message is printed and the program exits.
*/
#include "libbb.h"
#include "pwd_.h"
/* gets a username given a uid */
char * my_getpwuid(char *name, long uid, int bufsize)
{
struct passwd *myuser = getpwuid(uid);
return my_getug(name, (myuser) ? myuser->pw_name : (char *)myuser , uid, bufsize, 'u');
}
/* END CODE */
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/

View File

@ -1,64 +0,0 @@
/* vi: set sw=4 ts=4: */
/*
* Utility routines.
*
* Copyright (C) 2004 by Tito Ragusa <farmatito@tiscali.it>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
*
* if bufsize is > 0 char *buffer can not be set to NULL.
* If idname is not NULL it is written on the static allocated buffer
* (and a pointer to it is returned).
* if idname is NULL, id as string is written to the static allocated buffer
* and NULL is returned.
* if bufsize is = 0 char *buffer can be set to NULL.
* If idname exists a pointer to it is returned,
* else NULL is returned.
* if bufsize is < 0 char *buffer can be set to NULL.
* If idname exists a pointer to it is returned,
* else an error message is printed and the program exits.
*/
#include <stdio.h>
#include <assert.h>
#include "libbb.h"
/* internal function for my_getpwuid and my_getgrgid */
char * my_getug(char *buffer, char *idname, long id, int bufsize, char prefix)
{
if(bufsize > 0 ) {
assert(buffer!=NULL);
if(idname) {
return safe_strncpy(buffer, idname, bufsize);
}
snprintf(buffer, bufsize, "%ld", id);
} else if(bufsize < 0 && !idname) {
bb_error_msg_and_die("unknown %cid %ld", prefix, id);
}
return idname;
}
/* END CODE */
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/