int do_burst_ts6(int count, time_t now) { int i; char nick[20]; printf("PASS linkit TS 6 :%s\r\n", SID); printf("CAPAB :QS EX IE KLN UNKLN ENCAP TB SERVICES EUID EOPMOD MLOCK\r\n"); printf("SERVER irc.uplink.com 1 :Test file\r\n"); printf("SVINFO 6 3 0 :%lu\r\n", (unsigned long) now); for (i = 0; i < count; i++) { snprintf(nick, sizeof nick, "a%010d", i); printf(":%s UID %s 1 %lu +i ~Guest moo.cows.go.moo 0 %s :Grazing cow #%ld\r\n", SID, nick, (unsigned long) now, uid_get(), i); } printf(":%s PONG %s :%s\r\n", SID, SID, SID); return 0; }
int init_post(void) { uid_t ui; gid_t gi; struct mydir const *md = &dirs[0]; mastr *l = mastr_new(LN_PATH_MAX); mastr_vcat(l, spooldir, "/leaf.node/lock.file", NULL); lockfile=critstrdup(mastr_str(l), "init_post"); mastr_delete(l); if (!localgroups) { l = mastr_new(LN_PATH_MAX); mastr_vcat(l, sysconfdir, "/local.groups", NULL); localgroups=critstrdup(mastr_str(l), "init_post"); mastr_delete(l); } if (uid_getbyuname(RUNAS_USER, &ui)) { ln_log(LNLOG_SERR, LNLOG_CTOP, "cannot uid_getbyuname(%s,&ui): %m\n", RUNAS_USER); return FALSE; } if (ui == (uid_t)0) { ln_log(LNLOG_SERR, LNLOG_CTOP, "cannot run leafnode with user %s that has uid #0!\n", RUNAS_USER); return FALSE; } if (gid_getbyuname(RUNAS_USER, &gi)) { ln_log(LNLOG_SERR, LNLOG_CTOP, "cannot gid_getbyuname(%s,&gi): %m\n", RUNAS_USER); return FALSE; } if (gi == (gid_t)0) { ln_log(LNLOG_SERR, LNLOG_CTOP, "cannot run leafnode with user %s that has gid #0!\n", RUNAS_USER); return FALSE; } { struct stat lnst; mastr *x = mastr_new(LN_PATH_MAX); mastr_vcat(x, spooldir, "/leaf.node", NULL); if (lstat(mastr_str(x), &lnst)) { ln_log(LNLOG_SERR, LNLOG_CTOP, "cannot open %s - is your --enable-spooldir matching your installation?", mastr_str(x)); mastr_delete(x); return FALSE; } mastr_delete(x); } /* These directories should exist anyway */ while (md->name) { mastr *x = mastr_new(LN_PATH_MAX); mastr_vcat(x, spooldir, "/", md->name, NULL); if (mkdir(mastr_str(x), (mode_t) 0110)) { if (errno != EEXIST) { ln_log(LNLOG_SERR, LNLOG_CTOP, "cannot mkdir(%s): %m\n", mastr_str(x)); mastr_delete(x); return FALSE; } } else { if (chown(mastr_str(x), ui, gi)) { /* Flawfinder: ignore */ if (uid_get() == 0) { ln_log(LNLOG_SERR, LNLOG_CTOP, "cannot chown(%s,%ld,%ld): %m\n", mastr_str(x), (long)ui, (long)gi); mastr_delete(x); return FALSE; } else { ln_log(LNLOG_SWARNING, LNLOG_CTOP, "cannot chown(%s,%ld,%ld): %m\n", mastr_str(x), (long)ui, (long)gi); } } if (log_chmod(mastr_str(x), md->m)) { ln_log(LNLOG_SERR, LNLOG_CTOP, "cannot chmod(%s,%o): %m\n", mastr_str(x), (unsigned int)md->m); mastr_delete(x); return FALSE; } } md++; mastr_delete(x); } if (gid_get() == 0 && gid_ensure(gi)) { ln_log(LNLOG_SERR, LNLOG_CTOP, "cannot ensure gid %ld: %m\n", (long)gi); return FALSE; } if (uid_get() == 0 && uid_ensure(ui)) { ln_log(LNLOG_SERR, LNLOG_CTOP, "cannot ensure uid %ld: %m\n", (long)ui); return FALSE; } if (chdir(spooldir)) { ln_log(LNLOG_SERR, LNLOG_CTOP, "cannot change to spooldir %s: %m\n", spooldir); return FALSE; } return TRUE; }