mirror of
https://github.com/sheumann/hush.git
synced 2025-01-14 12:30:40 +00:00
fix build without shadow support
This commit is contained in:
parent
9a44c4f91c
commit
7fa0fcafca
@ -89,19 +89,16 @@ int id_main(int argc, char **argv)
|
|||||||
|
|
||||||
#ifdef CONFIG_SELINUX
|
#ifdef CONFIG_SELINUX
|
||||||
if (is_selinux_enabled()) {
|
if (is_selinux_enabled()) {
|
||||||
security_context_t mysid;
|
security_context_t mysid;
|
||||||
char context[80];
|
const char *context;
|
||||||
int len = sizeof(context);
|
|
||||||
|
|
||||||
getcon(&mysid);
|
context = "unknown";
|
||||||
context[0] = '\0';
|
getcon(&mysid);
|
||||||
if (mysid) {
|
if (mysid) {
|
||||||
len = strlen(mysid)+1;
|
context = alloca(strlen(mysid) + 1);
|
||||||
safe_strncpy(context, mysid, len);
|
strcpy((char*)context, mysid);
|
||||||
freecon(mysid);
|
freecon(mysid);
|
||||||
} else {
|
}
|
||||||
safe_strncpy(context, "unknown", 8);
|
|
||||||
}
|
|
||||||
printf(" context=%s", context);
|
printf(" context=%s", context);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -51,9 +51,7 @@
|
|||||||
|
|
||||||
#include "pwd_.h"
|
#include "pwd_.h"
|
||||||
#include "grp_.h"
|
#include "grp_.h"
|
||||||
#if ENABLE_FEATURE_SHADOWPASSWDS
|
|
||||||
#include "shadow_.h"
|
#include "shadow_.h"
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Try to pull in PATH_MAX */
|
/* Try to pull in PATH_MAX */
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
@ -17,83 +17,74 @@
|
|||||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
02111-1307 USA. */
|
02111-1307 USA. */
|
||||||
|
|
||||||
/* Declaration of types and functions for shadow password suite. */
|
/* Declaration of types and functions for shadow password suite */
|
||||||
|
|
||||||
#if !defined CONFIG_USE_BB_SHADOW
|
#if !ENABLE_USE_BB_SHADOW
|
||||||
#include <shadow.h>
|
#include <shadow.h>
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#ifndef _SHADOW_H
|
#ifndef _SHADOW_H
|
||||||
#define _SHADOW_H 1
|
#define _SHADOW_H 1
|
||||||
|
|
||||||
#include <stdio.h>
|
/* Paths to the user database files */
|
||||||
|
|
||||||
/* Paths to the user database files. */
|
|
||||||
#ifndef _PATH_SHADOW
|
#ifndef _PATH_SHADOW
|
||||||
#define _PATH_SHADOW "/etc/shadow"
|
#define _PATH_SHADOW "/etc/shadow"
|
||||||
#endif
|
#endif
|
||||||
#define SHADOW _PATH_SHADOW
|
|
||||||
|
|
||||||
|
/* Structure of the password file */
|
||||||
/* Structure of the password file. */
|
struct spwd {
|
||||||
struct spwd
|
char *sp_namp; /* Login name */
|
||||||
{
|
char *sp_pwdp; /* Encrypted password */
|
||||||
char *sp_namp; /* Login name. */
|
long int sp_lstchg; /* Date of last change */
|
||||||
char *sp_pwdp; /* Encrypted password. */
|
long int sp_min; /* Minimum number of days between changes */
|
||||||
long int sp_lstchg; /* Date of last change. */
|
long int sp_max; /* Maximum number of days between changes */
|
||||||
long int sp_min; /* Minimum number of days between changes. */
|
long int sp_warn; /* Number of days to warn user to change the password */
|
||||||
long int sp_max; /* Maximum number of days between changes. */
|
long int sp_inact; /* Number of days the account may be inactive */
|
||||||
long int sp_warn; /* Number of days to warn user to change
|
long int sp_expire; /* Number of days since 1970-01-01 until account expires */
|
||||||
the password. */
|
unsigned long int sp_flag; /* Reserved */
|
||||||
long int sp_inact; /* Number of days the account may be
|
|
||||||
inactive. */
|
|
||||||
long int sp_expire; /* Number of days since 1970-01-01 until
|
|
||||||
account expires. */
|
|
||||||
unsigned long int sp_flag; /* Reserved. */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Open database for reading */
|
||||||
|
extern void setspent(void);
|
||||||
|
|
||||||
/* Open database for reading. */
|
/* Close database */
|
||||||
extern void setspent (void);
|
extern void endspent(void);
|
||||||
|
|
||||||
/* Close database. */
|
/* Get next entry from database, perhaps after opening the file */
|
||||||
extern void endspent (void);
|
extern struct spwd *getspent(void);
|
||||||
|
|
||||||
/* Get next entry from database, perhaps after opening the file. */
|
/* Get shadow entry matching NAME */
|
||||||
extern struct spwd *getspent (void);
|
extern struct spwd *getspnam(__const char *__name);
|
||||||
|
|
||||||
/* Get shadow entry matching NAME. */
|
/* Read shadow entry from STRING */
|
||||||
extern struct spwd *getspnam (__const char *__name);
|
extern struct spwd *sgetspent(__const char *__string);
|
||||||
|
|
||||||
/* Read shadow entry from STRING. */
|
/* Read next shadow entry from STREAM */
|
||||||
extern struct spwd *sgetspent (__const char *__string);
|
extern struct spwd *fgetspent(FILE *__stream);
|
||||||
|
|
||||||
/* Read next shadow entry from STREAM. */
|
/* Write line containing shadow password entry to stream */
|
||||||
extern struct spwd *fgetspent (FILE *__stream);
|
extern int putspent(__const struct spwd *__p, FILE *__stream);
|
||||||
|
|
||||||
/* Write line containing shadow password entry to stream. */
|
/* Reentrant versions of some of the functions above */
|
||||||
extern int putspent (__const struct spwd *__p, FILE *__stream);
|
extern int getspent_r(struct spwd *__result_buf, char *__buffer,
|
||||||
|
|
||||||
/* Reentrant versions of some of the functions above. */
|
|
||||||
extern int getspent_r (struct spwd *__result_buf, char *__buffer,
|
|
||||||
size_t __buflen, struct spwd **__result);
|
size_t __buflen, struct spwd **__result);
|
||||||
|
|
||||||
extern int getspnam_r (__const char *__name, struct spwd *__result_buf,
|
extern int getspnam_r(__const char *__name, struct spwd *__result_buf,
|
||||||
char *__buffer, size_t __buflen,
|
char *__buffer, size_t __buflen,
|
||||||
struct spwd **__result);
|
struct spwd **__result);
|
||||||
|
|
||||||
extern int sgetspent_r (__const char *__string, struct spwd *__result_buf,
|
extern int sgetspent_r(__const char *__string, struct spwd *__result_buf,
|
||||||
char *__buffer, size_t __buflen,
|
char *__buffer, size_t __buflen,
|
||||||
struct spwd **__result);
|
struct spwd **__result);
|
||||||
|
|
||||||
extern int fgetspent_r (FILE *__stream, struct spwd *__result_buf,
|
extern int fgetspent_r(FILE *__stream, struct spwd *__result_buf,
|
||||||
char *__buffer, size_t __buflen,
|
char *__buffer, size_t __buflen,
|
||||||
struct spwd **__result);
|
struct spwd **__result);
|
||||||
/* Protect password file against multi writers. */
|
/* Protect password file against multi writers */
|
||||||
extern int lckpwdf (void);
|
extern int lckpwdf(void);
|
||||||
|
|
||||||
/* Unlock password file. */
|
/* Unlock password file */
|
||||||
extern int ulckpwdf (void);
|
extern int ulckpwdf(void);
|
||||||
|
|
||||||
#endif /* shadow.h */
|
#endif /* shadow.h */
|
||||||
#endif
|
#endif
|
||||||
|
@ -20,14 +20,7 @@
|
|||||||
|
|
||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
#include <features.h>
|
#include <features.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <ctype.h>
|
|
||||||
|
|
||||||
#ifndef _PATH_SHADOW
|
#ifndef _PATH_SHADOW
|
||||||
#define _PATH_SHADOW "/etc/shadow"
|
#define _PATH_SHADOW "/etc/shadow"
|
||||||
@ -50,13 +43,15 @@
|
|||||||
/**********************************************************************/
|
/**********************************************************************/
|
||||||
/* Prototypes for internal functions. */
|
/* Prototypes for internal functions. */
|
||||||
|
|
||||||
extern int __parsepwent(void *pw, char *line);
|
static int __pgsreader(int (*parserfunc)(void *d, char *line), void *data,
|
||||||
extern int __parsegrent(void *gr, char *line);
|
|
||||||
extern int __parsespent(void *sp, char *line);
|
|
||||||
|
|
||||||
extern int __pgsreader(int (*__parserfunc)(void *d, char *line), void *data,
|
|
||||||
char *__restrict line_buff, size_t buflen, FILE *f);
|
char *__restrict line_buff, size_t buflen, FILE *f);
|
||||||
|
|
||||||
|
static int __parsepwent(void *pw, char *line);
|
||||||
|
static int __parsegrent(void *gr, char *line);
|
||||||
|
#if ENABLE_USE_BB_SHADOW
|
||||||
|
static int __parsespent(void *sp, char *line);
|
||||||
|
#endif
|
||||||
|
|
||||||
/**********************************************************************/
|
/**********************************************************************/
|
||||||
/* For the various fget??ent_r funcs, return
|
/* For the various fget??ent_r funcs, return
|
||||||
*
|
*
|
||||||
@ -81,7 +76,8 @@ int fgetpwent_r(FILE *__restrict stream, struct passwd *__restrict resultbuf,
|
|||||||
|
|
||||||
*result = NULL;
|
*result = NULL;
|
||||||
|
|
||||||
if (!(rv = __pgsreader(__parsepwent, resultbuf, buffer, buflen, stream))) {
|
rv = __pgsreader(__parsepwent, resultbuf, buffer, buflen, stream);
|
||||||
|
if (!rv) {
|
||||||
*result = resultbuf;
|
*result = resultbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,13 +92,15 @@ int fgetgrent_r(FILE *__restrict stream, struct group *__restrict resultbuf,
|
|||||||
|
|
||||||
*result = NULL;
|
*result = NULL;
|
||||||
|
|
||||||
if (!(rv = __pgsreader(__parsegrent, resultbuf, buffer, buflen, stream))) {
|
rv = __pgsreader(__parsegrent, resultbuf, buffer, buflen, stream);
|
||||||
|
if (!rv) {
|
||||||
*result = resultbuf;
|
*result = resultbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ENABLE_USE_BB_SHADOW
|
||||||
int fgetspent_r(FILE *__restrict stream, struct spwd *__restrict resultbuf,
|
int fgetspent_r(FILE *__restrict stream, struct spwd *__restrict resultbuf,
|
||||||
char *__restrict buffer, size_t buflen,
|
char *__restrict buffer, size_t buflen,
|
||||||
struct spwd **__restrict result)
|
struct spwd **__restrict result)
|
||||||
@ -111,12 +109,14 @@ int fgetspent_r(FILE *__restrict stream, struct spwd *__restrict resultbuf,
|
|||||||
|
|
||||||
*result = NULL;
|
*result = NULL;
|
||||||
|
|
||||||
if (!(rv = __pgsreader(__parsespent, resultbuf, buffer, buflen, stream))) {
|
rv = __pgsreader(__parsespent, resultbuf, buffer, buflen, stream);
|
||||||
|
if (!rv) {
|
||||||
*result = resultbuf;
|
*result = resultbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/**********************************************************************/
|
/**********************************************************************/
|
||||||
/* For the various fget??ent funcs, return NULL on failure and a
|
/* For the various fget??ent funcs, return NULL on failure and a
|
||||||
@ -144,9 +144,7 @@ struct group *fgetgrent(FILE *stream)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern int fgetspent_r(FILE *__restrict stream, struct spwd *__restrict resultbuf,
|
#if ENABLE_USE_BB_SHADOW
|
||||||
char *__restrict buffer, size_t buflen,
|
|
||||||
struct spwd **__restrict result);
|
|
||||||
struct spwd *fgetspent(FILE *stream)
|
struct spwd *fgetspent(FILE *stream)
|
||||||
{
|
{
|
||||||
static char buffer[PWD_BUFFER_SIZE];
|
static char buffer[PWD_BUFFER_SIZE];
|
||||||
@ -177,13 +175,15 @@ int sgetspent_r(const char *string, struct spwd *result_buf,
|
|||||||
strcpy(buffer, string);
|
strcpy(buffer, string);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(rv = __parsespent(result_buf, buffer))) {
|
rv = __parsespent(result_buf, buffer);
|
||||||
|
if (!rv) {
|
||||||
*result = result_buf;
|
*result = result_buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
DONE:
|
DONE:
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/**********************************************************************/
|
/**********************************************************************/
|
||||||
|
|
||||||
@ -191,43 +191,45 @@ int sgetspent_r(const char *string, struct spwd *result_buf,
|
|||||||
#error GETXXKEY_R_FUNC is already defined!
|
#error GETXXKEY_R_FUNC is already defined!
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define GETXXKEY_R_FUNC getpwnam_R
|
#define GETXXKEY_R_FUNC getpwnam_R
|
||||||
#define GETXXKEY_R_PARSER __parsepwent
|
#define GETXXKEY_R_PARSER __parsepwent
|
||||||
#define GETXXKEY_R_ENTTYPE struct passwd
|
#define GETXXKEY_R_ENTTYPE struct passwd
|
||||||
#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->pw_name, key))
|
#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->pw_name, key))
|
||||||
#define DO_GETXXKEY_R_KEYTYPE const char *__restrict
|
#define DO_GETXXKEY_R_KEYTYPE const char *__restrict
|
||||||
#define DO_GETXXKEY_R_PATHNAME _PATH_PASSWD
|
#define DO_GETXXKEY_R_PATHNAME _PATH_PASSWD
|
||||||
#include "pwd_grp_internal.c"
|
#include "pwd_grp_internal.c"
|
||||||
|
|
||||||
#define GETXXKEY_R_FUNC getgrnam_R
|
#define GETXXKEY_R_FUNC getgrnam_R
|
||||||
#define GETXXKEY_R_PARSER __parsegrent
|
#define GETXXKEY_R_PARSER __parsegrent
|
||||||
#define GETXXKEY_R_ENTTYPE struct group
|
#define GETXXKEY_R_ENTTYPE struct group
|
||||||
#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->gr_name, key))
|
#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->gr_name, key))
|
||||||
#define DO_GETXXKEY_R_KEYTYPE const char *__restrict
|
#define DO_GETXXKEY_R_KEYTYPE const char *__restrict
|
||||||
#define DO_GETXXKEY_R_PATHNAME _PATH_GROUP
|
#define DO_GETXXKEY_R_PATHNAME _PATH_GROUP
|
||||||
#include "pwd_grp_internal.c"
|
#include "pwd_grp_internal.c"
|
||||||
|
|
||||||
#define GETXXKEY_R_FUNC getspnam_R
|
#if ENABLE_USE_BB_SHADOW
|
||||||
#define GETXXKEY_R_PARSER __parsespent
|
#define GETXXKEY_R_FUNC getspnam_R
|
||||||
#define GETXXKEY_R_ENTTYPE struct spwd
|
#define GETXXKEY_R_PARSER __parsespent
|
||||||
#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->sp_namp, key))
|
#define GETXXKEY_R_ENTTYPE struct spwd
|
||||||
#define DO_GETXXKEY_R_KEYTYPE const char *__restrict
|
#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->sp_namp, key))
|
||||||
|
#define DO_GETXXKEY_R_KEYTYPE const char *__restrict
|
||||||
#define DO_GETXXKEY_R_PATHNAME _PATH_SHADOW
|
#define DO_GETXXKEY_R_PATHNAME _PATH_SHADOW
|
||||||
#include "pwd_grp_internal.c"
|
#include "pwd_grp_internal.c"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define GETXXKEY_R_FUNC getpwuid_R
|
#define GETXXKEY_R_FUNC getpwuid_R
|
||||||
#define GETXXKEY_R_PARSER __parsepwent
|
#define GETXXKEY_R_PARSER __parsepwent
|
||||||
#define GETXXKEY_R_ENTTYPE struct passwd
|
#define GETXXKEY_R_ENTTYPE struct passwd
|
||||||
#define GETXXKEY_R_TEST(ENT) ((ENT)->pw_uid == key)
|
#define GETXXKEY_R_TEST(ENT) ((ENT)->pw_uid == key)
|
||||||
#define DO_GETXXKEY_R_KEYTYPE uid_t
|
#define DO_GETXXKEY_R_KEYTYPE uid_t
|
||||||
#define DO_GETXXKEY_R_PATHNAME _PATH_PASSWD
|
#define DO_GETXXKEY_R_PATHNAME _PATH_PASSWD
|
||||||
#include "pwd_grp_internal.c"
|
#include "pwd_grp_internal.c"
|
||||||
|
|
||||||
#define GETXXKEY_R_FUNC getgrgid_R
|
#define GETXXKEY_R_FUNC getgrgid_R
|
||||||
#define GETXXKEY_R_PARSER __parsegrent
|
#define GETXXKEY_R_PARSER __parsegrent
|
||||||
#define GETXXKEY_R_ENTTYPE struct group
|
#define GETXXKEY_R_ENTTYPE struct group
|
||||||
#define GETXXKEY_R_TEST(ENT) ((ENT)->gr_gid == key)
|
#define GETXXKEY_R_TEST(ENT) ((ENT)->gr_gid == key)
|
||||||
#define DO_GETXXKEY_R_KEYTYPE gid_t
|
#define DO_GETXXKEY_R_KEYTYPE gid_t
|
||||||
#define DO_GETXXKEY_R_PATHNAME _PATH_GROUP
|
#define DO_GETXXKEY_R_PATHNAME _PATH_GROUP
|
||||||
#include "pwd_grp_internal.c"
|
#include "pwd_grp_internal.c"
|
||||||
|
|
||||||
@ -253,10 +255,10 @@ struct group *getgrgid(gid_t gid)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0 //ENABLE_USE_BB_SHADOW
|
||||||
/* This function is non-standard and is currently not built. It seems
|
/* This function is non-standard and is currently not built. It seems
|
||||||
* to have been created as a reentrant version of the non-standard
|
* to have been created as a reentrant version of the non-standard
|
||||||
* functions getspuid. Why getspuid was added, I do not know. */
|
* functions getspuid. Why getspuid was added, I do not know. */
|
||||||
|
|
||||||
int getspuid_r(uid_t uid, struct spwd *__restrict resultbuf,
|
int getspuid_r(uid_t uid, struct spwd *__restrict resultbuf,
|
||||||
char *__restrict buffer, size_t buflen,
|
char *__restrict buffer, size_t buflen,
|
||||||
struct spwd **__restrict result)
|
struct spwd **__restrict result)
|
||||||
@ -267,7 +269,8 @@ int getspuid_r(uid_t uid, struct spwd *__restrict resultbuf,
|
|||||||
char pwd_buff[PWD_BUFFER_SIZE];
|
char pwd_buff[PWD_BUFFER_SIZE];
|
||||||
|
|
||||||
*result = NULL;
|
*result = NULL;
|
||||||
if (!(rv = getpwuid_r(uid, &password, pwd_buff, sizeof(pwd_buff), &pp))) {
|
rv = getpwuid_r(uid, &password, pwd_buff, sizeof(pwd_buff), &pp);
|
||||||
|
if (!rv) {
|
||||||
rv = getspnam_r(password.pw_name, resultbuf, buffer, buflen, result);
|
rv = getspnam_r(password.pw_name, resultbuf, buffer, buflen, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,7 +279,6 @@ int getspuid_r(uid_t uid, struct spwd *__restrict resultbuf,
|
|||||||
|
|
||||||
/* This function is non-standard and is currently not built.
|
/* This function is non-standard and is currently not built.
|
||||||
* Why it was added, I do not know. */
|
* Why it was added, I do not know. */
|
||||||
|
|
||||||
struct spwd *getspuid(uid_t uid)
|
struct spwd *getspuid(uid_t uid)
|
||||||
{
|
{
|
||||||
static char buffer[PWD_BUFFER_SIZE];
|
static char buffer[PWD_BUFFER_SIZE];
|
||||||
@ -286,6 +288,7 @@ struct spwd *getspuid(uid_t uid)
|
|||||||
getspuid_r(uid, &resultbuf, buffer, sizeof(buffer), &result);
|
getspuid_r(uid, &resultbuf, buffer, sizeof(buffer), &result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
struct passwd *getpwnam(const char *name)
|
struct passwd *getpwnam(const char *name)
|
||||||
{
|
{
|
||||||
@ -307,6 +310,7 @@ struct group *getgrnam(const char *name)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ENABLE_USE_BB_SHADOW
|
||||||
struct spwd *getspnam(const char *name)
|
struct spwd *getspnam(const char *name)
|
||||||
{
|
{
|
||||||
static char buffer[PWD_BUFFER_SIZE];
|
static char buffer[PWD_BUFFER_SIZE];
|
||||||
@ -316,6 +320,7 @@ struct spwd *getspnam(const char *name)
|
|||||||
getspnam_r(name, &resultbuf, buffer, sizeof(buffer), &result);
|
getspnam_r(name, &resultbuf, buffer, sizeof(buffer), &result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int getpw(uid_t uid, char *buf)
|
int getpw(uid_t uid, char *buf)
|
||||||
{
|
{
|
||||||
@ -382,14 +387,15 @@ int getpwent_r(struct passwd *__restrict resultbuf,
|
|||||||
*result = NULL; /* In case of error... */
|
*result = NULL; /* In case of error... */
|
||||||
|
|
||||||
if (!pwf) {
|
if (!pwf) {
|
||||||
if (!(pwf = fopen(_PATH_PASSWD, "r"))) {
|
pwf = fopen(_PATH_PASSWD, "r");
|
||||||
|
if (!pwf) {
|
||||||
rv = errno;
|
rv = errno;
|
||||||
goto ERR;
|
goto ERR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(rv = __pgsreader(__parsepwent, resultbuf,
|
rv = __pgsreader(__parsepwent, resultbuf, buffer, buflen, pwf);
|
||||||
buffer, buflen, pwf))) {
|
if (!rv) {
|
||||||
*result = resultbuf;
|
*result = resultbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -428,14 +434,15 @@ int getgrent_r(struct group *__restrict resultbuf,
|
|||||||
*result = NULL; /* In case of error... */
|
*result = NULL; /* In case of error... */
|
||||||
|
|
||||||
if (!grf) {
|
if (!grf) {
|
||||||
if (!(grf = fopen(_PATH_GROUP, "r"))) {
|
grf = fopen(_PATH_GROUP, "r");
|
||||||
|
if (!grf) {
|
||||||
rv = errno;
|
rv = errno;
|
||||||
goto ERR;
|
goto ERR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(rv = __pgsreader(__parsegrent, resultbuf,
|
rv = __pgsreader(__parsegrent, resultbuf, buffer, buflen, grf);
|
||||||
buffer, buflen, grf))) {
|
if (!rv) {
|
||||||
*result = resultbuf;
|
*result = resultbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -444,6 +451,7 @@ int getgrent_r(struct group *__restrict resultbuf,
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ENABLE_USE_BB_SHADOW
|
||||||
static FILE *spf /*= NULL*/;
|
static FILE *spf /*= NULL*/;
|
||||||
void setspent(void)
|
void setspent(void)
|
||||||
{
|
{
|
||||||
@ -473,14 +481,15 @@ int getspent_r(struct spwd *resultbuf, char *buffer,
|
|||||||
*result = NULL; /* In case of error... */
|
*result = NULL; /* In case of error... */
|
||||||
|
|
||||||
if (!spf) {
|
if (!spf) {
|
||||||
if (!(spf = fopen(_PATH_SHADOW, "r"))) {
|
spf = fopen(_PATH_SHADOW, "r");
|
||||||
|
if (!spf) {
|
||||||
rv = errno;
|
rv = errno;
|
||||||
goto ERR;
|
goto ERR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(rv = __pgsreader(__parsespent, resultbuf,
|
rv = __pgsreader(__parsespent, resultbuf, buffer, buflen, spf);
|
||||||
buffer, buflen, spf))) {
|
if (!rv) {
|
||||||
*result = resultbuf;
|
*result = resultbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -488,6 +497,7 @@ int getspent_r(struct spwd *resultbuf, char *buffer,
|
|||||||
UNLOCK;
|
UNLOCK;
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
struct passwd *getpwent(void)
|
struct passwd *getpwent(void)
|
||||||
{
|
{
|
||||||
@ -509,6 +519,7 @@ struct group *getgrent(void)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ENABLE_USE_BB_SHADOW
|
||||||
struct spwd *getspent(void)
|
struct spwd *getspent(void)
|
||||||
{
|
{
|
||||||
static char line_buff[PWD_BUFFER_SIZE];
|
static char line_buff[PWD_BUFFER_SIZE];
|
||||||
@ -528,6 +539,7 @@ struct spwd *sgetspent(const char *string)
|
|||||||
sgetspent_r(string, &spwd, line_buff, sizeof(line_buff), &result);
|
sgetspent_r(string, &spwd, line_buff, sizeof(line_buff), &result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int initgroups(const char *user, gid_t gid)
|
int initgroups(const char *user, gid_t gid)
|
||||||
{
|
{
|
||||||
@ -541,10 +553,10 @@ int initgroups(const char *user, gid_t gid)
|
|||||||
rv = -1;
|
rv = -1;
|
||||||
|
|
||||||
/* We alloc space for 8 gids at a time. */
|
/* We alloc space for 8 gids at a time. */
|
||||||
if (((group_list = (gid_t *) malloc(8*sizeof(gid_t *))) != NULL)
|
group_list = (gid_t *) malloc(8*sizeof(gid_t *));
|
||||||
&& ((grfile = fopen(_PATH_GROUP, "r")) != NULL)
|
if (group_list
|
||||||
) {
|
&& ((grfile = fopen(_PATH_GROUP, "r")) != NULL)
|
||||||
|
) {
|
||||||
*group_list = gid;
|
*group_list = gid;
|
||||||
num_groups = 1;
|
num_groups = 1;
|
||||||
|
|
||||||
@ -643,6 +655,7 @@ int putgrent(const struct group *__restrict p, FILE *__restrict f)
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ENABLE_USE_BB_SHADOW
|
||||||
static const unsigned char _sp_off[] = {
|
static const unsigned char _sp_off[] = {
|
||||||
offsetof(struct spwd, sp_lstchg), /* 2 - not a char ptr */
|
offsetof(struct spwd, sp_lstchg), /* 2 - not a char ptr */
|
||||||
offsetof(struct spwd, sp_min), /* 3 - not a char ptr */
|
offsetof(struct spwd, sp_min), /* 3 - not a char ptr */
|
||||||
@ -663,13 +676,14 @@ int putspent(const struct spwd *p, FILE *stream)
|
|||||||
/* Unlike putpwent and putgrent, glibc does not check the args. */
|
/* Unlike putpwent and putgrent, glibc does not check the args. */
|
||||||
if (fprintf(stream, "%s:%s:", p->sp_namp,
|
if (fprintf(stream, "%s:%s:", p->sp_namp,
|
||||||
(p->sp_pwdp ? p->sp_pwdp : "")) < 0
|
(p->sp_pwdp ? p->sp_pwdp : "")) < 0
|
||||||
) {
|
) {
|
||||||
goto DO_UNLOCK;
|
goto DO_UNLOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0 ; i < sizeof(_sp_off) ; i++) {
|
for (i=0 ; i < sizeof(_sp_off) ; i++) {
|
||||||
f = ld_format;
|
f = ld_format;
|
||||||
if ((x = *(const long int *)(((const char *) p) + _sp_off[i])) == -1) {
|
x = *(const long int *)(((const char *) p) + _sp_off[i]);
|
||||||
|
if (x == -1) {
|
||||||
f += 3;
|
f += 3;
|
||||||
}
|
}
|
||||||
if (fprintf(stream, f, x) < 0) {
|
if (fprintf(stream, f, x) < 0) {
|
||||||
@ -688,6 +702,7 @@ int putspent(const struct spwd *p, FILE *stream)
|
|||||||
DO_UNLOCK:
|
DO_UNLOCK:
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/**********************************************************************/
|
/**********************************************************************/
|
||||||
/* Internal uClibc functions. */
|
/* Internal uClibc functions. */
|
||||||
@ -703,7 +718,7 @@ static const unsigned char pw_off[] = {
|
|||||||
offsetof(struct passwd, pw_shell) /* 6 */
|
offsetof(struct passwd, pw_shell) /* 6 */
|
||||||
};
|
};
|
||||||
|
|
||||||
int __parsepwent(void *data, char *line)
|
static int __parsepwent(void *data, char *line)
|
||||||
{
|
{
|
||||||
char *endptr;
|
char *endptr;
|
||||||
char *p;
|
char *p;
|
||||||
@ -721,7 +736,8 @@ int __parsepwent(void *data, char *line)
|
|||||||
/* NOTE: glibc difference - glibc allows omission of
|
/* NOTE: glibc difference - glibc allows omission of
|
||||||
* ':' seperators after the gid field if all remaining
|
* ':' seperators after the gid field if all remaining
|
||||||
* entries are empty. We require all separators. */
|
* entries are empty. We require all separators. */
|
||||||
if (!(line = strchr(line, ':'))) {
|
line = strchr(line, ':');
|
||||||
|
if (!line) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -756,7 +772,7 @@ static const unsigned char gr_off[] = {
|
|||||||
offsetof(struct group, gr_gid) /* 2 - not a char ptr */
|
offsetof(struct group, gr_gid) /* 2 - not a char ptr */
|
||||||
};
|
};
|
||||||
|
|
||||||
int __parsegrent(void *data, char *line)
|
static int __parsegrent(void *data, char *line)
|
||||||
{
|
{
|
||||||
char *endptr;
|
char *endptr;
|
||||||
char *p;
|
char *p;
|
||||||
@ -771,7 +787,8 @@ int __parsegrent(void *data, char *line)
|
|||||||
|
|
||||||
if (i < 2) {
|
if (i < 2) {
|
||||||
*((char **) p) = line;
|
*((char **) p) = line;
|
||||||
if (!(line = strchr(line, ':'))) {
|
line = strchr(line, ':');
|
||||||
|
if (!line) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
*line++ = 0;
|
*line++ = 0;
|
||||||
@ -845,7 +862,7 @@ int __parsegrent(void *data, char *line)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**********************************************************************/
|
/**********************************************************************/
|
||||||
|
#if ENABLE_USE_BB_SHADOW
|
||||||
static const unsigned char sp_off[] = {
|
static const unsigned char sp_off[] = {
|
||||||
offsetof(struct spwd, sp_namp), /* 0 */
|
offsetof(struct spwd, sp_namp), /* 0 */
|
||||||
offsetof(struct spwd, sp_pwdp), /* 1 */
|
offsetof(struct spwd, sp_pwdp), /* 1 */
|
||||||
@ -858,7 +875,7 @@ static const unsigned char sp_off[] = {
|
|||||||
offsetof(struct spwd, sp_flag) /* 8 - not a char ptr */
|
offsetof(struct spwd, sp_flag) /* 8 - not a char ptr */
|
||||||
};
|
};
|
||||||
|
|
||||||
int __parsespent(void *data, char * line)
|
static int __parsespent(void *data, char * line)
|
||||||
{
|
{
|
||||||
char *endptr;
|
char *endptr;
|
||||||
char *p;
|
char *p;
|
||||||
@ -869,7 +886,8 @@ int __parsespent(void *data, char * line)
|
|||||||
p = ((char *) ((struct spwd *) data)) + sp_off[i];
|
p = ((char *) ((struct spwd *) data)) + sp_off[i];
|
||||||
if (i < 2) {
|
if (i < 2) {
|
||||||
*((char **) p) = line;
|
*((char **) p) = line;
|
||||||
if (!(line = strchr(line, ':'))) {
|
line = strchr(line, ':');
|
||||||
|
if (!line) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -900,6 +918,7 @@ int __parsespent(void *data, char * line)
|
|||||||
|
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/**********************************************************************/
|
/**********************************************************************/
|
||||||
|
|
||||||
@ -909,7 +928,7 @@ int __parsespent(void *data, char * line)
|
|||||||
* Returns 0 on success and ENOENT for end-of-file (glibc concession).
|
* Returns 0 on success and ENOENT for end-of-file (glibc concession).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int __pgsreader(int (*__parserfunc)(void *d, char *line), void *data,
|
static int __pgsreader(int (*parserfunc)(void *d, char *line), void *data,
|
||||||
char *__restrict line_buff, size_t buflen, FILE *f)
|
char *__restrict line_buff, size_t buflen, FILE *f)
|
||||||
{
|
{
|
||||||
int line_len;
|
int line_len;
|
||||||
@ -917,7 +936,7 @@ int __pgsreader(int (*__parserfunc)(void *d, char *line), void *data,
|
|||||||
int rv = ERANGE;
|
int rv = ERANGE;
|
||||||
|
|
||||||
if (buflen < PWD_BUFFER_SIZE) {
|
if (buflen < PWD_BUFFER_SIZE) {
|
||||||
errno=rv;
|
errno = rv;
|
||||||
} else {
|
} else {
|
||||||
skip = 0;
|
skip = 0;
|
||||||
do {
|
do {
|
||||||
@ -947,14 +966,14 @@ int __pgsreader(int (*__parserfunc)(void *d, char *line), void *data,
|
|||||||
/* Skip empty lines, comment lines, and lines with leading
|
/* Skip empty lines, comment lines, and lines with leading
|
||||||
* whitespace. */
|
* whitespace. */
|
||||||
if (*line_buff && (*line_buff != '#') && !isspace(*line_buff)) {
|
if (*line_buff && (*line_buff != '#') && !isspace(*line_buff)) {
|
||||||
if (__parserfunc == __parsegrent) { /* Do evil group hack. */
|
if (parserfunc == __parsegrent) { /* Do evil group hack. */
|
||||||
/* The group entry parsing function needs to know where
|
/* The group entry parsing function needs to know where
|
||||||
* the end of the buffer is so that it can construct the
|
* the end of the buffer is so that it can construct the
|
||||||
* group member ptr table. */
|
* group member ptr table. */
|
||||||
((struct group *) data)->gr_name = line_buff + buflen;
|
((struct group *) data)->gr_name = line_buff + buflen;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!__parserfunc(data, line_buff)) {
|
if (!parserfunc(data, line_buff)) {
|
||||||
rv = 0;
|
rv = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -965,5 +984,3 @@ int __pgsreader(int (*__parserfunc)(void *d, char *line), void *data,
|
|||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********************************************************************/
|
|
||||||
|
@ -41,7 +41,6 @@ int sulogin_main(int argc, char **argv)
|
|||||||
char *timeout_arg;
|
char *timeout_arg;
|
||||||
const char * const *p;
|
const char * const *p;
|
||||||
struct passwd *pwd;
|
struct passwd *pwd;
|
||||||
struct spwd *spwd;
|
|
||||||
const char *shell;
|
const char *shell;
|
||||||
|
|
||||||
logmode = LOGMODE_BOTH;
|
logmode = LOGMODE_BOTH;
|
||||||
@ -76,7 +75,7 @@ int sulogin_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ENABLE_FEATURE_SHADOWPASSWDS) {
|
if (ENABLE_FEATURE_SHADOWPASSWDS) {
|
||||||
spwd = getspnam(pwd->pw_name);
|
struct spwd *spwd = getspnam(pwd->pw_name);
|
||||||
if (!spwd) {
|
if (!spwd) {
|
||||||
goto auth_error;
|
goto auth_error;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user