|
|
1.1 root 1: #include "ipc.h"
2:
3: /*
4: * Read the connection info. If an error occurs, ip->reply and ip->conn are
5: * closed.
6: */
7: int
8: _info_read(fd, ip)
9: int fd;
10: ipcinfo *ip;
11: {
12: static char b[BUFLEN];
13: char *f[8];
14: int n;
15:
16: n=read(fd, b, sizeof(b));
17: if (n <= 0)
18: return _ipcabort(errno, "error reading request", ip);
19: b[n] = '\0';
20: setfields("\n");
21: if (getfields(b, f, 8)!=8)
22: return _ipcabort(EINVAL, "protocol botch", ip);
23: ip->myname = f[0];
24: ip->name = f[1];
25: ip->param = f[2];
26: ip->machine = f[3];
27: ip->flags = atoi(f[5]);
28:
29: /* supply a system name */
30: if (ip->uid!=ROOTUID || ip->machine[0]=='\0')
31: ip->machine = "";
32:
33: /* supply a user name */
34: if (ip->uid==ROOTUID && *(f[4])!='\0')
35: ip->user = f[4];
36:
37: /* supply uid/gid cruft */
38: if (ip->uid==ROOTUID && atoi(f[6])!=-1) {
39: ip->uid = atoi(f[6]);
40: ip->gid = atoi(f[7]);
41: }
42: return 0;
43: }
44:
45: /*
46: * Send a reply to a connection request
47: */
48: _reply_write(fd, no, str)
49: int fd;
50: int no;
51: char *str;
52: {
53: char b[BUFLEN];
54: int n;
55:
56: if (str==NULL)
57: str = "";
58: sprintf(b, "%d\n%s\n", no, str);
59: n = strlen(b);
60: if (write(fd, b, n)!=n)
61: return -1;
62: return 0;
63: }
64:
65: /*
66: * Get a reply to a connection request.
67: */
68: int
69: _reply_read(fd)
70: int fd;
71: {
72: static char b[BUFLEN];
73: char *f[2];
74: char *ptr;
75: int n;
76:
77: while((n=read(fd, b, sizeof(b)))<0 && errno==EINTR)
78: ;
79: if (n <= 0)
80: return _ipcabort(errno, "error reading request", NULLINFO);
81: b[n] = '\0';
82: parselines(b, f, 2);
83: errno = atoi(f[0]);
84: if ((ptr=strchr(f[1], '\n'))!=NULL)
85: *ptr = '\0';
86: if (errno!=0)
87: errstr = f[1];
88: else
89: ipcname = f[1];
90: return 0;
91: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.