-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdxl.c
79 lines (66 loc) · 1.74 KB
/
dxl.c
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* $Id$ */
#include <stdlib.h>
#include "dxl.h"
char *dxl_cmd=NULL;
#if DXL_EXC
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <errno.h>
#include <assert.h>
#include "m.h"
#include "er.h"
int dxl_allows(char *typ,char *ps,char *s,int n) {
int pid,status;
if(!dxl_cmd) return 0;
if((pid=fork())==0) {
char **argv; int argc;
char *p; int arg, i;
argc=5; p=ps; arg=0;
for(;;) {
if(*p=='\0') {
if(arg) {arg=0; ++argc;} else break;
} else arg=1;
++p;
}
argv=(char**)m_alloc(argc,sizeof(char*));
argv[--argc]=NULL;
argv[--argc]=(char*)m_alloc(n+1,sizeof(char)); argv[argc][n]='\0'; strncpy(argv[argc],s,n);
argv[0]=dxl_cmd; argv[1]="allows"; argv[2]=typ;
i=3; if(i<argc) {
for(;;) {
argv[i++]=ps;
if(i==argc) break;
while(*(ps++));
}
}
execv(dxl_cmd,argv);
(*er_printf)("dxl: cannot execute %s: %s\n",dxl_cmd,strerror(errno));
} else if(pid>0) {
wait(&status);
return !WEXITSTATUS(status);
}
(*er_printf)("dxl: %s\n",strerror(errno));
return 0;
}
int dxl_equal(char *typ,char *val,char *s,int n) {
int pid,status;
if(!dxl_cmd) return 0;
if((pid=fork())==0) {
char *argv[]={NULL,"equal",NULL,NULL,NULL,NULL};
argv[0]=dxl_cmd; argv[2]=typ; argv[3]=val;
argv[4]=(char*)m_alloc(n+1,sizeof(char)); argv[4][n]='\0'; strncpy(argv[4],s,n);
execvp(dxl_cmd,argv);
(*er_printf)("dxl: cannot execute %s\n",dxl_cmd,strerror(errno));
} else if(pid>0) {
wait(&status);
return !WEXITSTATUS(status);
}
(*er_printf)("dxl: %s\n",strerror(errno));
return 0;
}
#else
int dxl_allows(char *typ,char *ps,char *s,int n) {return 0;}
int dxl_equal(char *typ,char *val,char *s,int n) {return 0;}
#endif