Beispiel #1
0
void write_sqconfig(const char *dir, const char *configfile, const char *val)
{
    char *p=malloc(strlen(dir) + strlen(configfile) + 2);
    FILE	*f;

    if (!p)	enomem();
    strcat(strcat(strcpy(p, dir), "/"), configfile);
    if (!val)
        unlink(p);
    else
    {
        f=fopen(p, "w");
        if (!f)	enomem();
        fprintf(f, "%s\n", val);
        fflush(f);
        if (ferror(f))	enomem();
        fclose(f);

        /* Note - umask should already turn off the 077 bits, but
        ** just in case someone screwed up previously, I'll fix it
        ** myself */

        chmod(p, 0600);
    }
    free(p);
}
Beispiel #2
0
static char *getgpgconfig(const char *name)
{
	const char *p;
	char	*q, *r;

	int name_l=strlen(name);

	p=read_sqconfig(".", GPGCONFIGFILE, 0);

	if (p)
	{
		q=strdup(p);
		if (!q)
			enomem();

		for (r=q; (r=strtok(r, " ")) != NULL; r=NULL)
			if (strncmp(r, name, name_l) == 0 &&
			    r[name_l] == '=')
			{
				r=strdup(r+name_l+1);
				free(q);
				if (!r)
					enomem();
				return (r);
			}
		free(q);
	}
	return (NULL);
}
Beispiel #3
0
int login_changepwd(const char *u, const char *oldpwd, const char *newpwd,
		    int *rc)
{
	char *uid=strdup(u);
	char *driver;
	int	i;

	if (!uid)
		enomem();

	verifyuid(uid);

	if ((driver=strrchr(uid, '.')) == 0)
	{
		free(uid);
		enomem();
	}

	*driver++=0;

	for (i=0; authstaticmodulelist[i]; i++)
	{
		if (strcmp(authstaticmodulelist[i]->auth_name, driver) == 0)
		{
			*rc=badstr(uid) || badstr(oldpwd) || badstr(newpwd)
				? 1:(*authstaticmodulelist[i]->auth_changepwd)
				("webmail", uid, oldpwd, newpwd);

			free(uid);
			return (0);
		}
	}
	return (-1);
}
Beispiel #4
0
rt_public void once_init (void)
{
	EIF_GET_CONTEXT

#if !defined(WORKBENCH) && !defined (EIF_THREADS)
	int32 old_egc_prof_enabled = egc_prof_enabled; /* Save profiler status */
	egc_prof_enabled = 0;	/* Disable profiler as it is not initialized yet. */
#endif

	ALLOC_ONCE_INDEXES; 	/* Allocate array of once indexes. */
	egc_system_mod_init (); /* Assign once indexes. */

#if !defined(WORKBENCH) && !defined (EIF_THREADS)
	egc_prof_enabled = old_egc_prof_enabled; /* Restore profiler status. */
#endif

	if (!debug_mode) {
			/* Once indexes could be used by debugger,
			 * but we are not under debugger at the moment. */
		FREE_ONCE_INDEXES;	/* Free once indexes. */
	}

	/* Allocate room for once manifest strings array. */
	ALLOC_OMS (EIF_oms);

	if (EIF_once_count == 0) {
		EIF_once_values = (EIF_once_value_t *) 0;
	} else {
		/* Allocate room for once values. */
		EIF_once_values = (EIF_once_value_t *) eif_realloc (EIF_once_values, EIF_once_count * sizeof *EIF_once_values);
				/* needs malloc; crashes otherwise on some pure C-ansi compiler (SGI)*/
		if (EIF_once_values == (EIF_once_value_t *) 0) /* Out of memory */
			enomem();
		memset (EIF_once_values, 0, EIF_once_count * sizeof *EIF_once_values);
	}

#ifdef EIF_THREADS
	if (EIF_process_once_count == 0) {
		EIF_process_once_values = (EIF_process_once_value_t *) 0;
	} else {
			/* Allocate room for process-relative once values. */
		EIF_process_once_values = (EIF_process_once_value_t *) eif_realloc (EIF_process_once_values, EIF_process_once_count * sizeof *EIF_process_once_values);
				/* needs malloc; crashes otherwise on some pure C-ansi compiler (SGI)*/
		if (EIF_process_once_values == (EIF_process_once_value_t *) 0) /* Out of memory */
			enomem();
		memset (EIF_process_once_values, 0, EIF_process_once_count * sizeof *EIF_process_once_values);
		{
			int i = EIF_process_once_count;
			while (i > 0) {
				i--;
				EIF_process_once_values [i].mutex = eif_thr_mutex_create ();
			}
		}
	}
#endif
}
Beispiel #5
0
static void setgpgconfig(const char *name, const char *value)
{
	const	char *p;
	char *q, *r, *s;
	int name_l=strlen(name);

	/* Get the existing settings */

	p=read_sqconfig(".", GPGCONFIGFILE, 0);

	if (!p)
		p="";

	q=strdup(p);
	if (!q)
		enomem();

	s=malloc(strlen(q)+strlen(name)+strlen(value)+4);
	if (!s)
		enomem();
	*s=0;

	/*
	** Copy existing settings into a new buffer, deleting any old
	** setting.
	*/

	for (r=q; (r=strtok(r, " ")) != NULL; r=NULL)
	{
		if (strncmp(r, name, name_l) == 0 &&
		    r[name_l] == '=')
		{
			continue;
		}

		if (*s)
			strcat(s, " ");
		strcat(s, r);
	}

	/* Append the new setting */

	if (*s)
		strcat(s, " ");
	strcat(strcat(strcat(s, name), "="), value);
	free(q);
	write_sqconfig(".", GPGCONFIGFILE, s);
	free(s);
}
Beispiel #6
0
const char *myhostname()
{
char    buf[512];
static char *my_hostname=0;
FILE	*f;

	if (my_hostname == 0)
	{
		buf[0]=0;
		if ((f=fopen(HOSTNAMEFILE, "r")) != 0)
		{
		char *p;

			if (fgets(buf, sizeof(buf), f) == NULL)
				buf[0]=0;

			fclose(f);

			if ((p=strchr(buf, '\n')) != 0)
				*p=0;
		}

		if (buf[0] == 0 && gethostname(buf, sizeof(buf)-1))
			strcpy(buf, "localhost");

		if ((my_hostname=malloc(strlen(buf)+1)) == 0)
			enomem();
		strcpy(my_hostname, buf);
	}
	return (my_hostname);
}
Beispiel #7
0
/* Setup the logging output mechanism. */
int
setup_log_file(CONFIG *cfg)
{
	char *fname;

	if (cfg->verbose < 1)
		return (0);

	if ((fname = calloc(strlen(cfg->home) +
	    strlen(cfg->table_name) + strlen(".stat") + 2, 1)) == NULL)
		return (enomem(cfg));

	sprintf(fname, "%s/%s.stat", cfg->home, cfg->table_name);
	cfg->logf = fopen(fname, "w");
	free(fname);

	if (cfg->logf == NULL) {
		fprintf(stderr,
		    "Failed to open log file: %s\n", strerror(errno));
		return (EINVAL);
	}

	/* Use line buffering for the log file. */
	(void)setvbuf(cfg->logf, NULL, _IOLBF, 0);
	return (0);
}
Beispiel #8
0
static char *append_str(const char *prefs, const char *label,
	const char *value)
{
int	l=strlen(prefs) + sizeof(" =") +
	strlen(label)+ (value ? strlen(value):0);
int	i;
char	*p;
const char *q;

	for (i=0; value && value[i]; i++)
		if (value[i] <= ' ' || value[i] >= 127
			|| value[i] == '+')
			l += 2;

	p=malloc(l);
	if (!p)	enomem();
	strcpy(p, prefs);
	if (!value || !*value)	return (p);

	strcat(strcat(strcat(p, " "), label), "=");
	i=strlen(p);
	for (q=value; *q; q++)
	{
		if (*q <= ' ' || *q >= 127 || *q == '+')
		{
			sprintf(p+i, "+%02X", (int)(unsigned char)*q);
			i += 3;
			continue;
		}
		p[i++]= *q;
	}
	p[i]=0;
	return (p);
}
Beispiel #9
0
/*
 * emalloc --
 *	malloc, but die on error.
 */
