int main() { char* eggsbody; if (system("shuttingUp") == 0) { return 0; } eggsbody = getenv("EGGS_BODY"); eggsuser = getenv("EGGS_USER"); now = time(NULL); srand(now); if (eggsbody != NULL && eggsuser != NULL) { struct stat fs; eggsuserlength = strlen(eggsuser); snprintf(buf, sizeof(buf), "%s/links", getenv("CONCIEGGS_DB_DIR")); linksfd = open(buf, O_RDWR | O_APPEND | O_CREAT); fstat(linksfd, &fs); linkslength = fs.st_size; links = mmap(NULL, linkslength, PROT_WRITE | PROT_READ, MAP_PRIVATE, linksfd, 0); while (1) { char* start, *end; int atend; start = strstr(eggsbody, "http://"); if (start == NULL) { start = strstr(eggsbody, "https://"); } if (start == NULL) { return 0; } end = start; while (*end != ' ' && *end != 0) { end++; } atend = *end == 0; *end = 0; checklink(start); if (atend) { return 0; } eggsbody = end+1; } return 0; } else { return 1; } }
int unlink3d(register const char* path) { register char* sp; register int r; #if FS Mount_t* mp; if (!fscall(NiL, MSG_remove, 0, path)) return state.ret; mp = monitored(); #endif if (!(sp = pathreal(path, P_PATHONLY|P_SAFE, NiL))) return -1; if (state.path.level) return 0; if (!(r = LSTAT(sp, &state.path.st))) { if (S_ISLNK(state.path.st.st_mode) && !checklink(sp, &state.path.st, P_PATHONLY|P_LSTAT) && state.path.linksize > 0) { /* * remove instance if not default */ r = strlen(sp) - (sizeof(state.vdefault) - 1); if (r > 3 && streq(sp + r, state.vdefault)) return 0; } r = UNLINK(sp); } if (!r) { #if FS if (mp) fscall(mp, MSG_remove, 0, path); for (mp = state.global; mp; mp = mp->global) if (fssys(mp, MSG_remove)) fscall(mp, MSG_remove, 0, path); #endif } else if (errno == ENOENT && pathreal(path, 0, NiL)) r = 0; return r; }
static #endif char* pathreal(const char* apath, register int type, struct stat* st) { char* path = (char*)apath; register char* sp; register char* cp; register char* ip; Table_t* safe; int oerrno = errno; int opaqued = 0; int len; int vir; int safesize; int safe_dir; long visits; char buf[PATH_MAX + 1]; static struct stat stbuf; static struct stat tsbuf; state.path.level = state.path.synthesize = state.path.nlinks = 0; if (!path) { errno = EFAULT; return 0; } initialize(); if (state.in_2d) { if (!st || (!state.level || *path == '/') && !LSTAT(path, st)) return path; if (state.level && streq(path, ".") && !CHDIR(state.pwd)) { state.level = 0; return path; } return 0; } #if FS if (mounted() && (sp = fsreal(state.path.monitor, MSG_stat, state.path.mount))) apath = (char*)(path = sp); #endif /* * handle null path, . and / separately */ if (safe = state.safe ? &state.vsafe : (Table_t*)0) { type |= P_ABSOLUTE; if (!(safesize = state.safe->servicesize)) safesize = strlen(state.safe->service); } else type &= ~P_SAFE; again: if (!*path) { errno = ENOENT; return 0; } cp = sp = path; state.path.synthesize = state.path.linksize = 0; if (!st) st = &stbuf; /* * check if virtual dir has been created by another process * only P_PATHONLY|P_TOP calls (usually create or modify link) and * references to "." are checked for performance */ if (state.level > 0 && state.pwd && ((type & (P_PATHONLY|P_TOP)) && *sp != '/' || *sp == '.' && sp[1] == 0)) { if (!CHDIR(state.pwd)) state.level = 0; else if (!(type & (P_PATHONLY|P_TOP))) { len = 0; state.path.level += (state.path.synthesize = state.level); sp = strcpy(state.path.name, state.pwd); goto skip; } } if (!state.pwd || sp[1] == 0 && (*sp == '.' || *sp == '/' && !safe)) { if (st != &stbuf && LSTAT(sp, st)) return 0; if (*sp == '/' || !state.pwd && (type & P_PATHONLY)) strncpy(state.path.name, sp, PATH_MAX); else if (!state.pwd) { /* * treat the current directory as if were empty */ errno = ENOENT; return 0; } else strncpy(state.path.name, state.pwd, PATH_MAX); errno = oerrno; return state.path.name; } /* * put absolute pathname into state.path */ safe_dir = 0; if (*path != '/') { strcpy(state.path.name, state.pwd); sp = state.path.name + state.pwdsize; *sp++ = '/'; if (safe && state.pwdsize >= safesize && !strncmp(state.pwd, state.safe->service, safesize) && (!state.pwd[safesize] || state.pwd[safesize] == '/')) safe_dir = safesize; } else sp = state.path.name; ip = state.path.name + elementsof(state.path.name); while (sp < ip && (*sp = *cp++)) sp++; if (type & P_DOTDOT) strcpy(sp, "/.."); sp = state.path.name; if (!(ip = pathcanon(sp + safe_dir, sizeof(state.path.name) - safe_dir, 0))) { errno = ENOENT; return 0; } if (type & (P_DOTDOT|P_NOSLASH)) { /* * remove trailing slashes */ while (*--ip == '/'); *++ip = 0; } else if ((type & P_SLASH) && *(ip - 1) != '/') *ip++ = '/'; if (*(ip - 1) == '/' && ip - sp > 1) { /* * trailing slash is equivalent to trailing slash-dot * this forces the common-sense interpretation */ #if DEBUG if (!(state.test & 010)) #endif *ip++ = '.'; *ip = 0; } len = ip - sp; /* * try to use relative path */ if (!(type & (P_LSTAT|P_READLINK))) { for (ip = state.pwd; *ip && *ip == *sp++; ip++); if (*ip != 0 || *sp && *sp != '/' || state.level < 0) sp = state.path.name; else { state.path.level += (state.path.synthesize = state.level); if (state.level && !(type & P_PATHONLY) && st == &stbuf) { sp = state.path.name; len -= state.pwdsize; } else if (type & P_ABSOLUTE) sp = state.path.name; else if (*sp == '/') sp++; } if (*sp == 0) sp = state.dot; } skip: if ((type & P_NOOPAQUE) && !LSTAT(sp, st) && checkopaque(sp, st)) { message((-1, "%s: remove opaque", sp)); UNLINK(sp); opaqued = 1; } if (safe && *sp == '/') { state.path.table = safe; cp = pathnext(sp, NiL, NiL); state.path.table = safe = 0; if (cp) { state.path.level = 0; path = strcpy(buf, sp); message((-5, "pathreal: == safe map %s", path)); type &= ~(P_DOTDOT|P_SAFE); goto again; } if (!*(sp + 1)) { strncpy(sp, state.safe->service, safesize); sp[safesize] = 0; } else if (strncmp(sp, state.safe->service, safesize) || sp[safesize] && sp[safesize] != '/') { if (*path != '/' && safe_dir) { errno = EPERM; return 0; } if (sp[1]) strcpy(buf, sp); else *buf = 0; len = sfsprintf(sp, sizeof(state.path.name), "%-*s%s", safesize, state.safe->service, buf); message((-5, "pathreal: == safe next %s", sp)); if (!pathnext(sp, NiL, NiL)) { errno = EPERM; return 0; } } else type &= ~P_SAFE; } if ((type & P_SAFE) && state.path.level) { errno = EPERM; return 0; } if (type & P_PATHONLY) { errno = oerrno; return sp; } visits = 0; vir = 1; while (LSTAT(sp, st)) { if (vir) { if (apath[0] == '.' && apath[1] == '.' && apath[2] == '.' && !apath[3]) { if (state.level > 0) { message((-1, "pathreal: %s => %s", apath, sp)); LSTAT(".", st); return sp; } errno = ENOENT; return 0; } vir = 0; } if (errno == ENOTDIR) { /* * check for version instance */ cp = ip = sp + strlen(sp); while (ip > sp && *--ip != '/'); if (ip < sp) return 0; while (ip > sp && *--ip == '/'); if (ip < sp) return 0; while (ip > sp && *--ip != '/'); if (*ip == '/') ip++; while (cp >= ip) { cp[4] = *cp; cp--; } memcpy(ip, state.opaque, 4); if (!LSTAT(sp, st)) break; errno = ENOTDIR; return 0; } if (errno != ENOENT || opaqued) return 0; #if FS /* * check user mount */ if (visits) { Mount_t* mp; const char* up; if ((mp = getmount(sp, &up)) && (mp->fs->flags & FS_NAME) && (sp = fsreal(mp, MSG_open, (char*)up)) && !LSTAT(sp, st)) break; } #endif /* * search down the viewpath */ if (type & P_SAFE) { errno = EPERM; return 0; } if (!pathnext(state.path.name, NiL, &visits)) return 0; sp = state.path.name; if (!(type & P_ABSOLUTE)) { /* * try to use relative path */ for (ip = state.pwd; *ip && *ip == *sp++; ip++); if (*ip == 0 && *sp == '/') sp++; else sp = state.path.name; } if (*sp == 0) sp = state.dot; } if (st->st_nlink > 1 && checkopaque(sp, st)) return 0; if ((type & P_TOP) && state.path.level) { int rfd; int wfd; if ((rfd = OPEN(sp, O_RDONLY, 0)) < 0) sp = 0; else { tsbuf = *st; wfd = open(apath, O_WRONLY|O_CREAT|O_TRUNC|O_cloexec, st->st_mode & S_IPERM); *st = tsbuf; if (wfd < 0) sp = 0; else { if (fs3d_copy(rfd, wfd, st)) sp = 0; CLOSE(wfd); } CLOSE(rfd); } if (!sp) { errno = EROFS; return 0; } if (st == &stbuf) st = 0; return pathreal(apath, P_PATHONLY, st); } IVIEW(st, state.path.level); if (state.path.synthesize) { if (state.path.level < state.level) { if (len) { ip = state.path.name + strlen(state.path.name) - len; len = *ip; *ip = 0; } if (!CHDIR(state.path.name)) state.level = state.path.level; message((-1, "chdir=%s level=%d", state.path.name, state.level)); *ip = len; } else if (S_ISDIR(st->st_mode)) { int mask; static int uid = -1; static int gid; umask(mask = umask(0)); st->st_mode = (st->st_mode | (S_IRWXU|S_IRWXG|S_IRWXO)) & ~(mask & (S_IRWXU|S_IRWXG|S_IRWXO)); if (uid == -1) { uid = geteuid(); gid = getegid(); } st->st_uid = uid; st->st_gid = gid; } } ip = sp; /* * symbolic links handled specially * get filename from pathname */ if (S_ISLNK(st->st_mode) && (len = checklink(sp, st, type)) > 1 && !(type & (P_LSTAT|P_READLINK)) && state.path.nlinks++ < MAXSYMLINKS) { path = strcpy(buf, state.path.name); message((-1, "pathreal: == again %s", path)); if (*path != '/') state.path.level = 0; type &= ~(P_DOTDOT|P_SAFE); goto again; } #if VCS && defined(VCS_REAL) VCS_REAL(state.path.name, st); #endif errno = oerrno; return sp; }