mirror of
https://github.com/sudo-project/sudo.git
synced 2025-08-31 22:35:10 +00:00
kill perror("malloc") since we already have a good error messages
pw_ent -> pw for brevity
This commit is contained in:
13
check.c
13
check.c
@@ -645,8 +645,8 @@ static void check_passwd()
|
|||||||
*
|
*
|
||||||
* Validate a user via kerberos.
|
* Validate a user via kerberos.
|
||||||
*/
|
*/
|
||||||
static int sudo_krb_validate_user(pw_ent, pass)
|
static int sudo_krb_validate_user(pw, pass)
|
||||||
struct passwd *pw_ent;
|
struct passwd *pw;
|
||||||
char *pass;
|
char *pass;
|
||||||
{
|
{
|
||||||
char realm[REALM_SZ];
|
char realm[REALM_SZ];
|
||||||
@@ -662,7 +662,7 @@ static int sudo_krb_validate_user(pw_ent, pass)
|
|||||||
* wipe out other kerberos tickets.
|
* wipe out other kerberos tickets.
|
||||||
*/
|
*/
|
||||||
(void) sprintf(tkfile, "%s/tkt%ld", _PATH_SUDO_TIMEDIR,
|
(void) sprintf(tkfile, "%s/tkt%ld", _PATH_SUDO_TIMEDIR,
|
||||||
(long) pw_ent->pw_uid);
|
(long) pw->pw_uid);
|
||||||
(void) krb_set_tkt_string(tkfile);
|
(void) krb_set_tkt_string(tkfile);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -670,7 +670,7 @@ static int sudo_krb_validate_user(pw_ent, pass)
|
|||||||
* the ruid and euid to be the same here so we setuid to root.
|
* the ruid and euid to be the same here so we setuid to root.
|
||||||
*/
|
*/
|
||||||
set_perms(PERM_ROOT, 0);
|
set_perms(PERM_ROOT, 0);
|
||||||
k_errno = krb_get_pw_in_tkt(pw_ent->pw_name, "", realm, "krbtgt", realm,
|
k_errno = krb_get_pw_in_tkt(pw->pw_name, "", realm, "krbtgt", realm,
|
||||||
DEFAULT_TKT_LIFE, pass);
|
DEFAULT_TKT_LIFE, pass);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -788,7 +788,6 @@ static char *sudo_skeyprompt(user_skey, p)
|
|||||||
/* allocate space for new prompt */
|
/* allocate space for new prompt */
|
||||||
np_size = op_len + strlen(challenge) + 7;
|
np_size = op_len + strlen(challenge) + 7;
|
||||||
if (!(new_prompt = (char *) malloc(np_size))) {
|
if (!(new_prompt = (char *) malloc(np_size))) {
|
||||||
perror("malloc");
|
|
||||||
(void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
|
(void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@@ -797,7 +796,6 @@ static char *sudo_skeyprompt(user_skey, p)
|
|||||||
if (np_size < op_len + strlen(challenge) + 7) {
|
if (np_size < op_len + strlen(challenge) + 7) {
|
||||||
np_size = op_len + strlen(challenge) + 7;
|
np_size = op_len + strlen(challenge) + 7;
|
||||||
if (!(new_prompt = (char *) realloc(new_prompt, np_size))) {
|
if (!(new_prompt = (char *) realloc(new_prompt, np_size))) {
|
||||||
perror("malloc");
|
|
||||||
(void) fprintf(stderr, "%s: cannot allocate memory!\n",
|
(void) fprintf(stderr, "%s: cannot allocate memory!\n",
|
||||||
Argv[0]);
|
Argv[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
@@ -863,7 +861,6 @@ static char *sudo_opieprompt(user_opie, p)
|
|||||||
/* allocate space for new prompt */
|
/* allocate space for new prompt */
|
||||||
np_size = op_len + strlen(challenge) + 7;
|
np_size = op_len + strlen(challenge) + 7;
|
||||||
if (!(new_prompt = (char *) malloc(np_size))) {
|
if (!(new_prompt = (char *) malloc(np_size))) {
|
||||||
perror("malloc");
|
|
||||||
(void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
|
(void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@@ -872,7 +869,6 @@ static char *sudo_opieprompt(user_opie, p)
|
|||||||
if (np_size < op_len + strlen(challenge) + 7) {
|
if (np_size < op_len + strlen(challenge) + 7) {
|
||||||
np_size = op_len + strlen(challenge) + 7;
|
np_size = op_len + strlen(challenge) + 7;
|
||||||
if (!(new_prompt = (char *) realloc(new_prompt, np_size))) {
|
if (!(new_prompt = (char *) realloc(new_prompt, np_size))) {
|
||||||
perror("malloc");
|
|
||||||
(void) fprintf(stderr, "%s: cannot allocate memory!\n",
|
(void) fprintf(stderr, "%s: cannot allocate memory!\n",
|
||||||
Argv[0]);
|
Argv[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
@@ -977,7 +973,6 @@ static char *expand_prompt(old_prompt, user, host)
|
|||||||
|
|
||||||
if (subst) {
|
if (subst) {
|
||||||
if ((new_prompt = (char *) malloc(len + 1)) == NULL) {
|
if ((new_prompt = (char *) malloc(len + 1)) == NULL) {
|
||||||
perror("malloc");
|
|
||||||
(void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
|
(void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
87
getspwuid.c
87
getspwuid.c
@@ -107,13 +107,13 @@ static char *sudo_getepw __P((struct passwd *));
|
|||||||
* SHELL evariable or the passwd(5) entry (in that order).
|
* SHELL evariable or the passwd(5) entry (in that order).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static char *sudo_getshell(pw_ent)
|
static char *sudo_getshell(pw)
|
||||||
struct passwd *pw_ent;
|
struct passwd *pw;
|
||||||
{
|
{
|
||||||
char *pw_shell;
|
char *pw_shell;
|
||||||
|
|
||||||
if ((pw_shell = getenv("SHELL")) == NULL)
|
if ((pw_shell = getenv("SHELL")) == NULL)
|
||||||
pw_shell = pw_ent -> pw_shell;
|
pw_shell = pw -> pw_shell;
|
||||||
|
|
||||||
#ifdef _PATH_BSHELL
|
#ifdef _PATH_BSHELL
|
||||||
/* empty string "" means bourne shell */
|
/* empty string "" means bourne shell */
|
||||||
@@ -130,72 +130,72 @@ static char *sudo_getshell(pw_ent)
|
|||||||
* sudo_getepw()
|
* sudo_getepw()
|
||||||
*
|
*
|
||||||
* This function returns the encrypted password for the user described
|
* This function returns the encrypted password for the user described
|
||||||
* by pw_ent. If there is a shadow password it is returned, else the
|
* by pw. If there is a shadow password it is returned, else the
|
||||||
* normal UN*X password is returned instead.
|
* normal UN*X password is returned instead.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static char *sudo_getepw(pw_ent)
|
static char *sudo_getepw(pw)
|
||||||
struct passwd *pw_ent;
|
struct passwd *pw;
|
||||||
{
|
{
|
||||||
|
|
||||||
/* if there is a function to check for shadow enabled, use it... */
|
/* if there is a function to check for shadow enabled, use it... */
|
||||||
#ifdef HAVE_ISCOMSEC
|
#ifdef HAVE_ISCOMSEC
|
||||||
if (!iscomsec())
|
if (!iscomsec())
|
||||||
return(pw_ent->pw_passwd);
|
return(pw->pw_passwd);
|
||||||
#endif /* HAVE_ISCOMSEC */
|
#endif /* HAVE_ISCOMSEC */
|
||||||
#ifdef HAVE_ISSECURE
|
#ifdef HAVE_ISSECURE
|
||||||
if (!issecure())
|
if (!issecure())
|
||||||
return(pw_ent->pw_passwd);
|
return(pw->pw_passwd);
|
||||||
#endif /* HAVE_ISSECURE */
|
#endif /* HAVE_ISSECURE */
|
||||||
|
|
||||||
#ifdef HAVE_GETPRPWNAM
|
#ifdef HAVE_GETPRPWNAM
|
||||||
{
|
{
|
||||||
struct pr_passwd *spw_ent;
|
struct pr_passwd *spw;
|
||||||
|
|
||||||
spw_ent = getprpwnam(pw_ent->pw_name);
|
spw = getprpwnam(spw->pw_name);
|
||||||
if (spw_ent != NULL && spw_ent->ufld.fd_encrypt != NULL) {
|
if (spw != NULL && spw->ufld.fd_encrypt != NULL) {
|
||||||
# ifdef __alpha
|
# ifdef __alpha
|
||||||
crypt_type = spw_ent -> ufld.fd_oldcrypt;
|
crypt_type = spw -> ufld.fd_oldcrypt;
|
||||||
# endif /* __alpha */
|
# endif /* __alpha */
|
||||||
return(spw_ent -> ufld.fd_encrypt);
|
return(spw -> ufld.fd_encrypt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* HAVE_GETPRPWNAM */
|
#endif /* HAVE_GETPRPWNAM */
|
||||||
#ifdef HAVE_GETSPNAM
|
#ifdef HAVE_GETSPNAM
|
||||||
{
|
{
|
||||||
struct spwd *spw_ent;
|
struct spwd *spw;
|
||||||
|
|
||||||
if ((spw_ent = getspnam(pw_ent -> pw_name)) && spw_ent -> sp_pwdp)
|
if ((spw = getspnam(pw -> pw_name)) && spw -> sp_pwdp)
|
||||||
return(spw_ent -> sp_pwdp);
|
return(spw -> sp_pwdp);
|
||||||
}
|
}
|
||||||
#endif /* HAVE_GETSPNAM */
|
#endif /* HAVE_GETSPNAM */
|
||||||
#ifdef HAVE_GETSPWUID
|
#ifdef HAVE_GETSPWUID
|
||||||
{
|
{
|
||||||
struct s_passwd *spw_ent;
|
struct s_passwd *spw;
|
||||||
|
|
||||||
if ((spw_ent = getspwuid(pw_ent -> pw_uid)) && spw_ent -> pw_passwd)
|
if ((spw = getspwuid(pw -> pw_uid)) && spw -> pw_passwd)
|
||||||
return(spw_ent -> pw_passwd);
|
return(spw -> pw_passwd);
|
||||||
}
|
}
|
||||||
#endif /* HAVE_GETSPWUID */
|
#endif /* HAVE_GETSPWUID */
|
||||||
#ifdef HAVE_GETPWANAM
|
#ifdef HAVE_GETPWANAM
|
||||||
{
|
{
|
||||||
struct passwd_adjunct *spw_ent;
|
struct passwd_adjunct *spw;
|
||||||
|
|
||||||
if ((spw_ent = getpwanam(pw_ent -> pw_name)) && spw_ent -> pwa_passwd)
|
if ((spw = getpwanam(pw -> pw_name)) && spw -> pwa_passwd)
|
||||||
return(spw_ent -> pwa_passwd);
|
return(spw -> pwa_passwd);
|
||||||
}
|
}
|
||||||
#endif /* HAVE_GETPWANAM */
|
#endif /* HAVE_GETPWANAM */
|
||||||
#ifdef HAVE_GETAUTHUID
|
#ifdef HAVE_GETAUTHUID
|
||||||
{
|
{
|
||||||
AUTHORIZATION *spw_ent;
|
AUTHORIZATION *spw;
|
||||||
|
|
||||||
if ((spw_ent = getauthuid(pw_ent -> pw_uid)) && spw_ent -> a_password)
|
if ((spw = getauthuid(pw -> pw_uid)) && spw -> a_password)
|
||||||
return(spw_ent -> a_password);
|
return(spw -> a_password);
|
||||||
}
|
}
|
||||||
#endif /* HAVE_GETAUTHUID */
|
#endif /* HAVE_GETAUTHUID */
|
||||||
|
|
||||||
/* Fall back on normal passwd */
|
/* Fall back on normal passwd */
|
||||||
return(pw_ent->pw_passwd);
|
return(pw->pw_passwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -211,15 +211,14 @@ static char *sudo_getepw(pw_ent)
|
|||||||
struct passwd *sudo_getpwuid(uid)
|
struct passwd *sudo_getpwuid(uid)
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
{
|
{
|
||||||
struct passwd *pw_ent, *local_pw_ent;
|
struct passwd *pw, *local_pw;
|
||||||
|
|
||||||
if ((pw_ent = getpwuid(uid)) == NULL)
|
if ((pw = getpwuid(uid)) == NULL)
|
||||||
return(NULL);
|
return(NULL);
|
||||||
|
|
||||||
/* allocate space for a local copy of pw_ent */
|
/* allocate space for a local copy of pw */
|
||||||
local_pw_ent = (struct passwd *) malloc(sizeof(struct passwd));
|
local_pw = (struct passwd *) malloc(sizeof(struct passwd));
|
||||||
if (local_pw_ent == NULL) {
|
if (local_pw == NULL) {
|
||||||
perror("malloc");
|
|
||||||
(void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
|
(void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@@ -227,37 +226,33 @@ struct passwd *sudo_getpwuid(uid)
|
|||||||
/*
|
/*
|
||||||
* Copy the struct passwd and the interesting strings...
|
* Copy the struct passwd and the interesting strings...
|
||||||
*/
|
*/
|
||||||
(void) memcpy(local_pw_ent, pw_ent, sizeof(struct passwd));
|
(void) memcpy(local_pw, pw, sizeof(struct passwd));
|
||||||
|
|
||||||
local_pw_ent->pw_name = (char *) strdup(pw_ent->pw_name);
|
local_pw->pw_name = (char *) strdup(pw->pw_name);
|
||||||
if (local_pw_ent->pw_name == NULL) {
|
if (local_pw->pw_name == NULL) {
|
||||||
perror("malloc");
|
|
||||||
(void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
|
(void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
local_pw_ent->pw_dir = (char *) strdup(pw_ent->pw_dir);
|
local_pw->pw_dir = (char *) strdup(pw->pw_dir);
|
||||||
if (local_pw_ent->pw_dir == NULL) {
|
if (local_pw->pw_dir == NULL) {
|
||||||
perror("malloc");
|
|
||||||
(void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
|
(void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* pw_shell is a special case since we overide with $SHELL */
|
/* pw_shell is a special case since we overide with $SHELL */
|
||||||
local_pw_ent->pw_shell = (char *) strdup(sudo_getshell(pw_ent));
|
local_pw->pw_shell = (char *) strdup(sudo_getshell(pw));
|
||||||
if (local_pw_ent->pw_shell == NULL) {
|
if (local_pw->pw_shell == NULL) {
|
||||||
perror("malloc");
|
|
||||||
(void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
|
(void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* pw_passwd gets a shadow password if applicable */
|
/* pw_passwd gets a shadow password if applicable */
|
||||||
local_pw_ent->pw_passwd = (char *) strdup(sudo_getepw(pw_ent));
|
local_pw->pw_passwd = (char *) strdup(sudo_getepw(pw));
|
||||||
if (local_pw_ent->pw_passwd == NULL) {
|
if (local_pw->pw_passwd == NULL) {
|
||||||
perror("malloc");
|
|
||||||
(void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
|
(void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return(local_pw_ent);
|
return(local_pw);
|
||||||
}
|
}
|
||||||
|
@@ -125,7 +125,7 @@ void load_interfaces()
|
|||||||
for (;;) {
|
for (;;) {
|
||||||
ifconf_buf = ifconf_buf ? realloc(ifconf_buf, len) : malloc(len);
|
ifconf_buf = ifconf_buf ? realloc(ifconf_buf, len) : malloc(len);
|
||||||
if (ifconf_buf == NULL) {
|
if (ifconf_buf == NULL) {
|
||||||
perror("malloc");
|
(void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
ifconf = (struct ifconf *) ifconf_buf;
|
ifconf = (struct ifconf *) ifconf_buf;
|
||||||
@@ -159,7 +159,6 @@ void load_interfaces()
|
|||||||
*/
|
*/
|
||||||
interfaces = (struct interface *) malloc(sizeof(struct interface) * n);
|
interfaces = (struct interface *) malloc(sizeof(struct interface) * n);
|
||||||
if (interfaces == NULL) {
|
if (interfaces == NULL) {
|
||||||
perror("malloc");
|
|
||||||
(void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
|
(void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user