Lines Matching defs:css

84 drop(Css_t* css, register Cspoll_t* pp)
90 if (!css)
91 css = state.main;
94 if (ip->css == css)
98 if (css->auth)
103 if ((*ip->actionf)(css, ip, css->disc) > 0)
111 css->fdpolling--;
113 css->fdlistening--;
115 css->fduser--;
128 register Css_t* css;
148 if (!(css = newof(0, Css_t, 1, sizeof(Cssdisc_t))))
150 css->id = cs.id;
151 css->disc = (Cssdisc_t*)(css + 1);
152 css->disc->version = CSS_VERSION;
153 state.servers = state.main = css;
158 if (!(css = newof(0, Css_t, 1, n)))
161 css->next = state.servers;
162 state.servers = css;
163 if (!(css->state = csalloc(NiL)))
165 css->service = (char*)(css + 1);
166 css->path = css->service + n;
167 css->id = state.main->id;
168 css->disc = disc;
169 css->fdmax = state.fdmax;
172 strcpy(css->path, path);
173 if (tokscan(css->path, NiL, "/dev/%s/%s/%s", &s, NiL, &t) != 3)
175 if (css->disc->errorf)
176 (*css->disc->errorf)(css, css->disc, 3, "%s: invalid connect stream path", path);
182 strncpy(css->service, t, n);
184 if ((css->fd = csopen(css->state, path, CS_OPEN_CREATE)) < 0)
186 if (css->disc->errorf)
189 (*css->disc->errorf)(css, css->disc, 3, "%s: server already running", path);
191 (*css->disc->errorf)(css, css->disc, ERROR_SYSTEM|3, "%s: cannot create connect stream", path);
195 css->disc->flags &= ~CSS_AUTHENTICATE;
199 sfsprintf(css->service, n, "/dev/fdp/local/%s", path);
200 path = (char*)cspath(css->state, 0, 0);
202 css->perm = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH;
203 if ((css->disc->flags & CSS_AUTHENTICATE) && csopen(css->state, css->service, CS_OPEN_CREATE|CS_OPEN_MOUNT))
205 if (css->disc->errorf)
206 (*css->disc->errorf)(css, css->disc, ERROR_SYSTEM|3, "%s: cannot create authentication directory", css->service);
210 strcpy(css->path, path);
211 if ((css->disc->flags & CSS_DAEMON) && csdaemon(css->state, (css->disc->flags & CSS_PRESERVE) ? ~0L : ((1<<css->fd)|(1<<2))))
213 if (css->disc->errorf)
214 (*css->disc->errorf)(css, css->disc, 3, "cannot dive into background");
217 if (css->state->control)
219 strcpy(css->mount, css->state->mount);
220 css->control = strrchr(css->mount, '/') + 1;
221 strcpy(css->control + 1, CS_MNT_TAIL);
222 s = css->control - 1;
224 if (stat(css->mount, &st))
226 if (css->disc->errorf)
227 (*css->disc->errorf)(css, css->disc, 3, "%s: cannot stat service directory", css->mount);
230 if ((css->disc->flags & CSS_DAEMON) && chdir(css->mount))
232 if (css->disc->errorf)
233 (*css->disc->errorf)(css, css->disc, 3, "%s: cannot set service directory", css->mount);
247 while (s > css->mount)
252 if (css->disc->errorf)
253 (*css->disc->errorf)(css, css->disc, 3, "%s: invalid mount directory", css->mount);
257 if (lstat(css->mount, &st))
259 if (css->disc->errorf)
260 (*css->disc->errorf)(css, css->disc, 3, "%s: invalid global authentication directory", css->mount);
264 css->fid[0].dev = st.st_dev;
265 css->fid[0].ino = st.st_ino;
266 s = csvar(css->state, CS_VAR_LOCAL, 0);
269 if (css->disc->errorf)
270 (*css->disc->errorf)(css, css->disc, 3, "%s: invalid local authentication directory", s);
273 css->fid[1].dev = st.st_dev;
274 css->fid[1].ino = st.st_ino;
275 css->uid = st.st_uid;
276 css->gid = st.st_gid;
277 if (type == 't' && *(css->control - 2) != CS_MNT_OTHER && *(css->control - 2) != '.' && *(css->control - 2) != '*')
279 css->auth = 1;
283 css->conkey = state.pid + getppid() + css->uid + st.st_ino;
284 TOSS(css->conkey);
285 *css->control = CS_MNT_AUTH;
286 remove(css->mount);
287 css->newkey = css->conkey & KEYMASK;
288 if (close(open(css->mount, O_WRONLY|O_CREAT|O_TRUNC, st.st_mode & (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH))) ||
289 chmod(css->mount, st.st_mode & (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) ||
290 cschallenge(css->state, css->mount, NiL, &css->newkey))
292 if (css->disc->errorf)
293 (*css->disc->errorf)(css, css->disc, 3, "%s: cannot create service authentication file", css->mount);
296 chown(css->mount, -1, css->gid);
297 css->oldkey = css->newkey;
298 for (n = 0; n < (css->newkey & 0xff); n++)
299 CSTOSS(css->conkey, n);
300 css->challenge = (st.st_mode & S_IXOTH) ? 2 : 0;
302 *css->control = CS_MNT_PROCESS;
303 remove(css->mount);
304 s = css->buf;
305 if (type != 'f') s += sfsprintf(s, sizeof(css->buf) - (s - css->buf), "/n/%s", csname(css->state, 0));
306 sfsprintf(s, sizeof(css->buf) - (s - css->buf), "/proc/%d", getpid());
307 pathsetlink(css->buf, css->mount);
308 if (css->disc->flags & CSS_LOG)
310 *css->control = CS_MNT_OLDLOG;
311 strcpy(css->buf, css->mount);
312 *css->control = CS_MNT_LOG;
313 rename(css->mount, css->buf);
315 open(css->mount, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
317 *css->control = CS_MNT_AUTH;
318 css->perm = st.st_mode & (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
319 if (css->disc->flags & CSS_DAEMON)
320 umask(~css->perm & (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH));
322 if ((css->disc->flags & CSS_INTERRUPT) && !(state.flags & CSS_INTERRUPT))
329 cssfd(css, css->fd, type == 'u' ? CS_POLL_READ : (CS_POLL_AUTH|CS_POLL_CONNECT|CS_POLL_READ));
331 return css;
333 cssclose(css);
342 cssclose(register Css_t* css)
362 if (xss == css || !css)
365 (*xss->disc->exceptf)(css, CSS_CLOSE, 0, xss->disc);
370 if (state.fdinfo[state.fdpoll[i].fd].css == xss)
394 if (css)
403 if (css)
426 cssfd(register Css_t* css, register int fd, unsigned long op)
439 if (!css)
440 css = state.main;
459 if (!css->auth)
484 ip->css = css;
486 ip->actionf = css->disc->actionf;
490 css->fdpolling++;
494 css->fdlistening++;
496 css->fduser++;
508 if (ip->css != css)
510 if (css->fd != fd)
515 css->fdlistening--;
517 css->fduser--;
522 css->fdlistening++;
524 css->fduser++;
545 css = ip->css;
553 if (fd == css->fd)
554 css->fd = nfd;
575 else if (css->fd != fd)
580 drop(state.fdinfo[fd].css, &state.fdpoll[n]);
601 register Css_t* css;
649 for (css = state.servers; css; css = css->next)
650 if (css->auth)
652 css->oldkey = css->newkey;
654 do TOSS(css->newkey); while (n--);
655 css->newkey &= KEYMASK;
656 *css->control = CS_MNT_AUTH;
657 if (cschallenge(css->state, css->mount, NiL, &css->newkey))
658 css->newkey = css->oldkey;
664 drop(state.fdinfo[pp->fd].css, pp);
670 for (css = state.servers; css; css = css->next)
672 css->fdpending = 0;
673 if (css->disc->timeout)
675 if (css->timeout_last != css->disc->timeout)
676 css->timeout_last = css->timeout_remain = css->disc->timeout;
677 if (to > css->timeout_remain)
678 to = css->timeout_remain;
680 if (css->disc->wakeup)
682 if (css->wakeup_last != css->disc->wakeup)
683 css->wakeup_last = css->wakeup_remain = css->disc->wakeup;
684 if (to > css->wakeup_remain)
685 to = css->wakeup_remain;
695 if (ip->actionf && (*ip->actionf)(ip->css, ip, ip->css->disc) < 0)
697 drop(ip->css, pp);
732 state.fdinfo[pp->fd].css->fdpending++;
733 for (css = state.servers; css; css = css->next)
734 if (css->disc->exceptf)
736 if (css->disc->timeout)
738 if (css->fdpending)
739 css->timeout_remain = css->disc->timeout;
740 else if (css->timeout_remain <= z)
742 if ((css->disc->flags & CSS_DORMANT) && css->fdpolling <= (css->fdlistening + css->fduser))
743 (*css->disc->exceptf)(css, CSS_DORMANT, 0, css->disc);
744 else if (css->disc->flags & CSS_TIMEOUT)
745 (*css->disc->exceptf)(css, CSS_TIMEOUT, 0, css->disc);
746 css->timeout_last = css->timeout_remain = css->disc->timeout;
749 css->timeout_remain -= z;
751 if (css->disc->wakeup)
753 messagef((state.main->id, NiL, -4, "csspoll: pending=%d polling=%d z=%I*d wakeup=%I*d remain=%I*d", state.fdpending, state.fdpolling, sizeof(z), z, sizeof(css->disc->wakeup), css->disc->wakeup, sizeof(css->wakeup_remain), css->wakeup_remain));
754 if (css->wakeup_remain <= z)
756 (*css->disc->exceptf)(css, CSS_WAKEUP, 0, css->disc);
757 css->wakeup_last = css->wakeup_remain = css->disc->wakeup;
760 css->wakeup_remain -= z;
764 if ((css->disc->flags & CSS_INTERRUPT) && (sig || err == EINTR))
768 else if ((*css->disc->exceptf)(css, CSS_INTERRUPT, sig, css->disc) >= 0)
771 else if (css->disc->flags & CSS_ERROR)
773 if ((*css->disc->exceptf)(css, CSS_ERROR, err, css->disc) >= 0)
797 css = ip->css;
803 if (css->auth)
805 if (csrecv(css->state, fd, &id, &fdnew, 1) == 1)
808 cssfd(css, fdnew, CS_POLL_AUTH|CS_POLL_READ);
814 if (csrecv(css->state, fd, &id, &fdnew, 1) == 1 &&
815 (ip = cssfd(css, fdnew, CS_POLL_READ)) &&
816 css->disc->acceptf &&
817 (fdnew = (*css->disc->acceptf)(css, ip, &id, NiL, css->disc)) != ip->fd)
818 cssfd(css, ip->fd, fdnew >= 0 ? CS_POLL_CMD(fdnew, CS_POLL_MOVE) : CS_POLL_CLOSE);
824 if ((n = csread(css->state, fd, css->buf, sizeof(css->buf), CS_LINE)) <= 0)
826 css->buf[n - 1] = 0;
827 if (tokscan(css->buf, &t, "%lu", &key) != 1)
832 n = sfsprintf(css->tmp, sizeof(css->tmp), "%s\n", css->mount);
833 if (cswrite(css->state, fd, css->tmp, n) != n)
837 if (key <= CS_KEY_MAX || key != css->newkey && key != css->oldkey || tokscan(t, NiL, "%ld", &ap->id.pid) != 1)
839 if (!(ap->seq = css->challenge))
841 st.st_uid = css->uid;
842 st.st_gid = css->gid;
845 css->conkey ^= cs.time ^ ap->id.pid;
847 do TOSS(css->conkey); while (n--);
848 ap->atime = css->conkey & KEYMASK;
850 do TOSS(css->conkey); while (n--);
851 ap->mtime = css->conkey & KEYMASK;
852 n = sfsprintf(css->tmp, sizeof(css->tmp), "%lu %lu\n", (unsigned long)ap->atime, (unsigned long)ap->mtime);
853 if (cswrite(css->state, fd, css->tmp, n) != n)
861 if (cs.time > ap->expire || (n = csread(css->state, fd, css->buf, sizeof(css->buf), CS_LINE)) <= 1)
863 css->buf[n - 1] = 0;
864 if (t = strchr(css->buf, ' '))
866 if (!(s = strrchr(css->buf, '/')))
869 if (lstat(css->buf, &st))
872 for (n = 0; n < elementsof(css->fid); n++)
874 if (css->fid[n].dev == st.st_dev)
876 if (css->fid[n].dev == st.st_dev && css->fid[n].ino == st.st_ino)
879 if (n >= elementsof(css->fid))
881 if (lstat(css->buf, &st))
887 if (!(s = strrchr(css->buf, '.')))
890 close(open(css->buf, O_WRONLY|O_CREAT|O_TRUNC, 0));
891 remove(css->buf);
893 if (lstat(css->buf, &st))
901 if (cswrite(css->state, fd, "\n", 1) != 1)
904 if (css->disc->acceptf)
914 if ((fdnew = (*css->disc->acceptf)(css, ip, &ap->id, *va ? va : (char**)0, css->disc)) != ip->fd)
915 cssfd(css, ip->fd, fdnew >= 0 ? CS_POLL_CMD(fdnew, CS_POLL_MOVE) : CS_POLL_CLOSE);
929 if (!ip->actionf || (n = (*ip->actionf)(css, ip, css->disc)) == 0)
946 drop(css, pp);