void * emalloc(size_t len) {
	void * ptr = malloc(len);

	if( ptr == NULL )
		enomem();
	return ptr;
}
Beispiel #10
0
/*
 * ecalloc --
 *	calloc, but die on error.
 */
void * ecalloc(size_t nmemb, size_t size) {
	void * ptr = calloc(nmemb, size);

	if( ptr == NULL )
		enomem();
	return ptr;
}
Beispiel #11
0
static void
save_arg(args_t *args, char *arg1, ...)
{
    char *carg;
    va_list argp;

    va_start(argp, arg1);
    carg = arg1;
    while (carg) {
	if (args->no <= args->ix) {
	    args->vec = (char **) (args->no
				   ? realloc((void *) args->vec,
					     (sizeof(char *)
					      *(args->no + ARGS_INCR + 1)))
				   : malloc((sizeof(char *)
					     *(args->no + ARGS_INCR + 1))));
	    if (!args->vec)
		enomem();
	    args->no += ARGS_INCR;
	}
	args->vec[args->ix++] = carg;
	args->chars += strlen(carg);
	carg = va_arg(argp, char *);
    }
    args->vec[args->ix++] = " ";
    args->chars++;
    va_end(argp);
}
Beispiel #12
0
static int spellignore(const char *word)
{
char	buf[100];
const char *c;
char	*p, *q;
FILE	*fp=opendict("r");

	if (!fp)	return (0);
	while (fgets(buf, sizeof(buf), fp) != NULL)
	{
		if ((p=strchr(buf, '\n')) != 0)	*p=0;
		if (strcmp(word, buf) == 0)
		{
			fclose(fp);
			return (1);
		}
	}
	fclose(fp);

	c=cgi("globignore");

	p=malloc(strlen(c)+1);
	if (!p)	enomem();
	strcpy(p, c);

	for (q=p; (q=strtok(q, ":")) != 0; q=0)
		if (strcmp(q, word) == 0)
		{
			free(p);
			return (1);
		}

	return (0);
}
Beispiel #13
0
/*
 * bmake_realloc --
 *	realloc, but die on error.
 */
