SRCS = check.c getspwuid.c find_path.c logging.c parse.c sudo.c secureware.c \
goodpath.c sudo_setenv.c parse.yacc parse.lex visudo.c interfaces.c \
- check_sia.c
+ check_sia.c alloc.c
-PARSEOBJS = sudo.tab.o lex.yy.o
+PARSEOBJS = sudo.tab.o lex.yy.o alloc.o
SUDOBJS = check.o getspwuid.o find_path.o logging.o parse.o sudo.o \
secureware.o goodpath.o sudo_setenv.o interfaces.o \
ins_classic.h ins_csops.h ins_goons.h insults.h interfaces.c \
logging.c parse.c parse.lex parse.yacc pathnames.h.in \
putenv.c strdup.c sudo.c sudo.h sudo_setenv.c testsudoers.c \
- tgetpass.c utime.c visudo.c secureware.c check_sia.c
+ tgetpass.c utime.c visudo.c secureware.c check_sia.c alloc.c
all: $(PROGS)
return -1;
krb5_get_init_creds_opt_init(&opts);
- princ_name = malloc(strlen(pw->pw_name) + strlen(realm) + 2);
- if (!princ_name) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
+ princ_name = emalloc(strlen(pw->pw_name) + strlen(realm) + 2);
sprintf(princ_name, "%s@%s", pw->pw_name, realm);
if (retval = krb5_parse_name(sudo_context, princ_name, &princ))
int replies = 0;
struct pam_response *reply = NULL;
-/* XXX - replace with estrdup() */
-#define COPY_STRING(s) (s) ? strdup(s) : NULL
-
- reply = malloc(sizeof(struct pam_response) * num_msg);
- if (reply == NULL)
+ if ((reply = malloc(sizeof(struct pam_response) * num_msg)) == NULL)
return(PAM_CONV_ERR);
for (replies = 0; replies < num_msg; replies++) {
switch (msg[replies]->msg_style) {
case PAM_PROMPT_ECHO_ON:
reply[replies].resp_retcode = PAM_SUCCESS;
- reply[replies].resp = COPY_STRING(PAM_username);
+ reply[replies].resp = estrdup(PAM_username);
/* PAM frees resp */
break;
case PAM_PROMPT_ECHO_OFF:
reply[replies].resp_retcode = PAM_SUCCESS;
- reply[replies].resp = COPY_STRING(PAM_password);
+ reply[replies].resp = estrdup(PAM_password);
/* PAM frees resp */
break;
case PAM_TEXT_INFO:
if (new_prompt == NULL) {
/* allocate space for new prompt */
np_size = op_len + strlen(challenge) + 7;
- if (!(new_prompt = (char *) malloc(np_size))) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
+ new_prompt = (char *) emalloc(np_size);
} else {
/* already have space allocated, is it enough? */
if (np_size < op_len + strlen(challenge) + 7) {
np_size = op_len + strlen(challenge) + 7;
- if (!(new_prompt = (char *) realloc(new_prompt, np_size))) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n",
- Argv[0]);
- exit(1);
- }
+ new_prompt = (char *) erealloc(new_prompt, np_size);
}
}
if (new_prompt == NULL) {
/* allocate space for new prompt */
np_size = op_len + strlen(challenge) + 7;
- if (!(new_prompt = (char *) malloc(np_size))) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
+ new_prompt = (char *) emalloc(np_size);
} else {
/* already have space allocated, is it enough? */
if (np_size < op_len + strlen(challenge) + 7) {
np_size = op_len + strlen(challenge) + 7;
- if (!(new_prompt = (char *) realloc(new_prompt, np_size))) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n",
- Argv[0]);
- exit(1);
- }
+ new_prompt = (char *) erealloc(new_prompt, np_size);
}
}
}
if (subst) {
- if ((new_prompt = (char *) malloc(len + 1)) == NULL) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
+ new_prompt = (char *) emalloc(len + 1);
for (p = prompt, np = new_prompt; *p; p++) {
if (lastchar == '%' && (*p == 'h' || *p == 'u' || *p == '%')) {
/* substiture user/host name */
* ocommand contain the resolved and unresolved pathnames respectively.
* NOTE: if "." or "" exists in PATH it will be searched last.
*
- * Todd C. Miller (millert@colorado.edu) Sat Mar 25 21:50:36 MST 1995
+ * Todd C. Miller <Todd.Miller@courtesan.com> Sat Mar 25 21:50:36 MST 1995
*/
#include "config.h"
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif /* HAVE_STRINGS_H */
-#if defined(HAVE_MALLOC_H) && !defined(STDC_HEADERS)
-#include <malloc.h>
-#endif /* HAVE_MALLOC_H && !STDC_HEADERS */
#include <errno.h>
#include <sys/types.h>
#include <sys/param.h>
#include "sudo.h"
#ifndef STDC_HEADERS
-#ifndef __GNUC__ /* gcc has its own malloc */
-extern char *malloc __P((size_t));
-#endif /* __GNUC__ */
extern char *getenv __P((const char *));
extern char *strcpy __P((char *, const char *));
extern int fprintf __P((FILE *, const char *, ...));
extern ssize_t readlink __P((const char *, VOID *, size_t));
extern int stat __P((const char *, struct stat *));
extern int lstat __P((const char *, struct stat *));
-#ifdef HAVE_STRDUP
-extern char *strdup __P((const char *));
-#endif /* HAVE_STRDUP */
#endif /* !STDC_HEADERS */
#ifndef _S_IFMT
if ((path = getenv("PATH")) == NULL)
return(NOT_FOUND);
- if ((path = (char *) strdup(path)) == NULL) {
- (void) fprintf(stderr, "%s: out of memory!\n", Argv[0]);
- exit(1);
- }
+ path = estrdup(path);
origpath = path;
/* XXX use strtok() */
#ifdef STDC_HEADERS
#include <stdlib.h>
#endif /* STDC_HEADERS */
-#if defined(HAVE_MALLOC_H) && !defined(STDC_HEADERS)
-#include <malloc.h>
-#endif /* HAVE_MALLOC_H && !STDC_HEADERS */
#ifdef HAVE_STRING_H
#include <string.h>
#endif /* HAVE_STRING_H */
#endif /* lint */
#ifndef STDC_HEADERS
-#ifndef __GNUC__ /* gcc has its own malloc */
-extern char *malloc __P((size_t));
-#endif /* __GNUC__ */
extern char *getenv __P((const char *));
-#ifdef HAVE_STRDUP
-extern char *strdup __P((const char *));
-#endif /* HAVE_STRDUP */
#endif /* !STDC_HEADERS */
/*
return(NULL);
/* allocate space for a local copy of pw */
- local_pw = (struct passwd *) malloc(sizeof(struct passwd));
- if (local_pw == NULL) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
+ local_pw = (struct passwd *) emalloc(sizeof(struct passwd));
/*
* Copy the struct passwd and the interesting strings...
*/
(void) memcpy(local_pw, pw, sizeof(struct passwd));
-
- local_pw->pw_name = (char *) strdup(pw->pw_name);
- if (local_pw->pw_name == NULL) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
-
- local_pw->pw_dir = (char *) strdup(pw->pw_dir);
- if (local_pw->pw_dir == NULL) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
+ local_pw->pw_name = estrdup(pw->pw_name);
+ local_pw->pw_dir = estrdup(pw->pw_dir);
/* pw_shell is a special case since we overide with $SHELL */
- local_pw->pw_shell = (char *) strdup(sudo_getshell(pw));
- if (local_pw->pw_shell == NULL) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
+ local_pw->pw_shell = estrdup(sudo_getshell(pw));
/* pw_passwd gets a shadow password if applicable */
- local_pw->pw_passwd = (char *) strdup(sudo_getepw(pw));
- if (local_pw->pw_passwd == NULL) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
+ local_pw->pw_passwd = estrdup(sudo_getepw(pw));
return(local_pw);
}
* if the path is stat(2)'able, a regular file, and executable by
* root. The string's size should be <= MAXPATHLEN.
*
- * Todd C. Miller (millert@colorado.edu) Sat Mar 25 21:58:17 MST 1995
+ * Todd C. Miller <Todd.Miller@courtesan.com> Sat Mar 25 21:58:17 MST 1995
*/
#include "config.h"
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif /* HAVE_STRINGS_H */
-#if defined(HAVE_MALLOC_H) && !defined(STDC_HEADERS)
-#include <malloc.h>
-#endif /* HAVE_MALLOC_H && !STDC_HEADERS */
#include <netdb.h>
#include <errno.h>
#include <sys/types.h>
#include "sudo.h"
#include "version.h"
-#if !defined(STDC_HEADERS) && !defined(__GNUC__)
-extern char *malloc __P((size_t));
-extern char *realloc __P((VOID *, size_t));
-#endif /* !STDC_HEADERS && !__GNUC__ */
-
#ifndef lint
static const char rcsid[] = "$Sudo$";
#endif /* lint */
* get interface configuration or return (leaving interfaces NULL)
*/
for (;;) {
- ifconf_buf = ifconf_buf ? realloc(ifconf_buf, len) : malloc(len);
- if (ifconf_buf == NULL) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
+ ifconf_buf = erealloc(ifconf_buf, len);
ifconf = (struct ifconf *) ifconf_buf;
ifconf->ifc_len = len - sizeof(struct ifconf);
ifconf->ifc_buf = (caddr_t) (ifconf_buf + sizeof(struct ifconf));
n = ifconf->ifc_len / sizeof(struct ifreq);
/*
- * malloc() space for interfaces array
+ * allocate space for interfaces array
*/
- interfaces = (struct interface *) malloc(sizeof(struct interface) * n);
- if (interfaces == NULL) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
+ interfaces = (struct interface *) emalloc(sizeof(struct interface) * n);
/*
* for each interface, store the ip address and netmask
/* if there were bogus entries, realloc the array */
if (n != num_interfaces) {
/* it is unlikely that num_interfaces will be 0 but who knows... */
- if (num_interfaces != 0) {
- interfaces = (struct interface *) realloc(interfaces,
+ if (num_interfaces != 0)
+ interfaces = (struct interface *) erealloc(interfaces,
sizeof(struct interface) * num_interfaces);
- if (interfaces == NULL) {
- perror("realloc");
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
- } else {
+ else
(void) free(interfaces);
- }
}
(void) free(ifconf_buf);
(void) close(sock);
while (new_len >= (arg_size += COMMANDARGINC))
;
- yylval.command.args = (char *) realloc(yylval.command.args, arg_size);
- if (yylval.command.args == NULL)
+ if ((p = (char *) realloc(yylval.command.args, arg_size)) == NULL) {
+ (void) free(yylval.command.args);
yyerror("unable to allocate memory");
+ } else
+ yylval.command.args = p;
}
}
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif /* HAVE_STRINGS_H */
-#if defined(HAVE_MALLOC_H) && !defined(STDC_HEADERS)
-#include <malloc.h>
-#endif /* HAVE_MALLOC_H && !STDC_HEADERS */
#include <pwd.h>
#include <signal.h>
#include <time.h>
strlen(runas_user);
if (cmnd_args)
count += strlen(cmnd_args);
-
- logline = (char *) malloc(count);
- if (logline == NULL) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
+ logline = (char *) emalloc(count);
/*
* we will skip this stuff when using syslog(3) but it is
# include "emul/fnmatch.h"
# endif /* HAVE_FNMATCH */
#endif /* HAVE_FNMATCH_H */
-#if defined(HAVE_MALLOC_H) && !defined(STDC_HEADERS)
-# include <malloc.h>
-#endif /* HAVE_MALLOC_H && !STDC_HEADERS */
#ifdef HAVE_NETGROUP_H
# include <netgroup.h>
#endif /* HAVE_NETGROUP_H */
#ifdef HAVE_GETDOMAINNAME
/* get the domain name (if any) */
if (domain == (char *) -1) {
- if ((domain = (char *) malloc(MAXHOSTNAMELEN)) == NULL) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
-
+ domain = (char *) emalloc(MAXHOSTNAMELEN);
if (getdomainname(domain, MAXHOSTNAMELEN) != 0 || *domain == '\0') {
(void) free(domain);
domain = NULL;
while (new_len >= (arg_size += COMMANDARGINC))
;
- yylval.command.args = (char *) realloc(yylval.command.args, arg_size);
- if (yylval.command.args == NULL)
+ if ((p = (char *) realloc(yylval.command.args, arg_size)) == NULL) {
+ (void) free(yylval.command.args);
yyerror("unable to allocate memory");
+ } else
+ yylval.command.args = p;
}
}
{ \
if (top >= stacksize) { \
while ((stacksize += STACKINCREMENT) < top); \
- match = (struct matchstack *) realloc(match, sizeof(struct matchstack) * stacksize); \
- if (match == NULL) { \
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]); \
- exit(1); \
- } \
+ match = (struct matchstack *) erealloc(match, sizeof(struct matchstack) * stacksize); \
} \
match[top].user = -1; \
match[top].cmnd = -1; \
in_alias = TRUE;
/* Allocate space for ga_list if necesary. */
expand_ga_list();
- if (!(ga_list[ga_list_len-1].alias = (char *) strdup($1))){
- (void) fprintf(stderr,
- "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
+ ga_list[ga_list_len-1].alias = estrdup($1);
}
} '=' cmndlist {
if (cmnd_matches == TRUE &&
in_alias = TRUE;
/* Allocate space for ga_list if necesary. */
expand_ga_list();
- if (!(ga_list[ga_list_len-1].alias = (char *) strdup($1))){
- (void) fprintf(stderr,
- "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
+ ga_list[ga_list_len-1].alias = estrdup($1);
}
} '=' runaslist {
if ($4 > 0 && add_alias($1, RUNAS_ALIAS) == FALSE)
}
(void) free(cm_list);
cm_list = NULL;
+ cm_list_len = 0;
+ cm_list_size = 0;
}
/* Assumes dst will be NULL if not set. */
if (dst == NULL) {
- if ((dst = (char *) malloc(BUFSIZ)) == NULL) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
-
+ dst = (char *) emalloc(BUFSIZ);
*dst_size = BUFSIZ;
*dst_len = 0;
*dstp = dst;
while (*dst_size <= *dst_len + src_len)
*dst_size += BUFSIZ;
- if (!(dst = (char *) realloc(dst, *dst_size))) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
+ dst = (char *) erealloc(dst, *dst_size);
*dstp = dst;
}
void reset_aliases()
{
- if (aliases)
+ if (aliases) {
(void) free(aliases);
+ aliases = NULL;
+ }
naliases = nslots = 0;
}
static void expand_ga_list()
{
if (++ga_list_len >= ga_list_size) {
- while ((ga_list_size += STACKINCREMENT) < ga_list_len);
- if (ga_list == NULL) {
- if ((ga_list = (struct generic_alias *)
- malloc(sizeof(struct generic_alias) * ga_list_size)) == NULL) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
- } else {
- if ((ga_list = (struct generic_alias *) realloc(ga_list,
- sizeof(struct generic_alias) * ga_list_size)) == NULL) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
- }
+ while ((ga_list_size += STACKINCREMENT) < ga_list_len)
+ ;
+ ga_list = (struct generic_alias *)
+ erealloc(ga_list, sizeof(struct generic_alias) * ga_list_size);
}
ga_list[ga_list_len - 1].entries = NULL;
static void expand_match_list()
{
if (++cm_list_len >= cm_list_size) {
- while ((cm_list_size += STACKINCREMENT) < cm_list_len);
- if (cm_list == NULL) {
- if ((cm_list = (struct command_match *)
- malloc(sizeof(struct command_match) * cm_list_size)) == NULL) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
- cm_list_len = 0;
- } else {
- if ((cm_list = (struct command_match *) realloc(cm_list,
- sizeof(struct command_match) * cm_list_size)) == NULL) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
- }
+ while ((cm_list_size += STACKINCREMENT) < cm_list_len)
+ ;
+ cm_list = (struct command_match *)
+ erealloc(cm_list, sizeof(struct command_match) * cm_list_size);
}
cm_list[cm_list_len].runas = cm_list[cm_list_len].cmnd = NULL;
/* Allocate space for the matching stack. */
stacksize = STACKINCREMENT;
- match = (struct matchstack *) malloc(sizeof(struct matchstack) * stacksize);
- if (match == NULL) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
+ match = (struct matchstack *) emalloc(sizeof(struct matchstack) * stacksize);
/* Allocate space for the match list (for `sudo -l'). */
if (printmatches == TRUE)
*
* This module contains putenv(3) for those systems that lack it.
*
- * Todd C. Miller (millert@colorado.edu) Sun Aug 7 20:30:17 MDT 1994
+ * Todd C. Miller <Todd.Miller@courtesan.com> Sun Aug 7 20:30:17 MDT 1994
*/
#include "config.h"
#include "compat.h"
#if !defined(STDC_HEADERS) && !defined(__GNUC__)
-extern char *malloc __P((size_t));
+extern VOID *malloc __P((size_t));
#endif /* !STDC_HEADERS && !gcc */
#ifndef lint
*
* secureware.c -- check a user's password when using SecureWare C2
*
- * Todd C. Miller (millert@colorado.edu) Sat Oct 17 14:42:44 MDT 1998
+ * Todd C. Miller <Todd.Miller@courtesan.com> Sat Oct 17 14:42:44 MDT 1998
*/
#include "config.h"
#ifndef STDC_HEADERS
#ifndef __GNUC__ /* gcc has its own malloc */
-extern char *malloc __P((size_t));
+extern VOID *malloc __P((size_t));
#endif /* __GNUC__ */
extern char *strcpy __P((char *, const char *));
#endif /* !STDC_HEADERS */
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif /* HAVE_STRINGS_H */
-#if defined(HAVE_MALLOC_H) && !defined(STDC_HEADERS)
-#include <malloc.h>
-#endif /* HAVE_MALLOC_H && !STDC_HEADERS */
#include <pwd.h>
#include <errno.h>
#include <fcntl.h>
#include "version.h"
#ifndef STDC_HEADERS
-#ifndef __GNUC__ /* gcc has its own malloc */
-extern char *malloc __P((size_t));
-#endif /* __GNUC__ */
-#ifdef HAVE_STRDUP
-extern char *strdup __P((const char *));
-#endif /* HAVE_STRDUP */
extern char *getenv __P((char *));
#endif /* STDC_HEADERS */
if ((sudo_mode & MODE_SHELL)) {
char **dst, **src = NewArgv;
- NewArgv = (char **) malloc (sizeof(char *) * (++NewArgc + 1));
- if (NewArgv == NULL) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
+ NewArgv = (char **) emalloc (sizeof(char *) * (++NewArgc + 1));
/* add the shell as argv[0] */
if (user_shell && *user_shell) {
realm = lrealm;
if (!arg_prompt) {
- p = malloc(strlen(user_name) + strlen(realm) + 17);
- if (p == NULL) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
+ p = emalloc(strlen(user_name) + strlen(realm) + 17);
sprintf(p, "Password for %s@%s: ", user_name, realm);
prompt = p;
}
if ((p = (char *) ttyname(0)) || (p = (char *) ttyname(1))) {
if (strncmp(p, _PATH_DEV, sizeof(_PATH_DEV) - 1) == 0)
p += sizeof(_PATH_DEV) - 1;
- if ((tty = (char *) strdup(p)) == NULL) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
+ tty = estrdup(p);
}
#ifdef SUDO_UMASK
*/
if ((p = strchr(host, '.'))) {
*p = '\0';
- if ((shost = (char *) strdup(host)) == NULL) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
+ shost = estrdup(host);
*p = '.';
} else {
shost = &host[0];
size += strlen(*from) + 1;
}
- if ((buf = (char *) malloc(size)) == NULL) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
+ buf = (char *) emalloc(size);
/*
* Copy the command and it's arguments info buf
*/
#define YY_DECL int yylex __P((void))
-#ifndef HAVE_STRDUP
-char *strdup __P((const char *));
-#endif
#ifndef HAVE_GETCWD
char *getcwd __P((char *, size_t size));
#endif
void sia_attempt_auth __P((void));
int yyparse __P((void));
void pass_warn __P((FILE *));
+VOID *emalloc __P((size_t));
+VOID *erealloc __P((VOID *, size_t));
+VOID *estrdup __P((char *));
YY_DECL;
{ \
if (top >= stacksize) { \
while ((stacksize += STACKINCREMENT) < top); \
- match = (struct matchstack *) realloc(match, sizeof(struct matchstack) * stacksize); \
- if (match == NULL) { \
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]); \
- exit(1); \
- } \
+ match = (struct matchstack *) erealloc(match, sizeof(struct matchstack) * stacksize); \
} \
match[top].user = -1; \
match[top].cmnd = -1; \
#endif
parse_error = TRUE;
}
-#line 162 "parse.yacc"
+#line 158 "parse.yacc"
typedef union {
char *string;
int BOOLEAN;
struct sudo_command command;
int tok;
} YYSTYPE;
-#line 186 "sudo.tab.c"
+#line 182 "sudo.tab.c"
#define ALIAS 257
#define NTWKADDR 258
#define FQHOST 259
short *yysslim;
YYSTYPE *yyvs;
int yystacksize;
-#line 621 "parse.yacc"
+#line 609 "parse.yacc"
typedef struct {
}
(void) free(cm_list);
cm_list = NULL;
+ cm_list_len = 0;
+ cm_list_size = 0;
}
/* Assumes dst will be NULL if not set. */
if (dst == NULL) {
- if ((dst = (char *) malloc(BUFSIZ)) == NULL) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
-
+ dst = (char *) emalloc(BUFSIZ);
*dst_size = BUFSIZ;
*dst_len = 0;
*dstp = dst;
while (*dst_size <= *dst_len + src_len)
*dst_size += BUFSIZ;
- if (!(dst = (char *) realloc(dst, *dst_size))) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
+ dst = (char *) erealloc(dst, *dst_size);
*dstp = dst;
}
void reset_aliases()
{
- if (aliases)
+ if (aliases) {
(void) free(aliases);
+ aliases = NULL;
+ }
naliases = nslots = 0;
}
static void expand_ga_list()
{
if (++ga_list_len >= ga_list_size) {
- while ((ga_list_size += STACKINCREMENT) < ga_list_len);
- if (ga_list == NULL) {
- if ((ga_list = (struct generic_alias *)
- malloc(sizeof(struct generic_alias) * ga_list_size)) == NULL) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
- } else {
- if ((ga_list = (struct generic_alias *) realloc(ga_list,
- sizeof(struct generic_alias) * ga_list_size)) == NULL) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
- }
+ while ((ga_list_size += STACKINCREMENT) < ga_list_len)
+ ;
+ ga_list = (struct generic_alias *)
+ erealloc(ga_list, sizeof(struct generic_alias) * ga_list_size);
}
ga_list[ga_list_len - 1].entries = NULL;
static void expand_match_list()
{
if (++cm_list_len >= cm_list_size) {
- while ((cm_list_size += STACKINCREMENT) < cm_list_len);
- if (cm_list == NULL) {
- if ((cm_list = (struct command_match *)
- malloc(sizeof(struct command_match) * cm_list_size)) == NULL) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
- cm_list_len = 0;
- } else {
- if ((cm_list = (struct command_match *) realloc(cm_list,
- sizeof(struct command_match) * cm_list_size)) == NULL) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
- }
+ while ((cm_list_size += STACKINCREMENT) < cm_list_len)
+ ;
+ cm_list = (struct command_match *)
+ erealloc(cm_list, sizeof(struct command_match) * cm_list_size);
}
cm_list[cm_list_len].runas = cm_list[cm_list_len].cmnd = NULL;
/* Allocate space for the matching stack. */
stacksize = STACKINCREMENT;
- match = (struct matchstack *) malloc(sizeof(struct matchstack) * stacksize);
- if (match == NULL) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
+ match = (struct matchstack *) emalloc(sizeof(struct matchstack) * stacksize);
/* Allocate space for the match list (for `sudo -l'). */
if (printmatches == TRUE)
expand_match_list();
}
-#line 874 "sudo.tab.c"
+#line 842 "sudo.tab.c"
/* allocate initial stack or double stack size, up to YYMAXDEPTH */
#if defined(__cplusplus) || __STDC__
static int yygrowstack(void)
switch (yyn)
{
case 3:
-#line 203 "parse.yacc"
+#line 199 "parse.yacc"
{ ; }
break;
case 4:
-#line 205 "parse.yacc"
+#line 201 "parse.yacc"
{ yyerrok; }
break;
case 5:
-#line 206 "parse.yacc"
+#line 202 "parse.yacc"
{ push; }
break;
case 6:
-#line 206 "parse.yacc"
+#line 202 "parse.yacc"
{
while (top && user_matches != TRUE) {
pop;
}
break;
case 7:
-#line 212 "parse.yacc"
+#line 208 "parse.yacc"
{ ; }
break;
case 8:
-#line 214 "parse.yacc"
+#line 210 "parse.yacc"
{ ; }
break;
case 9:
-#line 216 "parse.yacc"
+#line 212 "parse.yacc"
{ ; }
break;
case 10:
-#line 218 "parse.yacc"
+#line 214 "parse.yacc"
{ ; }
break;
case 13:
-#line 226 "parse.yacc"
+#line 222 "parse.yacc"
{
if (user_matches == TRUE) {
push;
}
break;
case 14:
-#line 237 "parse.yacc"
+#line 233 "parse.yacc"
{
host_matches = TRUE;
}
break;
case 15:
-#line 240 "parse.yacc"
+#line 236 "parse.yacc"
{
if (addr_matches(yyvsp[0].string))
host_matches = TRUE;
}
break;
case 16:
-#line 245 "parse.yacc"
+#line 241 "parse.yacc"
{
if (netgr_matches(yyvsp[0].string, host, NULL))
host_matches = TRUE;
}
break;
case 17:
-#line 250 "parse.yacc"
+#line 246 "parse.yacc"
{
if (strcasecmp(shost, yyvsp[0].string) == 0)
host_matches = TRUE;
}
break;
case 18:
-#line 255 "parse.yacc"
+#line 251 "parse.yacc"
{
if (strcasecmp(host, yyvsp[0].string) == 0)
host_matches = TRUE;
}
break;
case 19:
-#line 260 "parse.yacc"
+#line 256 "parse.yacc"
{
/* could be an all-caps hostname */
if (find_alias(yyvsp[0].string, HOST_ALIAS) == TRUE ||
}
break;
case 22:
-#line 273 "parse.yacc"
+#line 269 "parse.yacc"
{ /* Push a new entry onto the stack if needed */
if (user_matches == TRUE && host_matches == TRUE &&
cmnd_matches == TRUE && runas_matches == TRUE) {
}
break;
case 23:
-#line 284 "parse.yacc"
+#line 280 "parse.yacc"
{
if (yyvsp[-2].BOOLEAN > 0 && yyvsp[0].BOOLEAN == TRUE) {
runas_matches = TRUE;
}
break;
case 24:
-#line 297 "parse.yacc"
+#line 293 "parse.yacc"
{ ; }
break;
case 25:
-#line 298 "parse.yacc"
+#line 294 "parse.yacc"
{
if (printmatches == TRUE && host_matches == TRUE &&
user_matches == TRUE) {
}
break;
case 26:
-#line 310 "parse.yacc"
+#line 306 "parse.yacc"
{
int cmnd_matched = cmnd_matches;
pop;
}
break;
case 27:
-#line 321 "parse.yacc"
+#line 317 "parse.yacc"
{
yyval.BOOLEAN = (strcmp(RUNAS_DEFAULT, runas_user) == 0);
}
break;
case 28:
-#line 324 "parse.yacc"
+#line 320 "parse.yacc"
{
yyval.BOOLEAN = yyvsp[0].BOOLEAN;
}
break;
case 29:
-#line 329 "parse.yacc"
+#line 325 "parse.yacc"
{
yyval.BOOLEAN = yyvsp[0].BOOLEAN;
}
break;
case 30:
-#line 332 "parse.yacc"
+#line 328 "parse.yacc"
{
yyval.BOOLEAN = yyvsp[-2].BOOLEAN + yyvsp[0].BOOLEAN;
}
break;
case 31:
-#line 338 "parse.yacc"
+#line 334 "parse.yacc"
{
yyval.BOOLEAN = (strcmp(yyvsp[0].string, runas_user) == 0);
if (printmatches == TRUE && in_alias == TRUE)
}
break;
case 32:
-#line 351 "parse.yacc"
+#line 347 "parse.yacc"
{
yyval.BOOLEAN = usergr_matches(yyvsp[0].string, runas_user);
if (printmatches == TRUE && in_alias == TRUE)
}
break;
case 33:
-#line 368 "parse.yacc"
+#line 364 "parse.yacc"
{
yyval.BOOLEAN = netgr_matches(yyvsp[0].string, NULL, runas_user);
if (printmatches == TRUE && in_alias == TRUE)
}
break;
case 34:
-#line 385 "parse.yacc"
+#line 381 "parse.yacc"
{
/* could be an all-caps username */
if (find_alias(yyvsp[0].string, RUNAS_ALIAS) == TRUE ||
}
break;
case 35:
-#line 403 "parse.yacc"
+#line 399 "parse.yacc"
{
yyval.BOOLEAN = TRUE;
if (printmatches == TRUE && in_alias == TRUE)
}
break;
case 36:
-#line 417 "parse.yacc"
+#line 413 "parse.yacc"
{
yyval.BOOLEAN = FALSE;
}
break;
case 37:
-#line 420 "parse.yacc"
+#line 416 "parse.yacc"
{
yyval.BOOLEAN = TRUE;
if (printmatches == TRUE && host_matches == TRUE &&
}
break;
case 38:
-#line 428 "parse.yacc"
+#line 424 "parse.yacc"
{
if (printmatches == TRUE && in_alias == TRUE) {
append("ALL", &ga_list[ga_list_len-1].entries,
}
break;
case 39:
-#line 445 "parse.yacc"
+#line 441 "parse.yacc"
{
if (printmatches == TRUE && in_alias == TRUE) {
append(yyvsp[0].string, &ga_list[ga_list_len-1].entries,
}
break;
case 40:
-#line 464 "parse.yacc"
+#line 460 "parse.yacc"
{
if (printmatches == TRUE && in_alias == TRUE) {
append(yyvsp[0].command.cmnd, &ga_list[ga_list_len-1].entries,
}
break;
case 43:
-#line 503 "parse.yacc"
+#line 499 "parse.yacc"
{ push; }
break;
case 44:
-#line 503 "parse.yacc"
+#line 499 "parse.yacc"
{
if (host_matches == TRUE &&
add_alias(yyvsp[-3].string, HOST_ALIAS) == FALSE)
}
break;
case 49:
-#line 519 "parse.yacc"
+#line 515 "parse.yacc"
{
push;
if (printmatches == TRUE) {
in_alias = TRUE;
/* Allocate space for ga_list if necesary. */
expand_ga_list();
- if (!(ga_list[ga_list_len-1].alias = (char *) strdup(yyvsp[0].string))){
- (void) fprintf(stderr,
- "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
+ ga_list[ga_list_len-1].alias = estrdup(yyvsp[0].string);
}
}
break;
case 50:
-#line 531 "parse.yacc"
+#line 523 "parse.yacc"
{
if (cmnd_matches == TRUE &&
add_alias(yyvsp[-3].string, CMND_ALIAS) == FALSE)
}
break;
case 51:
-#line 544 "parse.yacc"
+#line 536 "parse.yacc"
{ ; }
break;
case 55:
-#line 552 "parse.yacc"
+#line 544 "parse.yacc"
{
push;
if (printmatches == TRUE) {
in_alias = TRUE;
/* Allocate space for ga_list if necesary. */
expand_ga_list();
- if (!(ga_list[ga_list_len-1].alias = (char *) strdup(yyvsp[0].string))){
- (void) fprintf(stderr,
- "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
+ ga_list[ga_list_len-1].alias = estrdup(yyvsp[0].string);
}
}
break;
case 56:
-#line 564 "parse.yacc"
+#line 552 "parse.yacc"
{
if (yyvsp[0].BOOLEAN > 0 && add_alias(yyvsp[-3].string, RUNAS_ALIAS) == FALSE)
YYERROR;
}
break;
case 59:
-#line 579 "parse.yacc"
+#line 567 "parse.yacc"
{ push; }
break;
case 60:
-#line 579 "parse.yacc"
+#line 567 "parse.yacc"
{
if (user_matches == TRUE &&
add_alias(yyvsp[-3].string, USER_ALIAS) == FALSE)
}
break;
case 61:
-#line 589 "parse.yacc"
+#line 577 "parse.yacc"
{ ; }
break;
case 63:
-#line 593 "parse.yacc"
+#line 581 "parse.yacc"
{
if (strcmp(yyvsp[0].string, user_name) == 0)
user_matches = TRUE;
}
break;
case 64:
-#line 598 "parse.yacc"
+#line 586 "parse.yacc"
{
if (usergr_matches(yyvsp[0].string, user_name))
user_matches = TRUE;
}
break;
case 65:
-#line 603 "parse.yacc"
+#line 591 "parse.yacc"
{
if (netgr_matches(yyvsp[0].string, NULL, user_name))
user_matches = TRUE;
}
break;
case 66:
-#line 608 "parse.yacc"
+#line 596 "parse.yacc"
{
/* could be an all-caps username */
if (find_alias(yyvsp[0].string, USER_ALIAS) == TRUE ||
}
break;
case 67:
-#line 615 "parse.yacc"
+#line 603 "parse.yacc"
{
user_matches = TRUE;
}
break;
-#line 1552 "sudo.tab.c"
+#line 1512 "sudo.tab.c"
}
yyssp -= yym;
yystate = *yyssp;
* This module contains sudo_setenv().
* sudo_setenv(3) adds a string of the form "var=val" to the environment.
*
- * Todd C. Miller (millert@colorado.edu) Fri Jun 3 18:32:19 MDT 1994
+ * Todd C. Miller <Todd.Miller@courtesan.com> Fri Jun 3 18:32:19 MDT 1994
*/
#include "config.h"
# include "emul/fnmatch.h"
# endif /* HAVE_FNMATCH */
#endif /* HAVE_FNMATCH_H */
-#if defined(HAVE_MALLOC_H) && !defined(STDC_HEADERS)
-# include <malloc.h>
-#endif /* HAVE_MALLOC_H && !STDC_HEADERS */
#ifdef HAVE_NETGROUP_H
# include <netgroup.h>
#endif /* HAVE_NETGROUP_H */
#ifdef HAVE_GETDOMAINNAME
/* get the domain name (if any) */
if (domain == (char *) -1) {
- if ((domain = (char *) malloc(MAXHOSTNAMELEN)) == NULL) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
+ domain = (char *) emalloc(MAXHOSTNAMELEN);
if (getdomainname(domain, MAXHOSTNAMELEN) != 0 || *domain == '\0') {
(void) free(domain);
if ((p = strchr(host, '.'))) {
*p = '\0';
- if ((shost = (char *) strdup(host)) == NULL) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
+ shost = estrdup(host);
*p = '.';
} else {
shost = &host[0];
size = (size_t) NewArgv[NewArgc-1] + strlen(NewArgv[NewArgc-1]) -
(size_t) NewArgv[1] + 1;
- if ((cmnd_args = (char *) malloc(size)) == NULL) {
- (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
- exit(1);
- }
+ cmnd_args = (char *) emalloc(size);
for (to = cmnd_args, from = &NewArgv[1]; *from; from++) {
*to++ = ' ';
(void) strcpy(to, *from);
* lack utime(2).
* utime(3) sets the access and mod times of the named file.
*
- * Todd C. Miller (millert@colorado.edu) Sat Jun 17 16:42:41 MDT 1995
+ * Todd C. Miller <Todd.Miller@courtesan.com> Sat Jun 17 16:42:41 MDT 1995
*/
#include "config.h"
* visudo.c -- locks the sudoers file for safe editing and check
* for parse errors.
*
- * Todd C. Miller (millert@colorado.edu) Sat Mar 25 21:50:36 MST 1995
+ * Todd C. Miller <Todd.Miller@courtesan.com> Sat Mar 25 21:50:36 MST 1995
*/
#include "config.h"