summaryrefslogtreecommitdiff
path: root/sys/src/cmd/auth/secstore/util.c
blob: 409681e317f590e1d4aaf00c09ad98f0c6bd7d18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <u.h>
#include <libc.h>
#include <mp.h>
#include <libsec.h>
#include "SConn.h"
#include "secstore.h"

void *
emalloc(ulong n)
{
	void *p = malloc(n);

	if(p == nil)
		sysfatal("emalloc");
	memset(p, 0, n);
	return p;
}

void *
erealloc(void *p, ulong n)
{
	if ((p = realloc(p, n)) == nil)
		sysfatal("erealloc");
	return p;
}

char *
estrdup(char *s)
{
	if ((s = strdup(s)) == nil)
		sysfatal("estrdup");
	return s;
}

static char *
illegal(char *f)
{
	syslog(0, LOG, "illegal name: %s", f);
	return nil;
}

char *
validatefile(char *f)
{
	char *p;

	if(f == nil || *f == '\0')
		return nil;
	if(strcmp(f, "..") == 0 || strlen(f) >= 250)
		return illegal(f);
	for(p = f; *p; p++)
		if(*p < 040 || *p == '/')
			return illegal(f);
	return f;
}