void *
bmake_realloc(void *ptr, size_t size)
{
	if ((ptr = realloc(ptr, size)) == NULL)
		enomem();
	return(ptr);
}
Beispiel #14
0
void new_V3(
    float x,
    float y,
    float z)
{
    if (!current_prim) {
        printf("!!! ignoring V3 outside of prim\n");
        return;
    }
    struct prim_t * p = current_prim;
    struct V3_t * v = p->V3;
    if (!v) {
        v = malloc(sizeof(*v));
        p->V3 = v;
    } else {
        while (v->next)
            v = v->next;
        v->next = malloc(sizeof(*v));
        v = v->next;
    }
    if (!v) enomem();
    v->next = NULL;
    v->norm = norm_last;
    v->v.x = x;
    v->v.y = y;
    v->v.z = z;
    p->nV3++;
}
Beispiel #15
0
/*
 * estrdup --
 *	strdup, but die on error.
 */
char * estrdup(const char * str) {
	char * ptr = strdup(str);

	if( ptr == NULL )
		enomem();
	return ptr;
}
Beispiel #16
0
void * safe_alloc (void *ptr)
{
  if (ptr == NULL)
    {
      enomem ();
    }
  return ptr;
}
Beispiel #17
0
static void verifyuid(char *uid)
{
	if (badstr(uid))
	{
		free(uid);
		enomem();
	}
}
Beispiel #18
0
void new_VertexPointer( GLint size, GLenum type,
                        GLsizei stride, const GLvoid *ptr )
{
    if (size != 3) {
        printf("!!! unsupported new_VertexPointer() size %d\n", size);
        return;
    }
    if ( (type != GL_FLOAT) &&
            (type != GL_SHORT) )
    {
        printf("!!! unsupported new_VertexPointer() type %d\n", type);
        return;
    }

    struct vertexpointer_t * p = vertexpointer;

    if (!p) {
        p = malloc(sizeof(*p));
        all_vertexpointer = p;
    } else {
        p->next = malloc(sizeof(*p));
        p = p->next;
    }
    if (!p) enomem();
    p->next = NULL;

    p->size   = size;
    p->type   = type;
    p->ptr    = ptr;
    p->stride = stride;

    p->max_index = 0;

    p->sizeof_type = 0;
    switch (type) {
    case GL_SHORT:
        p->sizeof_type = 2;
        break;
    case GL_INT:
        p->sizeof_type = 4;
        break;
    case GL_FLOAT:
        p->sizeof_type = 4;
        break;
    case GL_DOUBLE:
        p->sizeof_type = 8;
        break;
    default:
        printf("!!! ERROR: unknown type %d in glVertexPointer()\n", type);
        exit(1);
    }

    vertexpointer = p;
    /* a stride of 0 means tightly packed, we prefer a correct stride value */
    if (p->stride == 0) {
        p->stride = p->sizeof_type * p->size;
    }
}
Beispiel #19
0
void write_sqconfig(const char *dir, const char *configfile, const char *val)
{
	char *p=malloc(strlen(dir) + strlen(configfile) + 2);

	struct maildir_tmpcreate_info createInfo;
	FILE *fp;

	if (!p)	enomem();

	strcat(strcat(strcpy(p, dir), "/"), configfile);
	if (!val)
	{
		unlink(p);
		free(p);
		return;
	}

	maildir_tmpcreate_init(&createInfo);

	createInfo.maildir=dir;
	createInfo.uniq="config";
	createInfo.doordie=1;

	fp=maildir_tmpcreate_fp(&createInfo);

	if (!fp)
		enomem();


	free(createInfo.newname);
	createInfo.newname=p;

	fprintf(fp, "%s\n", val);
	fflush(fp);
	if (ferror(fp))	eio("Error after write:",p);
	fclose(fp);

	/* Note - umask should already turn off the 077 bits, but
	** just in case someone screwed up previously, I'll fix it
	** myself */

	chmod(createInfo.tmpname, 0600);
	rename(createInfo.tmpname, createInfo.newname);
	maildir_tmpcreate_free(&createInfo);
}
Beispiel #20
0
/*
 * emalloc --
 *	malloc, but die on error.
 */
char *
emalloc(u_int len)
{
	char *p;

	if (!(p = (char *)malloc(len)))
		enomem();
	return(p);
}
Beispiel #21
0
/*
 * ecalloc --
 *	calloc, but die on error.
 */
void *
ecalloc(size_t nmemb, size_t size)
{
	void	*ptr;

	if ((ptr = calloc(nmemb, size)) == NULL)
		enomem();
	return(ptr);
}
Beispiel #22
0
/*
 * estrdup --
 *	strdup, but die on error.
 */
char *
estrdup(const char *str)
{
	char *p;

	if ((p = strdup(str)) == NULL)
		enomem();
	return (p);
}
Beispiel #23
0
/*
 * emalloc --
 *	malloc, but die on error.
 */
void *
emalloc(size_t len)
{
	void *p;

	if ((p = malloc(len)) == NULL)
		enomem();
	return (p);
}
Beispiel #24
0
void pref_setfrom(const char *p)
{
	if (pref_from)	free(pref_from);
	// by lfan
	// pref_from=strdup(p);
	pref_from = malloc(256);
	if (!pref_from)	enomem();
	sprintf(pref_from, "\"%s\" <%s>", p, login_returnaddr());
	pref_update();
}
Beispiel #25
0
void pref_setldap(const char *p)
{
	if (pref_ldap && strcmp(p, pref_ldap) == 0)
		return;

	if (pref_ldap)	free(pref_ldap);
	pref_ldap=strdup(p);
	if (!pref_ldap)	enomem();
	pref_update();
}
Beispiel #26
0
/*
 * bmake_strdup --
 *	strdup, but die on error.
 */
char *
bmake_strdup(const char *str)
{
	size_t len;
	char *p;

	len = strlen(str) + 1;
	if ((p = malloc(len)) == NULL)
		enomem();
	return memcpy(p, str, len);
}
Beispiel #27
0
static char *spellreplace(const char *word)
{
char	*p, *q, *r;
const char *c=cgi("globreplace");

	p=malloc(strlen(c)+1);
	if (!p)	enomem();
	strcpy(p, c);
	for (q=p; (q=strtok(q, ":")) != 0 && (r=strtok(0, ":")) != 0; q=0)
	{
		if (strcmp(q, word) == 0)
		{
			q=malloc(strlen(r)+1);
			if (!q)	enomem();
			strcpy(q, r);
			free(p);
			return (q);
		}
	}
	free(p);
	return (0);
}
Beispiel #28
0
rt_public EIF_POINTER rout_obj_new_args (EIF_INTEGER count)

{
	EIF_POINTER result = (EIF_POINTER) 0;

	if (count > 0) {
		result = (EIF_POINTER) eif_malloc (count * sizeof (EIF_VALUE));
		if (result == (EIF_POINTER) 0)
			enomem();
	}

	return result;
}
Beispiel #29
0
void newmsg_showfp(FILE *fp, int *attachcnt)
{
	struct	rfc2045 *p=rfc2045_fromfp(fp), *q;

	if (!p)	enomem();

	/* Here's a nice opportunity to count all attachments */

	*attachcnt=0;

	for (q=p->firstpart; q; q=q->next)
		if (!q->isdummy)	++*attachcnt;
	if (*attachcnt)	--*attachcnt;
	/* Not counting the 1st MIME part */

	{
		const char *content_type;
		const char *content_transfer_encoding;
		const char *charset;

		rfc2045_mimeinfo(p, &content_type,
				 &content_transfer_encoding, &charset);

		if (content_type &&
		    strcmp(content_type, "multipart/alternative") == 0)
			*attachcnt=0;
	}

	q=rfc2045_searchcontenttype(p, "text/plain");

	if (q)
	{
		struct rfc2045src *src=rfc2045src_init_fd(fileno(fp));

		if (src)
		{
			struct show_textarea_info info;

			show_textarea_init(&info, 1);

			rfc2045_decodetextmimesection(src, q,
						      sqwebmail_content_charset,
						      NULL,
						      &show_textarea_trampoline,
						      &info);
			rfc2045src_deinit(src);
			show_textarea(&info, "\n", 1);
		}
	}
	rfc2045_free(p);
}
Beispiel #30
0
char	*cgi_cookie(const char *p)
{
    size_t	pl=strlen(p);
    const char *c=getenv("HTTP_COOKIE");
    char	*buf;

    while (c && *c)
    {
        size_t	i;

        for (i=0; c[i] && c[i] != '='; i++)
            ;
        if (i == pl && strncmp(p, c, i) == 0)
        {
            c += i;
            if (*c)	++c;	/* skip over = */
            for (i=0; c[i] && c[i] != ';'; i++)
                ;

            buf=malloc(i+1);
            if (!buf)	enomem();
            memcpy(buf, c, i);
            buf[i]=0;
            cgiurldecode(buf);
            return (buf);
        }
        c=strchr(c, ';');
        if (c)
            do
            {
                ++c;
            } while (isspace((int)(unsigned char)*c));
    }
    buf=malloc(1);
    if (!buf)	enomem();
    *buf=0;
    return (buf);
}