void BListView::MessageReceived(BMessage* message) { switch (message->what) { case B_COUNT_PROPERTIES: case B_EXECUTE_PROPERTY: case B_GET_PROPERTY: case B_SET_PROPERTY: { BPropertyInfo propInfo(sProperties); BMessage specifier; const char *property; if (message->GetCurrentSpecifier(NULL, &specifier) != B_OK || specifier.FindString("property", &property) != B_OK) return; switch (propInfo.FindMatch(message, 0, &specifier, message->what, property)) { case B_ERROR: BView::MessageReceived(message); break; case 0: { BMessage reply(B_REPLY); reply.AddInt32("result", CountItems()); reply.AddInt32("error", B_OK); message->SendReply(&reply); break; } case 1: break; case 2: { int32 count = 0; for (int32 i = 0; i < CountItems(); i++) { if (ItemAt(i)->IsSelected()) count++; } BMessage reply(B_REPLY); reply.AddInt32("result", count); reply.AddInt32("error", B_OK); message->SendReply(&reply); break; } case 3: break; case 4: { BMessage reply (B_REPLY); for (int32 i = 0; i < CountItems(); i++) { if (ItemAt(i)->IsSelected()) reply.AddInt32("result", i); } reply.AddInt32("error", B_OK); message->SendReply(&reply); break; } case 5: break; case 6: { BMessage reply(B_REPLY); bool select; if (message->FindBool("data", &select) == B_OK && select) Select(0, CountItems() - 1, false); else DeselectAll(); reply.AddInt32("error", B_OK); message->SendReply(&reply); break; } } break; } case B_SELECT_ALL: if (fListType == B_MULTIPLE_SELECTION_LIST) Select(0, CountItems() - 1, false); break; default: BView::MessageReceived(message); } }
pass2() { register DINODE *dp; struct inodesc rootdesc; bzero((char *)&rootdesc, sizeof(struct inodesc)); rootdesc.id_type = ADDR; rootdesc.id_func = pass2check; rootdesc.id_number = ROOTINO; pathp = pathname; switch (statemap[ROOTINO]) { case USTATE: pfatal("ROOT INODE UNALLOCATED"); if (reply("ALLOCATE") == 0) errexit(""); if (allocdir(ROOTINO, ROOTINO) != ROOTINO) errexit("CANNOT ALLOCATE ROOT INODE\n"); descend(&rootdesc, ROOTINO); break; case DCLEAR: pfatal("DUPS/BAD IN ROOT INODE"); if (reply("REALLOCATE")) { freeino(ROOTINO); if (allocdir(ROOTINO, ROOTINO) != ROOTINO) errexit("CANNOT ALLOCATE ROOT INODE\n"); descend(&rootdesc, ROOTINO); break; } if (reply("CONTINUE") == 0) errexit(""); statemap[ROOTINO] = DSTATE; descend(&rootdesc, ROOTINO); break; case FSTATE: case FCLEAR: pfatal("ROOT INODE NOT DIRECTORY"); if (reply("REALLOCATE")) { freeino(ROOTINO); if (allocdir(ROOTINO, ROOTINO) != ROOTINO) errexit("CANNOT ALLOCATE ROOT INODE\n"); descend(&rootdesc, ROOTINO); break; } if (reply("FIX") == 0) errexit(""); dp = ginode(ROOTINO); dp->di_mode &= ~IFMT; dp->di_mode |= IFDIR; inodirty(); statemap[ROOTINO] = DSTATE; /* fall into ... */ case DSTATE: descend(&rootdesc, ROOTINO); break; default: errexit("BAD STATE %d FOR ROOT INODE", statemap[ROOTINO]); } }
virtual void reply( Message& received, Message& response ) { reply( received , response , received.data->id ); }
bool CheckServerJob::finished() { if (reply()->request().url().scheme() == QLatin1String("https") && reply()->sslConfiguration().sessionTicket().isEmpty() && reply()->error() == QNetworkReply::NoError) { qCWarning(lcCheckServerJob) << "No SSL session identifier / session ticket is used, this might impact sync performance negatively."; } mergeSslConfigurationForSslButton(reply()->sslConfiguration(), account()); // The server installs to /owncloud. Let's try that if the file wasn't found // at the original location if ((reply()->error() == QNetworkReply::ContentNotFoundError) && (!_subdirFallback)) { _subdirFallback = true; setPath(QLatin1String(owncloudDirC) + QLatin1String(statusphpC)); start(); qCInfo(lcCheckServerJob) << "Retrying with" << reply()->url(); return false; } QByteArray body = reply()->peek(4 * 1024); int httpStatus = reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); if (body.isEmpty() || httpStatus != 200) { qCWarning(lcCheckServerJob) << "error: status.php replied " << httpStatus << body; emit instanceNotFound(reply()); } else { QJsonParseError error; auto status = QJsonDocument::fromJson(body, &error); // empty or invalid response if (error.error != QJsonParseError::NoError || status.isNull()) { qCWarning(lcCheckServerJob) << "status.php from server is not valid JSON!" << body << reply()->request().url() << error.errorString(); } qCInfo(lcCheckServerJob) << "status.php returns: " << status << " " << reply()->error() << " Reply: " << reply(); if (status.object().contains("installed")) { emit instanceFound(_serverUrl, status.object()); } else { qCWarning(lcCheckServerJob) << "No proper answer on " << reply()->url(); emit instanceNotFound(reply()); } } return true; }
bool SimpleNetworkJob::finished() { emit finishedSignal(reply()); return true; }
pass2() { register struct dinode *dp; register struct inoinfo **inpp, *inp; struct inoinfo **inpend; struct inodesc curino; struct dinode dino; char pathbuf[MAXPATHLEN + 1]; switch (statemap[ROOTINO]) { case USTATE: pfatal("ROOT INODE UNALLOCATED"); if (reply("ALLOCATE") == 0) errexit(""); if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO) errexit("CANNOT ALLOCATE ROOT INODE\n"); break; case DCLEAR: pfatal("DUPS/BAD IN ROOT INODE"); if (reply("REALLOCATE")) { freeino(ROOTINO); if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO) errexit("CANNOT ALLOCATE ROOT INODE\n"); break; } if (reply("CONTINUE") == 0) errexit(""); break; case FSTATE: case FCLEAR: pfatal("ROOT INODE NOT DIRECTORY"); if (reply("REALLOCATE")) { freeino(ROOTINO); if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO) errexit("CANNOT ALLOCATE ROOT INODE\n"); break; } if (reply("FIX") == 0) errexit(""); dp = ginode(ROOTINO); dp->di_mode &= ~IFMT; dp->di_mode |= IFDIR; inodirty(); break; case DSTATE: break; default: errexit("BAD STATE %d FOR ROOT INODE", statemap[ROOTINO]); } statemap[ROOTINO] = DFOUND; /* * Sort the directory list into disk block order. */ qsort((char *)inpsort, (size_t)inplast, sizeof *inpsort, blksort); /* * Check the integrity of each directory. */ bzero((char *)&curino, sizeof(struct inodesc)); curino.id_type = DATA; curino.id_func = pass2check; dino.di_mode = IFDIR; dp = &dino; inpend = &inpsort[inplast]; for (inpp = inpsort; inpp < inpend; inpp++) { inp = *inpp; if (inp->i_isize == 0) continue; if (inp->i_isize < MINDIRSIZE) { direrror(inp->i_number, "DIRECTORY TOO SHORT"); inp->i_isize = roundup(MINDIRSIZE, DIRBLKSIZ); if (reply("FIX") == 1) { dp = ginode(inp->i_number); dp->di_size = inp->i_isize; inodirty(); dp = &dino; } } else if ((inp->i_isize & (DIRBLKSIZ - 1)) != 0) { getpathname(pathbuf, inp->i_number, inp->i_number); pwarn("DIRECTORY %s: LENGTH %d NOT MULTIPLE OF %d", pathbuf, inp->i_isize, DIRBLKSIZ); if (preen) printf(" (ADJUSTED)\n"); inp->i_isize = roundup(inp->i_isize, DIRBLKSIZ); if (preen || reply("ADJUST") == 1) { dp = ginode(inp->i_number); dp->di_size = roundup(inp->i_isize, DIRBLKSIZ); inodirty(); dp = &dino; } } dp->di_size = inp->i_isize; bcopy((char *)&inp->i_blks[0], (char *)&dp->di_db[0], (size_t)inp->i_numblks); curino.id_number = inp->i_number; curino.id_parent = inp->i_parent; (void)ckinode(dp, &curino); } /* * Now that the parents of all directories have been found, * make another pass to verify the value of `..' */ for (inpp = inpsort; inpp < inpend; inpp++) { inp = *inpp; if (inp->i_parent == 0 || inp->i_isize == 0) continue; if (statemap[inp->i_parent] == DFOUND && statemap[inp->i_number] == DSTATE) statemap[inp->i_number] = DFOUND; if (inp->i_dotdot == inp->i_parent || inp->i_dotdot == (ino_t)-1) continue; if (inp->i_dotdot == 0) { inp->i_dotdot = inp->i_parent; fileerror(inp->i_parent, inp->i_number, "MISSING '..'"); if (reply("FIX") == 0) continue; (void)makeentry(inp->i_number, inp->i_parent, ".."); lncntp[inp->i_parent]--; continue; } fileerror(inp->i_parent, inp->i_number, "BAD INODE NUMBER FOR '..'"); if (reply("FIX") == 0) continue; lncntp[inp->i_dotdot]++; lncntp[inp->i_parent]--; inp->i_dotdot = inp->i_parent; (void)changeino(inp->i_number, "..", inp->i_parent); } /* * Mark all the directories that can be found from the root. */ propagate(); }
void CheckServerJob::encryptedSlot() { mergeSslConfigurationForSslButton(reply()->sslConfiguration(), account()); }
void sender(String *path) { String *s; static char *lastsender; if(rejectcheck()) return; if (authenticate && !authenticated) { rejectcount++; reply("530 5.7.0 Authentication required\r\n"); return; } if(him == 0 || *him == 0){ rejectcount++; reply("503 Start by saying HELO, please.\r\n", s_to_c(path)); return; } /* don't add the domain onto black holes or we will loop */ if(strchr(s_to_c(path), '!') == 0 && strcmp(s_to_c(path), "/dev/null") != 0){ s = s_new(); s_append(s, him); s_append(s, "!"); s_append(s, s_to_c(path)); s_terminate(s); s_free(path); path = s; } if(shellchars(s_to_c(path))){ rejectcount++; reply("501 5.1.3 Bad character in sender address %s.\r\n", s_to_c(path)); return; } /* * if the last sender address resulted in a rejection because the sending * domain didn't exist and this sender has the same domain, reject * immediately. */ if(lastsender){ if (strncmp(lastsender, s_to_c(path), strlen(lastsender)) == 0){ filterstate = REFUSED; rejectcount++; reply("554 5.1.8 Sender domain must exist: %s\r\n", s_to_c(path)); return; } free(lastsender); /* different sender domain */ lastsender = 0; } /* * see if this ip address, domain name, user name or account is blocked */ logged = 0; filterstate = blocked(path); /* * permanently reject what we can before trying smtp ping, which * often leads to merely temporary rejections. */ switch (filterstate){ case DENIED: syslog(0, "smtpd", "Denied %s (%s/%s)", s_to_c(path), him, nci->rsys); rejectcount++; logged++; reply("554-5.7.1 We don't accept mail from %s.\r\n", s_to_c(path)); reply("554 5.7.1 Contact postmaster@%s for more information.\r\n", dom); return; case REFUSED: syslog(0, "smtpd", "Refused %s (%s/%s)", s_to_c(path), him, nci->rsys); rejectcount++; logged++; reply("554 5.7.1 Sender domain must exist: %s\r\n", s_to_c(path)); return; } listadd(&senders, path); reply("250 2.0.0 sender is %s\r\n", s_to_c(path)); }
String* startcmd(void) { int n; char *filename; char **av; Link *l; String *cmd; /* * ignore the filterstate if the all the receivers prefer it. */ filterstate = optoutall(filterstate); switch (filterstate){ case BLOCKED: case DELAY: rejectcount++; logmsg("Blocked"); filename = dumpfile(s_to_c(senders.last->p)); cmd = s_new(); s_append(cmd, "cat > "); s_append(cmd, filename); pp = proc_start(s_to_c(cmd), instream(), 0, outstream(), 0, 0); break; case DIALUP: logmsg("Dialup"); rejectcount++; reply("554 5.7.1 We don't accept mail from dial-up ports.\r\n"); /* * we could exit here, because we're never going to accept mail * from this ip address, but it's unclear that RFC821 allows * that. Instead we set the hardreject flag and go stupid. */ hardreject = 1; return 0; case DENIED: logmsg("Denied"); rejectcount++; reply("554-5.7.1 We don't accept mail from %s.\r\n", s_to_c(senders.last->p)); reply("554 5.7.1 Contact postmaster@%s for more information.\r\n", dom); return 0; case REFUSED: logmsg("Refused"); rejectcount++; reply("554 5.7.1 Sender domain must exist: %s\r\n", s_to_c(senders.last->p)); return 0; default: case NONE: logmsg("Confused"); rejectcount++; reply("554-5.7.0 We have had an internal mailer error " "classifying your message.\r\n"); reply("554-5.7.0 Filterstate is %d\r\n", filterstate); reply("554 5.7.0 Contact postmaster@%s for more information.\r\n", dom); return 0; case ACCEPT: /* * now that all other filters have been passed, * do grey-list processing. */ if(gflag) vfysenderhostok(); /* fall through */ case TRUSTED: /* * set up mail command */ cmd = s_clone(mailer); n = 3; for(l = rcvers.first; l; l = l->next) n++; av = malloc(n * sizeof(char*)); if(av == nil){ reply("450 4.3.2 We're busy right now, try later\r\n"); s_free(cmd); return 0; } n = 0; av[n++] = s_to_c(cmd); av[n++] = "-r"; for(l = rcvers.first; l; l = l->next) av[n++] = s_to_c(l->p); av[n] = 0; /* * start mail process */ pp = noshell_proc_start(av, instream(), outstream(), outstream(), 0, 0); free(av); break; } if(pp == 0) { reply("450 4.3.2 We're busy right now, try later\r\n"); s_free(cmd); return 0; } return cmd; }
void sayhi(void) { reply("220 %s ESMTP\r\n", dom); }
void hello(String *himp, int extended) { char **mynames; char *ldot, *rdot; him = s_to_c(himp); syslog(0, "smtpd", "%s from %s as %s", extended? "ehlo": "helo", nci->rsys, him); if(rejectcheck()) return; if (strchr(him, '.') && nci && !trusted && fflag && strcmp(nci->rsys, nci->lsys) != 0){ /* * We don't care if he lies about who he is, but it is * not okay to pretend to be us. Many viruses do this, * just parroting back what we say in the greeting. */ if(strcmp(him, dom) == 0) goto Liarliar; for(mynames = sysnames_read(); mynames && *mynames; mynames++){ if(cistrcmp(*mynames, him) == 0){ Liarliar: syslog(0, "smtpd", "Hung up on %s; claimed to be %s", nci->rsys, him); if(Dflag) sleep(delaysecs()*1000); reply("554 5.7.0 Liar!\r\n"); exits("client pretended to be us"); return; } } } /* * it is unacceptable to claim any string that doesn't look like * a domain name (e.g., has at least one dot in it), but * Microsoft mail client software gets this wrong, so let trusted * (local) clients omit the dot. */ rdot = strrchr(him, '.'); if (rdot && rdot[1] == '\0') { *rdot = '\0'; /* clobber trailing dot */ rdot = strrchr(him, '.'); /* try again */ } if (!trusted && rdot == nil) goto Liarliar; /* * Reject obviously bogus domains and those reserved by RFC 2606. */ if (rdot == nil) rdot = him; else rdot++; if (!trusted && (cistrcmp(rdot, "localdomain") == 0 || cistrcmp(rdot, "localhost") == 0 || cistrcmp(rdot, "example") == 0 || cistrcmp(rdot, "invalid") == 0 || cistrcmp(rdot, "test") == 0)) goto Liarliar; /* bad top-level domain */ /* check second-level RFC 2606 domains: example\.(com|net|org) */ if (rdot != him) *--rdot = '\0'; ldot = strrchr(him, '.'); if (rdot != him) *rdot = '.'; if (ldot == nil) ldot = him; else ldot++; if (cistrcmp(ldot, "example.com") == 0 || cistrcmp(ldot, "example.net") == 0 || cistrcmp(ldot, "example.org") == 0) goto Liarliar; /* * similarly, if the claimed domain is not an address-literal, * require at least one letter, which there will be in * at least the last component (e.g., .com, .net) if it's real. * this rejects non-address-literal IP addresses, * among other bogosities. */ if (!trusted && him[0] != '[') { char *p; for (p = him; *p != '\0'; p++) if (isascii(*p) && isalpha(*p)) break; if (*p == '\0') goto Liarliar; } if(strchr(him, '.') == 0 && nci != nil && strchr(nci->rsys, '.') != nil) him = nci->rsys; if(Dflag) sleep(delaysecs()*1000); reply("250%c%s you are %s\r\n", extended ? '-' : ' ', dom, him); if (extended) { reply("250-ENHANCEDSTATUSCODES\r\n"); /* RFCs 2034 and 3463 */ if(tlscert != nil) reply("250-STARTTLS\r\n"); if (passwordinclear) reply("250 AUTH CRAM-MD5 PLAIN LOGIN\r\n"); else reply("250 AUTH CRAM-MD5\r\n"); } }
void auth(String *mech, String *resp) { char *user, *pass, *scratch = nil; AuthInfo *ai = nil; Chalstate *chs = nil; String *s_resp1_64 = nil, *s_resp2_64 = nil, *s_resp1 = nil; String *s_resp2 = nil; if (rejectcheck()) goto bomb_out; syslog(0, "smtpd", "auth(%s, %s) from %s", s_to_c(mech), "(protected)", him); if (authenticated) { bad_sequence: rejectcount++; reply("503 5.5.2 Bad sequence of commands\r\n"); goto bomb_out; } if (cistrcmp(s_to_c(mech), "plain") == 0) { if (!passwordinclear) { rejectcount++; reply("538 5.7.1 Encryption required for requested " "authentication mechanism\r\n"); goto bomb_out; } s_resp1_64 = resp; if (s_resp1_64 == nil) { reply("334 \r\n"); s_resp1_64 = s_new(); if (getcrnl(s_resp1_64, &bin) <= 0) goto bad_sequence; } s_resp1 = s_dec64(s_resp1_64); if (s_resp1 == nil) { rejectcount++; reply("501 5.5.4 Cannot decode base64\r\n"); goto bomb_out; } memset(s_to_c(s_resp1_64), 'X', s_len(s_resp1_64)); user = s_to_c(s_resp1) + strlen(s_to_c(s_resp1)) + 1; pass = user + strlen(user) + 1; ai = auth_userpasswd(user, pass); authenticated = ai != nil; memset(pass, 'X', strlen(pass)); goto windup; } else if (cistrcmp(s_to_c(mech), "login") == 0) { if (!passwordinclear) { rejectcount++; reply("538 5.7.1 Encryption required for requested " "authentication mechanism\r\n"); goto bomb_out; } if (resp == nil) { reply("334 VXNlcm5hbWU6\r\n"); s_resp1_64 = s_new(); if (getcrnl(s_resp1_64, &bin) <= 0) goto bad_sequence; } reply("334 UGFzc3dvcmQ6\r\n"); s_resp2_64 = s_new(); if (getcrnl(s_resp2_64, &bin) <= 0) goto bad_sequence; s_resp1 = s_dec64(s_resp1_64); s_resp2 = s_dec64(s_resp2_64); memset(s_to_c(s_resp2_64), 'X', s_len(s_resp2_64)); if (s_resp1 == nil || s_resp2 == nil) { rejectcount++; reply("501 5.5.4 Cannot decode base64\r\n"); goto bomb_out; } ai = auth_userpasswd(s_to_c(s_resp1), s_to_c(s_resp2)); authenticated = ai != nil; memset(s_to_c(s_resp2), 'X', s_len(s_resp2)); windup: if (authenticated) { /* if you authenticated, we trust you despite your IP */ trusted = 1; reply("235 2.0.0 Authentication successful\r\n"); } else { rejectcount++; reply("535 5.7.1 Authentication failed\r\n"); syslog(0, "smtpd", "authentication failed: %r"); } goto bomb_out; } else if (cistrcmp(s_to_c(mech), "cram-md5") == 0) { int chal64n; char *resp, *t; chs = auth_challenge("proto=cram role=server"); if (chs == nil) { rejectcount++; reply("501 5.7.5 Couldn't get CRAM-MD5 challenge\r\n"); goto bomb_out; } scratch = malloc(chs->nchal * 2 + 1); chal64n = enc64(scratch, chs->nchal * 2, (uchar *)chs->chal, chs->nchal); scratch[chal64n] = 0; reply("334 %s\r\n", scratch); s_resp1_64 = s_new(); if (getcrnl(s_resp1_64, &bin) <= 0) goto bad_sequence; s_resp1 = s_dec64(s_resp1_64); if (s_resp1 == nil) { rejectcount++; reply("501 5.5.4 Cannot decode base64\r\n"); goto bomb_out; } /* should be of form <user><space><response> */ resp = s_to_c(s_resp1); t = strchr(resp, ' '); if (t == nil) { rejectcount++; reply("501 5.5.4 Poorly formed CRAM-MD5 response\r\n"); goto bomb_out; } *t++ = 0; chs->user = resp; chs->resp = t; chs->nresp = strlen(t); ai = auth_response(chs); authenticated = ai != nil; goto windup; } rejectcount++; reply("501 5.5.1 Unrecognised authentication type %s\r\n", s_to_c(mech)); bomb_out: if (ai) auth_freeAI(ai); if (chs) auth_freechal(chs); if (scratch) free(scratch); if (s_resp1) s_free(s_resp1); if (s_resp2) s_free(s_resp2); if (s_resp1_64) s_free(s_resp1_64); if (s_resp2_64) s_free(s_resp2_64); }
void data(void) { int status, nbytes; char *cp, *ep; char errx[ERRMAX]; Link *l; String *cmd, *err; if(rejectcheck()) return; if(senders.last == 0){ reply("503 2.5.2 Data without MAIL FROM:\r\n"); rejectcount++; return; } if(rcvers.last == 0){ reply("503 2.5.2 Data without RCPT TO:\r\n"); rejectcount++; return; } if(!trusted && sendermxcheck()){ rerrstr(errx, sizeof errx); if(strncmp(errx, "rejected:", 9) == 0) reply("554 5.7.1 %s\r\n", errx); else reply("450 4.7.0 %s\r\n", errx); for(l=rcvers.first; l; l=l->next) syslog(0, "smtpd", "[%s/%s] %s -> %s sendercheck: %s", him, nci->rsys, s_to_c(senders.first->p), s_to_c(l->p), errx); rejectcount++; return; } cmd = startcmd(); if(cmd == 0) return; reply("354 Input message; end with <CRLF>.<CRLF>\r\n"); if(debug){ seek(2, 0, 2); stamp(); fprint(2, "# sent 354; accepting DATA %s\n", thedate()); } /* * allow 145 more minutes to move the data */ alarm(145*60*1000); status = pipemsg(&nbytes); /* * read any error messages */ err = s_new(); if (debug) { stamp(); fprint(2, "waiting for upas/send to close stderr\n"); } while(s_read_line(pp->std[2]->fp, err)) ; alarm(0); atnotify(catchalarm, 0); if (debug) { stamp(); fprint(2, "waiting for upas/send to exit\n"); } status |= proc_wait(pp); if(debug){ seek(2, 0, 2); stamp(); fprint(2, "# %d upas/send status %#ux at %s\n", getpid(), status, thedate()); if(*s_to_c(err)) fprint(2, "# %d error %s\n", getpid(), s_to_c(err)); } /* * if process terminated abnormally, send back error message */ if(status){ int code; char *ecode; if(strstr(s_to_c(err), "mail refused")){ syslog(0, "smtpd", "++[%s/%s] %s %s refused: %s", him, nci->rsys, s_to_c(senders.first->p), s_to_c(cmd), firstline(s_to_c(err))); code = 554; ecode = "5.0.0"; } else { syslog(0, "smtpd", "++[%s/%s] %s %s %s%s%sreturned %#q %s", him, nci->rsys, s_to_c(senders.first->p), s_to_c(cmd), piperror? "error during pipemsg: ": "", piperror? piperror: "", piperror? "; ": "", pp->waitmsg->msg, firstline(s_to_c(err))); code = 450; ecode = "4.0.0"; } for(cp = s_to_c(err); ep = strchr(cp, '\n'); cp = ep){ *ep++ = 0; reply("%d-%s %s\r\n", code, ecode, cp); } reply("%d %s mail process terminated abnormally\r\n", code, ecode); } else { /* * if a message appeared on stderr, despite good status, * log it. this can happen if rewrite.in contains a bad * r.e., for example. */ if(*s_to_c(err)) syslog(0, "smtpd", "%s returned good status, but said: %s", s_to_c(mailer), s_to_c(err)); if(filterstate == BLOCKED) reply("554 5.7.1 we believe this is spam. " "we don't accept it.\r\n"); else if(filterstate == DELAY) reply("450 4.3.0 There will be a delay in delivery " "of this message.\r\n"); else { reply("250 2.5.0 sent\r\n"); logcall(nbytes); if(debug){ seek(2, 0, 2); stamp(); fprint(2, "# %d sent 250 reply %s\n", getpid(), thedate()); } } } proc_free(pp); pp = 0; s_free(cmd); s_free(err); listfree(&senders); listfree(&rcvers); }
int linkup(ino_t orphan, ino_t parentdir) { union lfs_dinode *dp; int lostdir; ino_t oldlfdir; struct inodesc idesc; char tempname[BUFSIZ]; struct uvnode *vp; memset(&idesc, 0, sizeof(struct inodesc)); vp = vget(fs, orphan); dp = VTOD(vp); lostdir = (lfs_dino_getmode(fs, dp) & LFS_IFMT) == LFS_IFDIR; pwarn("UNREF %s ", lostdir ? "DIR" : "FILE"); pinode(orphan); if (preen && lfs_dino_getsize(fs, dp) == 0) return (0); if (preen) printf(" (RECONNECTED)\n"); else if (reply("RECONNECT") == 0) return (0); if (lfdir == 0) { dp = ginode(ULFS_ROOTINO); idesc.id_name = lfname; idesc.id_type = DATA; idesc.id_func = findino; idesc.id_number = ULFS_ROOTINO; if ((ckinode(dp, &idesc) & FOUND) != 0) { lfdir = idesc.id_parent; } else { pwarn("NO lost+found DIRECTORY"); if (preen || reply("CREATE")) { lfdir = allocdir(ULFS_ROOTINO, (ino_t) 0, lfmode); if (lfdir != 0) { if (makeentry(ULFS_ROOTINO, lfdir, lfname) != 0) { if (preen) printf(" (CREATED)\n"); } else { freedir(lfdir, ULFS_ROOTINO); lfdir = 0; if (preen) printf("\n"); } } } } if (lfdir == 0) { pfatal("SORRY. CANNOT CREATE lost+found DIRECTORY"); printf("\n\n"); return (0); } } vp = vget(fs, lfdir); dp = VTOD(vp); if ((lfs_dino_getmode(fs, dp) & LFS_IFMT) != LFS_IFDIR) { pfatal("lost+found IS NOT A DIRECTORY"); if (reply("REALLOCATE") == 0) return (0); oldlfdir = lfdir; if ((lfdir = allocdir(ULFS_ROOTINO, (ino_t) 0, lfmode)) == 0) { pfatal("SORRY. CANNOT CREATE lost+found DIRECTORY\n\n"); return (0); } if ((changeino(ULFS_ROOTINO, lfname, lfdir) & ALTERED) == 0) { pfatal("SORRY. CANNOT CREATE lost+found DIRECTORY\n\n"); return (0); } inodirty(VTOI(vp)); idesc.id_type = ADDR; idesc.id_func = pass4check; idesc.id_number = oldlfdir; adjust(&idesc, lncntp[oldlfdir] + 1); lncntp[oldlfdir] = 0; vp = vget(fs, lfdir); dp = VTOD(vp); } if (statemap[lfdir] != DFOUND) { pfatal("SORRY. NO lost+found DIRECTORY\n\n"); return (0); } (void) lftempname(tempname, orphan); if (makeentry(lfdir, orphan, tempname) == 0) { pfatal("SORRY. NO SPACE IN lost+found DIRECTORY"); printf("\n\n"); return (0); } lncntp[orphan]--; if (lostdir) { if ((changeino(orphan, "..", lfdir) & ALTERED) == 0 && parentdir != (ino_t) - 1) (void) makeentry(orphan, lfdir, ".."); vp = vget(fs, lfdir); lfs_dino_setnlink(fs, VTOI(vp)->i_din, lfs_dino_getnlink(fs, VTOI(vp)->i_din) + 1); inodirty(VTOI(vp)); lncntp[lfdir]++; pwarn("DIR I=%llu CONNECTED. ", (unsigned long long)orphan); if (parentdir != (ino_t) - 1) printf("PARENT WAS I=%llu\n", (unsigned long long)parentdir); if (preen == 0) printf("\n"); } return (1); }
/*! \brief Message handling function for all messages sent to the app_server \param code ID of the message sent \param buffer Attachment buffer for the message. */ void AppServer::_DispatchMessage(int32 code, BPrivate::LinkReceiver& msg) { switch (code) { case AS_GET_DESKTOP: { Desktop* desktop = NULL; port_id replyPort; msg.Read<port_id>(&replyPort); int32 userID; msg.Read<int32>(&userID); char* targetScreen = NULL; msg.ReadString(&targetScreen); if (targetScreen != NULL && strlen(targetScreen) == 0) { free(targetScreen); targetScreen = NULL; } int32 version; if (msg.Read<int32>(&version) < B_OK || version != AS_PROTOCOL_VERSION) { syslog(LOG_ERR, "Application for user %" B_PRId32 " with port " "%" B_PRId32 " does not support the current server " "protocol.\n", userID, replyPort); } else { desktop = _FindDesktop(userID, targetScreen); if (desktop == NULL) { // we need to create a new desktop object for this user // TODO: test if the user exists on the system // TODO: maybe have a separate AS_START_DESKTOP_SESSION for // authorizing the user desktop = _CreateDesktop(userID, targetScreen); } } free(targetScreen); BPrivate::LinkSender reply(replyPort); if (desktop != NULL) { reply.StartMessage(B_OK); reply.Attach<port_id>(desktop->MessagePort()); } else reply.StartMessage(B_ERROR); reply.Flush(); break; } #if TEST_MODE case B_QUIT_REQUESTED: { // We've been asked to quit, so (for now) broadcast to all // desktops to quit. This situation will occur only when the server // is compiled as a regular Be application. fQuitting = true; while (fDesktops.CountItems() > 0) { Desktop *desktop = fDesktops.RemoveItemAt(0); thread_id thread = desktop->Thread(); desktop->PostMessage(B_QUIT_REQUESTED); // we just wait for the desktop to kill itself status_t status; wait_for_thread(thread, &status); } delete this; // we are now clear to exit exit(0); break; } #endif default: STRACE(("Server::MainLoop received unexpected code %" B_PRId32 " " "(offset %" B_PRId32 ")\n", code, code - SERVER_TRUE)); break; } }
void NotificationView::MessageReceived(BMessage* msg) { switch (msg->what) { case B_GET_PROPERTY: { BMessage specifier; const char* property; BMessage reply(B_REPLY); bool msgOkay = true; if (msg->FindMessage("specifiers", 0, &specifier) != B_OK) msgOkay = false; if (specifier.FindString("property", &property) != B_OK) msgOkay = false; if (msgOkay) { if (strcmp(property, "type") == 0) reply.AddInt32("result", fType); if (strcmp(property, "app") == 0) reply.AddString("result", fApp); if (strcmp(property, "title") == 0) reply.AddString("result", fTitle); if (strcmp(property, "content") == 0) reply.AddString("result", fText); if (strcmp(property, "progress") == 0) reply.AddFloat("result", fProgress); if ((strcmp(property, "icon") == 0) && fBitmap) { BMessage archive; if (fBitmap->Archive(&archive) == B_OK) reply.AddMessage("result", &archive); } reply.AddInt32("error", B_OK); } else { reply.what = B_MESSAGE_NOT_UNDERSTOOD; reply.AddInt32("error", B_ERROR); } msg->SendReply(&reply); break; } case B_SET_PROPERTY: { BMessage specifier; const char* property; BMessage reply(B_REPLY); bool msgOkay = true; if (msg->FindMessage("specifiers", 0, &specifier) != B_OK) msgOkay = false; if (specifier.FindString("property", &property) != B_OK) msgOkay = false; if (msgOkay) { if (strcmp(property, "app") == 0) msg->FindString("data", &fApp); if (strcmp(property, "title") == 0) msg->FindString("data", &fTitle); if (strcmp(property, "content") == 0) msg->FindString("data", &fText); if (strcmp(property, "icon") == 0) { BMessage archive; if (msg->FindMessage("data", &archive) == B_OK) { delete fBitmap; fBitmap = new BBitmap(&archive); } } SetText(Application(), Title(), Text()); Invalidate(); reply.AddInt32("error", B_OK); } else { reply.what = B_MESSAGE_NOT_UNDERSTOOD; reply.AddInt32("error", B_ERROR); } msg->SendReply(&reply); break; } case kRemoveView: { BMessage remove(kRemoveView); remove.AddPointer("view", this); BMessenger msgr(Window()); msgr.SendMessage( &remove ); break; } default: BView::MessageReceived(msg); } }
void Cserver::ThreadProc(void) { if(server==INVALID_SOCKET) return; int i; CEvent ServerEvent; CEvent ClientEvent[MAX_CLIENTS]; #define MAX_DATA 1024 // longest message a client can send char ClientData[MAX_CLIENTS][MAX_DATA]; char toparse[MAX_DATA]; HANDLE events[MAX_CLIENTS+2]; bool server_running=true; WSAEventSelect(server,ServerEvent,FD_ACCEPT); for(i=0;i<MAX_CLIENTS;i++) ClientData[i][0]=0; for(;;) { int count=0; events[count++]=ServerThreadEvent; if(server_running) events[count++]=ServerEvent; for(i=0;i<MAX_CLIENTS;i++) if(clients[i]!=INVALID_SOCKET) events[count++]=ClientEvent[i]; unsigned int res=WaitForMultipleObjects(count,events,FALSE,INFINITE); if(res==WAIT_OBJECT_0) { DEBUG("ServerThread terminating\n"); AfxEndThread(0); return; } else if(server_running && res==(WAIT_OBJECT_0+1)) { for(i=0;i<MAX_CLIENTS;i++) if(clients[i]==INVALID_SOCKET) break; if(i==MAX_CLIENTS) { DEBUG("Should have at least 1 empty client, but none found\n"); continue; } clients[i]=accept(server,NULL,NULL); if(clients[i]==INVALID_SOCKET) { DEBUG("accept() failed\n"); continue; } WSAEventSelect(clients[i],ClientEvent[i],FD_CLOSE|FD_READ); ClientEvent[i].ResetEvent(); ClientData[i][0]='\0'; DEBUG("Client connection %d accepted\n",i); for(i=0;i<MAX_CLIENTS;i++) if(clients[i]==INVALID_SOCKET) break; if(i==MAX_CLIENTS) { DEBUG("Server full. Closing server socket.\n"); stopserver(); server_running=false; } } else /* client closed or data received */ { count=server_running?2:1; for(i=0;i<MAX_CLIENTS;i++) { if(clients[i]!=INVALID_SOCKET) { if(res==(WAIT_OBJECT_0+(count++))) { /* either we got data or the connection closed */ int curlen=strlen(ClientData[i]); int maxlen=MAX_DATA-curlen-1; int bytes=recv( clients[i], ClientData[i]+curlen, maxlen, 0); if(bytes==0 || bytes==SOCKET_ERROR) { /* Connection was closed or something's screwy */ closesocket(clients[i]); clients[i]=INVALID_SOCKET; DEBUG("Client connection %d closed\n",i); if(server_running==false) { DEBUG("Slot open. Restarting server.\n"); if(startserver()==true) { WSAEventSelect(server,ServerEvent,FD_ACCEPT); server_running=true; } else { DEBUG("Server failed to restart.\n"); stopserver(); } } } else /* bytes > 0, we read data */ { ClientData[i][curlen+bytes]='\0'; char *cur=ClientData[i]; for(;;) { char *nl=strchr(cur,'\n'); if(nl==NULL) { if(cur!=ClientData[i]) memmove(ClientData[i],cur,strlen(cur)+1); break; } else { *nl='\0'; // ---------------------------- // Do something with the received line (cur) DEBUG("Got string: %s\n",cur); LRESULT copyDataResult=false; char *response=NULL; strcpy(toparse,cur); char *command=NULL; char *remotename=NULL; char *buttonname=NULL; char *repeats=NULL; if (toparse) command=strtok(toparse," \t\r"); if (!command) //ignore lines with only whitespace { cur=nl+1; break; } else if (stricmp(command,"VERSION")==0) { if (strtok(NULL," \t\r")==NULL) { copyDataResult = true; response = new char[strlen(id)+9]; if (response) sprintf(response,"DATA\n1\n%s\n",id); } else copyDataResult=-100; } else if (stricmp(command,"LIST")==0) { remotename=strtok(NULL," \t\r"); struct ir_remote *all=global_remotes; int n=0; if (!remotename) { copyDataResult = true; while(all) { n++; all=all->next; } if (n!=0) { response = new char[n*(LINE_LEN+2)+7]; sprintf(response,"DATA\n%d\n",n); all=global_remotes; while(all) { strcat(response,all->name); strcat(response,"\n"); all=all->next; } } } else { while (all!=NULL && stricmp(remotename,all->name)) all=all->next; if (all) { copyDataResult = true; struct ir_ncode *allcodes=all->codes; while (allcodes->name) { n++; allcodes++; } if (n!=0) { response = new char[n*(LINE_LEN+2)+7]; sprintf(response,"DATA\n%d\n",n); allcodes=all->codes; while(allcodes->name) { strcat(response,allcodes->name); strcat(response,"\n"); allcodes++; } } } else copyDataResult=-1; //unknown remote } } else if (!password.IsEmpty() && !password.CompareNoCase(command)) //only accept commands if a password is set and matches { CString incoming = (LPCSTR) (cur); int j=incoming.FindOneOf(" \t")+1; remotename=strtok(NULL," \t\r"); if (remotename==NULL) { response = new char[14]; if (response) sprintf(response,"DATA\n1\nremote missing\n"); } else { buttonname=strtok(NULL," \t\r"); if (buttonname==NULL) { response = new char[12]; if (response) sprintf(response,"DATA\n1\ncode missing\n"); } else { HWND pOtherWnd = FindWindow(NULL, "WinLirc"); if (pOtherWnd) { COPYDATASTRUCT cpd; cpd.dwData = 0; cpd.cbData = strlen(&cur[j]); cpd.lpData = (void*)&cur[j]; copyDataResult = SendMessage(pOtherWnd,WM_COPYDATA,NULL,(LPARAM)&cpd); } } } } else { response = new char[strlen(command)+26]; if (response) sprintf(response,"DATA\n1\n%s%s\n","unknown command: ",command); } if (copyDataResult==-1) { response = new char[strlen(remotename)+25]; if (response) sprintf(response,"DATA\n1\n%s%s\n","unknown remote: ",remotename); } else if (copyDataResult==-2) { response = new char[strlen(buttonname)+23]; if (response) sprintf(response,"DATA\n1\n%s%s\n","unknown code: ",buttonname); } else if (copyDataResult==-100) { response = new char[15]; if (response) sprintf(response,"DATA\n1\nbad send packet\n"); } reply(cur,i,copyDataResult==1,response); if (response) delete(response); cur=nl+1; } } } break; } } } } } }
static int pass2check(struct inodesc *idesc) { struct direct *dirp = idesc->id_dirp; struct inoinfo *inp; int n, entrysize, ret = 0; union dinode *dp; char *errmsg; struct direct proto; char namebuf[MAXPATHLEN + 1]; char pathbuf[MAXPATHLEN + 1]; /* * If converting, set directory entry type. */ if (doinglevel2 && dirp->d_ino > 0 && dirp->d_ino < maxino) { dirp->d_type = GET_ITYPE(dirp->d_ino); ret |= ALTERED; } /* * check for "." */ if (idesc->id_entryno != 0) goto chk1; if (dirp->d_ino != 0 && strcmp(dirp->d_name, ".") == 0) { if (dirp->d_ino != idesc->id_number) { direrror(idesc->id_number, "BAD INODE NUMBER FOR '.'"); dirp->d_ino = idesc->id_number; if (reply("FIX") == 1) ret |= ALTERED; } if (newinofmt && dirp->d_type != DT_DIR) { direrror(idesc->id_number, "BAD TYPE VALUE FOR '.'"); dirp->d_type = DT_DIR; if (reply("FIX") == 1) ret |= ALTERED; } goto chk1; } direrror(idesc->id_number, "MISSING '.'"); proto.d_ino = idesc->id_number; if (newinofmt) proto.d_type = DT_DIR; else proto.d_type = 0; proto.d_namlen = 1; (void)strlcpy(proto.d_name, ".", sizeof proto.d_name); # if BYTE_ORDER == LITTLE_ENDIAN if (!newinofmt) { u_char tmp; tmp = proto.d_type; proto.d_type = proto.d_namlen; proto.d_namlen = tmp; } # endif entrysize = DIRSIZ(0, &proto); if (dirp->d_ino != 0 && strcmp(dirp->d_name, "..") != 0) { pfatal("CANNOT FIX, FIRST ENTRY IN DIRECTORY CONTAINS %s\n", dirp->d_name); } else if (dirp->d_reclen < entrysize) { pfatal("CANNOT FIX, INSUFFICIENT SPACE TO ADD '.'\n"); } else if (dirp->d_reclen < 2 * entrysize) { proto.d_reclen = dirp->d_reclen; memcpy(dirp, &proto, (size_t)entrysize); if (reply("FIX") == 1) ret |= ALTERED; } else { n = dirp->d_reclen - entrysize; proto.d_reclen = entrysize; memcpy(dirp, &proto, (size_t)entrysize); idesc->id_entryno++; lncntp[dirp->d_ino]--; dirp = (struct direct *)((char *)(dirp) + entrysize); memset(dirp, 0, (size_t)n); dirp->d_reclen = n; if (reply("FIX") == 1) ret |= ALTERED; } chk1: if (idesc->id_entryno > 1) goto chk2; inp = getinoinfo(idesc->id_number); proto.d_ino = inp->i_parent; if (newinofmt) proto.d_type = DT_DIR; else proto.d_type = 0; proto.d_namlen = 2; (void)strlcpy(proto.d_name, "..", sizeof proto.d_name); # if BYTE_ORDER == LITTLE_ENDIAN if (!newinofmt) { u_char tmp; tmp = proto.d_type; proto.d_type = proto.d_namlen; proto.d_namlen = tmp; } # endif entrysize = DIRSIZ(0, &proto); if (idesc->id_entryno == 0) { n = DIRSIZ(0, dirp); if (dirp->d_reclen < n + entrysize) goto chk2; proto.d_reclen = dirp->d_reclen - n; dirp->d_reclen = n; idesc->id_entryno++; lncntp[dirp->d_ino]--; dirp = (struct direct *)((char *)(dirp) + n); memset(dirp, 0, (size_t)proto.d_reclen); dirp->d_reclen = proto.d_reclen; } if (dirp->d_ino != 0 && strcmp(dirp->d_name, "..") == 0) { inp->i_dotdot = dirp->d_ino; if (newinofmt && dirp->d_type != DT_DIR) { direrror(idesc->id_number, "BAD TYPE VALUE FOR '..'"); dirp->d_type = DT_DIR; if (reply("FIX") == 1) ret |= ALTERED; } goto chk2; } if (dirp->d_ino != 0 && strcmp(dirp->d_name, ".") != 0) { fileerror(inp->i_parent, idesc->id_number, "MISSING '..'"); pfatal("CANNOT FIX, SECOND ENTRY IN DIRECTORY CONTAINS %s\n", dirp->d_name); inp->i_dotdot = -1; } else if (dirp->d_reclen < entrysize) { fileerror(inp->i_parent, idesc->id_number, "MISSING '..'"); pfatal("CANNOT FIX, INSUFFICIENT SPACE TO ADD '..'\n"); inp->i_dotdot = -1; } else if (inp->i_parent != 0) { /* * We know the parent, so fix now. */ inp->i_dotdot = inp->i_parent; fileerror(inp->i_parent, idesc->id_number, "MISSING '..'"); proto.d_reclen = dirp->d_reclen; memcpy(dirp, &proto, (size_t)entrysize); if (reply("FIX") == 1) ret |= ALTERED; } idesc->id_entryno++; if (dirp->d_ino != 0) lncntp[dirp->d_ino]--; return (ret|KEEPON); chk2: if (dirp->d_ino == 0) return (ret|KEEPON); if (dirp->d_namlen <= 2 && dirp->d_name[0] == '.' && idesc->id_entryno >= 2) { if (dirp->d_namlen == 1) { direrror(idesc->id_number, "EXTRA '.' ENTRY"); dirp->d_ino = 0; if (reply("FIX") == 1) ret |= ALTERED; return (KEEPON | ret); } if (dirp->d_name[1] == '.') { direrror(idesc->id_number, "EXTRA '..' ENTRY"); dirp->d_ino = 0; if (reply("FIX") == 1) ret |= ALTERED; return (KEEPON | ret); } } idesc->id_entryno++; n = 0; if (dirp->d_ino > maxino) { fileerror(idesc->id_number, dirp->d_ino, "I OUT OF RANGE"); n = reply("REMOVE"); } else { again: switch (GET_ISTATE(dirp->d_ino)) { case USTATE: if (idesc->id_entryno <= 2) break; fileerror(idesc->id_number, dirp->d_ino, "UNALLOCATED"); n = reply("REMOVE"); break; case DCLEAR: case FCLEAR: if (idesc->id_entryno <= 2) break; if (GET_ISTATE(dirp->d_ino) == FCLEAR) errmsg = "DUP/BAD"; else if (!preen && !usedsoftdep) errmsg = "ZERO LENGTH DIRECTORY"; else { n = 1; break; } fileerror(idesc->id_number, dirp->d_ino, errmsg); if ((n = reply("REMOVE")) == 1) break; dp = ginode(dirp->d_ino); SET_ISTATE(dirp->d_ino, (DIP(dp, di_mode) & IFMT) == IFDIR ? DSTATE : FSTATE); lncntp[dirp->d_ino] = DIP(dp, di_nlink); goto again; case DSTATE: case DFOUND: inp = getinoinfo(dirp->d_ino); if (inp->i_parent != 0 && idesc->id_entryno > 2) { getpathname(pathbuf, sizeof pathbuf, idesc->id_number, idesc->id_number); getpathname(namebuf, sizeof namebuf, dirp->d_ino, dirp->d_ino); pwarn("%s %s %s\n", pathbuf, "IS AN EXTRANEOUS HARD LINK TO DIRECTORY", namebuf); if (preen) { printf (" (REMOVED)\n"); n = 1; break; } if ((n = reply("REMOVE")) == 1) break; } if (idesc->id_entryno > 2) inp->i_parent = idesc->id_number; /* FALLTHROUGH */ case FSTATE: if (newinofmt && dirp->d_type != GET_ITYPE(dirp->d_ino)) { fileerror(idesc->id_number, dirp->d_ino, "BAD TYPE VALUE"); dirp->d_type = GET_ITYPE(dirp->d_ino); if (reply("FIX") == 1) ret |= ALTERED; } lncntp[dirp->d_ino]--; break; default: errexit("BAD STATE %d FOR INODE I=%d\n", GET_ISTATE(dirp->d_ino), dirp->d_ino); } } if (n == 0) return (ret|KEEPON); dirp->d_ino = 0; return (ret|KEEPON|ALTERED); }
void MainWidget::request( QTcpSocket *id, const QHttpRequestHeader &header ) { mpMessageBuffer->addItem( header.toString() ); while( mpMessageBuffer->count() > 200 ) { QListWidgetItem *item = mpMessageBuffer->takeItem( 0 ); if( item ) { delete item; } } mpMessageBuffer->scrollToBottom(); #if 0 if( header.path() == "/favicon.ico" ) { QFile file( ":/favicon.ico" ); file.open( QIODevice::ReadOnly | QIODevice::Text ); emit response( id, QHttpResponseHeader( 200, "OK" ), file.readAll() ); file.close(); return; } #endif if( header.path() == "/wait" ) { mDelayList.append( id ); return; } if( header.path() == "/get" ) { QString reply( "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" "<response>\n" " <reply>%1</reply>\n" " <artist>%2</artist>\n" " <title>%3</title>\n" " <album>%4</album>\n" " <track>%5</track>\n" "</response>\n" ); QByteArray replyMsg( reply.arg( Qt::escape( QString::fromUtf8(mMsg.constData()) ), Qt::escape( mTrackInfo.mArtist ), Qt::escape( mTrackInfo.mTitle ), Qt::escape( mTrackInfo.mAlbum ), QString::number(mTrackInfo.mTrackNr) ).toUtf8() ); emit response( id, QHttpResponseHeader( 200, "OK XML" ), replyMsg ); return; } QString html("<html>\n<head>\n<title>%1</title>\n" "<meta http-equiv='content-type' content='text/html; charset=UTF-8'>\n" "<link rel='shortcut icon' href='/favicon.ico' type='image/x-icon'>\n" "<script src='ajax.js' type='text/javascript'>\n" "</script>\n" "</head>\n<body>\n" "<h1>%2</h1>\n" "<p>HTTP Request: %3 %4</p>\n" "<table border='1'>\n" "<tr valign='top'><td>Artist:</td><td><textarea cols='80' rows='1' name='artist' wrap='off' readonly></textarea></td></tr>\n" "<tr valign='top'><td>Title:</td><td><textarea cols='80' rows='1' name='title' wrap='off' readonly></textarea></td></tr>\n" "<tr valign='top'><td>Album:</td><td><textarea cols='80' rows='1' name='album' wrap='off' readonly></textarea></td></tr>\n" "<tr valign='top'><td>Track:</td><td><textarea cols='80' rows='1' name='track' wrap='off' readonly></textarea></td></tr>\n" "<tr valign='top'><td>Reply:</td><td><textarea cols='80' rows='5' name='reply' wrap='off' readonly></textarea></td></tr>\n" "<tr valign='top'><td>Status:</td><td><input name='status' size='12' readonly>" "<input type='button' value='refresh' onclick='loadFields();'></td></tr>\n" "</table></body></html>\n" ); html = html.arg( QApplication::organizationName() + ": " + QApplication::applicationName(), QApplication::organizationName() + ": " + QApplication::applicationName(), header.method(), header.path() ); emit response( id, QHttpResponseHeader( 200, "OK" ), html.toUtf8() ); }
void pass2(void) { union dinode *dp; struct inoinfo **inpp, *inp, *pinp; struct inoinfo **inpend; struct inodesc curino; union dinode dino; char pathbuf[MAXPATHLEN + 1]; int i; switch (GET_ISTATE(ROOTINO)) { case USTATE: pfatal("ROOT INODE UNALLOCATED"); if (reply("ALLOCATE") == 0) { ckfini(0); errexit("%s", ""); } if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO) errexit("CANNOT ALLOCATE ROOT INODE\n"); break; case DCLEAR: pfatal("DUPS/BAD IN ROOT INODE"); if (reply("REALLOCATE")) { freeino(ROOTINO); if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO) errexit("CANNOT ALLOCATE ROOT INODE\n"); break; } if (reply("CONTINUE") == 0) { ckfini(0); errexit("%s", ""); } break; case FSTATE: case FCLEAR: pfatal("ROOT INODE NOT DIRECTORY"); if (reply("REALLOCATE")) { freeino(ROOTINO); if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO) errexit("CANNOT ALLOCATE ROOT INODE\n"); break; } if (reply("FIX") == 0) { ckfini(0); errexit("%s", ""); } dp = ginode(ROOTINO); DIP_SET(dp, di_mode, DIP(dp, di_mode) & ~IFMT); DIP_SET(dp, di_mode, DIP(dp, di_mode) | IFDIR); inodirty(); break; case DSTATE: break; default: errexit("BAD STATE %d FOR ROOT INODE\n", GET_ISTATE(ROOTINO)); } SET_ISTATE(ROOTINO, DFOUND); /* * Sort the directory list into disk block order. */ qsort(inpsort, (size_t)inplast, sizeof *inpsort, blksort); /* * Check the integrity of each directory. */ memset(&curino, 0, sizeof(struct inodesc)); curino.id_type = DATA; curino.id_func = pass2check; inpend = &inpsort[inplast]; info_pos = 0; info_max = inpend - inpsort; info_fn = pass2_info1; for (inpp = inpsort; inpp < inpend; inpp++) { inp = *inpp; info_pos ++; if (inp->i_isize == 0) continue; if (inp->i_isize < MINDIRSIZE) { direrror(inp->i_number, "DIRECTORY TOO SHORT"); inp->i_isize = roundup(MINDIRSIZE, DIRBLKSIZ); if (reply("FIX") == 1) { dp = ginode(inp->i_number); DIP_SET(dp, di_size, inp->i_isize); inodirty(); } } else if ((inp->i_isize & (DIRBLKSIZ - 1)) != 0) { getpathname(pathbuf, sizeof pathbuf, inp->i_number, inp->i_number); if (usedsoftdep) pfatal("%s %s: LENGTH %ld NOT MULTIPLE of %d", "DIRECTORY", pathbuf, (long)inp->i_isize, DIRBLKSIZ); else pwarn("%s %s: LENGTH %ld NOT MULTIPLE OF %d", "DIRECTORY", pathbuf, (long)inp->i_isize, DIRBLKSIZ); if (preen) printf(" (ADJUSTED)\n"); inp->i_isize = roundup(inp->i_isize, DIRBLKSIZ); if (preen || reply("ADJUST") == 1) { dp = ginode(inp->i_number); DIP_SET(dp, di_size, inp->i_isize); inodirty(); } } memset(&dino, 0, sizeof(union dinode)); dp = &dino; DIP_SET(dp, di_mode, IFDIR); DIP_SET(dp, di_size, inp->i_isize); for (i = 0; i < (inp->i_numblks<NDADDR ? inp->i_numblks : NDADDR); i++) DIP_SET(dp, di_db[i], inp->i_blks[i]); if (inp->i_numblks > NDADDR) for (i = 0; i < NIADDR; i++) DIP_SET(dp, di_ib[i], inp->i_blks[NDADDR + i]); curino.id_number = inp->i_number; curino.id_parent = inp->i_parent; (void)ckinode(dp, &curino); } /* * Now that the parents of all directories have been found, * make another pass to verify the value of `..' */ info_pos = 0; info_fn = pass2_info2; for (inpp = inpsort; inpp < inpend; inpp++) { inp = *inpp; info_pos++; if (inp->i_parent == 0 || inp->i_isize == 0) continue; if (inp->i_dotdot == inp->i_parent || inp->i_dotdot == (ino_t)-1) continue; if (inp->i_dotdot == 0) { inp->i_dotdot = inp->i_parent; fileerror(inp->i_parent, inp->i_number, "MISSING '..'"); if (reply("FIX") == 0) continue; (void)makeentry(inp->i_number, inp->i_parent, ".."); lncntp[inp->i_parent]--; continue; } fileerror(inp->i_parent, inp->i_number, "BAD INODE NUMBER FOR '..'"); if (reply("FIX") == 0) continue; lncntp[inp->i_dotdot]++; lncntp[inp->i_parent]--; inp->i_dotdot = inp->i_parent; (void)changeino(inp->i_number, "..", inp->i_parent); } info_fn = NULL; /* * Create a list of children for each directory. */ inpend = &inpsort[inplast]; for (inpp = inpsort; inpp < inpend; inpp++) { inp = *inpp; if (inp->i_parent == 0 || inp->i_number == ROOTINO) continue; pinp = getinoinfo(inp->i_parent); inp->i_parentp = pinp; inp->i_sibling = pinp->i_child; pinp->i_child = inp; } /* * Mark all the directories that can be found from the root. */ propagate(ROOTINO); }
void CheckServerJob::metaDataChangedSlot() { account()->setSslConfiguration(reply()->sslConfiguration()); mergeSslConfigurationForSslButton(reply()->sslConfiguration(), account()); }
status_t PrintServerApp::async_thread(void* data) { AsyncThreadParams* p = (AsyncThreadParams*)data; Printer* printer = p->printer; BMessage* msg = p->AcquireMessage(); { AutoReply sender(msg, 'stop'); switch (msg->what) { // Handle showing the config dialog case PSRV_SHOW_PAGE_SETUP: { case PSRV_SHOW_PRINT_SETUP: if (printer) { if (p->app->fUseConfigWindow) { config_setup_kind kind = kJobSetup; if (msg->what == PSRV_SHOW_PAGE_SETUP) kind = kPageSetup; ConfigWindow* w = new ConfigWindow(kind, printer, msg, &sender); w->Go(); } else { BMessage reply(*msg); status_t status = B_ERROR; if (msg->what == PSRV_SHOW_PAGE_SETUP) status = printer->ConfigurePage(reply); else status = printer->ConfigureJob(reply); if (status == B_OK) sender.SetReply(&reply); } } else { // If no default printer is set, give user // choice of aborting or setting up a printer int32 count = Printer::CountPrinters(); BString alertText( B_TRANSLATE("There are no printers set up.")); if (count > 0) alertText.SetTo(B_TRANSLATE( "There is no default printer set up.")); alertText.Append(" "); alertText.Append( B_TRANSLATE("Would you like to set one up now?")); BAlert* alert = new BAlert("Info", alertText.String(), B_TRANSLATE("No"), B_TRANSLATE("Yes")); alert->SetShortcut(0, B_ESCAPE); if (alert->Go() == 1) { if (count == 0) run_add_printer_panel(); else run_select_printer_panel(); } } } break; // Retrieve default configuration message from printer add-on case PSRV_GET_DEFAULT_SETTINGS: { if (printer) { BMessage reply; if (printer->GetDefaultSettings(reply) == B_OK) { sender.SetReply(&reply); break; } } } break; // Create a new printer case PSRV_MAKE_PRINTER: { BString driverName; BString printerName; BString transportName; BString transportPath; if (msg->FindString("driver", &driverName) == B_OK && msg->FindString("transport", &transportName) == B_OK && msg->FindString("transport path", &transportPath) == B_OK && msg->FindString("printer name", &printerName) == B_OK) { BString connection; if (msg->FindString("connection", &connection) != B_OK) connection = "Local"; // then create the actual printer if (p->app->CreatePrinter(printerName.String(), driverName.String(), connection.String(), transportName.String(), transportPath.String()) == B_OK) { // If printer was created ok, // ask if it needs to be the default BString text(B_TRANSLATE("Would you like to make @ " "the default printer?")); text.ReplaceFirst("@", printerName.String()); BAlert* alert = new BAlert("", text.String(), B_TRANSLATE("No"), B_TRANSLATE("Yes")); alert->SetShortcut(0, B_ESCAPE); if (alert->Go() == 1) p->app->SelectPrinter(printerName.String()); } } } break; } } delete p; return B_OK; }
bool EntityExistsJob::finished() { emit exists(reply()); return true; }
/*===========================================================================* * main * *===========================================================================*/ int main(void) { /* This is the main routine of this service. The main loop consists of * three major activities: getting new work, processing the work, and * sending the reply. The loop never terminates, unless a panic occurs. */ message m; /* request message */ int ipc_status; /* status code */ int call_nr, who_e,who_p; /* call number and caller */ int result; /* result to return */ int s; /* SEF local startup. */ sef_local_startup(); if (OK != (s=sys_getmachine(&machine))) panic("couldn't get machine info: %d", s); /* Main loop - get work and do it, forever. */ while (TRUE) { /* Perform sensitive background operations when RS is idle. */ rs_idle_period(); /* Wait for request message. */ get_work(&m, &ipc_status); who_e = m.m_source; if(rs_isokendpt(who_e, &who_p) != OK) { panic("message from bogus source: %d", who_e); } call_nr = m.m_type; /* Now determine what to do. Four types of requests are expected: * - Heartbeat messages (notifications from registered system services) * - System notifications (synchronous alarm) * - User requests (control messages to manage system services) * - Ready messages (reply messages from registered services) */ /* Notification messages are control messages and do not need a reply. * These include heartbeat messages and system notifications. */ if (is_ipc_notify(ipc_status)) { switch (who_p) { case CLOCK: do_period(&m); /* check services status */ continue; default: /* heartbeat notification */ if (rproc_ptr[who_p] != NULL) { /* mark heartbeat time */ rproc_ptr[who_p]->r_alive_tm = m.m_notify.timestamp; } else { printf("RS: warning: got unexpected notify message from %d\n", m.m_source); } } } /* If we get this far, this is a normal request. * Handle the request and send a reply to the caller. */ else { /* Handler functions are responsible for permission checking. */ switch(call_nr) { /* User requests. */ case RS_UP: result = do_up(&m); break; case RS_DOWN: result = do_down(&m); break; case RS_REFRESH: result = do_refresh(&m); break; case RS_RESTART: result = do_restart(&m); break; case RS_SHUTDOWN: result = do_shutdown(&m); break; case RS_UPDATE: result = do_update(&m); break; case RS_CLONE: result = do_clone(&m); break; case RS_UNCLONE: result = do_unclone(&m); break; case RS_EDIT: result = do_edit(&m); break; case RS_SYSCTL: result = do_sysctl(&m); break; case RS_FI: result = do_fi(&m); break; case RS_GETSYSINFO: result = do_getsysinfo(&m); break; case RS_LOOKUP: result = do_lookup(&m); break; /* Ready messages. */ case RS_INIT: result = do_init_ready(&m); break; case RS_LU_PREPARE: result = do_upd_ready(&m); break; default: printf("RS: warning: got unexpected request %d from %d\n", m.m_type, m.m_source); result = ENOSYS; } /* Finally send reply message, unless disabled. */ if (result != EDONTREPLY) { m.m_type = result; reply(who_e, NULL, &m); } } } }
void ChatHandler::handleEnterChannelMessage(ChatClient &client, MessageIn &msg) { MessageOut reply(CPMSG_ENTER_CHANNEL_RESPONSE); std::string channelName = msg.readString(); std::string givenPassword = msg.readString(); ChatChannel *channel = NULL; if (chatChannelManager->channelExists(channelName) || chatChannelManager->tryNewPublicChannel(channelName)) { channel = chatChannelManager->getChannel(channelName); } if (!channel) { reply.writeByte(ERRMSG_INVALID_ARGUMENT); } else if (!channel->getPassword().empty() && channel->getPassword() != givenPassword) { // Incorrect password (should probably have its own return value) reply.writeByte(ERRMSG_INSUFFICIENT_RIGHTS); } else if (!channel->canJoin()) { reply.writeByte(ERRMSG_INVALID_ARGUMENT); } else { if (channel->addUser(&client)) { reply.writeByte(ERRMSG_OK); // The user entered the channel, now give him the channel // id, the announcement string and the user list. reply.writeShort(channel->getId()); reply.writeString(channelName); reply.writeString(channel->getAnnouncement()); const ChatChannel::ChannelUsers &users = channel->getUserList(); for (ChatChannel::ChannelUsers::const_iterator i = users.begin(), i_end = users.end(); i != i_end; ++i) { reply.writeString((*i)->characterName); reply.writeString(channel->getUserMode((*i))); } // Send an CPMSG_UPDATE_CHANNEL to warn other clients a user went // in the channel. warnUsersAboutPlayerEventInChat(channel, client.characterName, CHAT_EVENT_NEW_PLAYER); // log transaction Transaction trans; trans.mCharacterId = client.characterId; trans.mAction = TRANS_CHANNEL_JOIN; trans.mMessage = "User joined " + channelName; storage->addTransaction(trans); } else { reply.writeByte(ERRMSG_FAILURE); } } client.send(reply); }
static void my_actor_child(self_t self) { aid_t aid = recv(self, 3); reply(self, aid); }
int runpipe(int c) { int retval = EXIT_FAILURE; int s; struct sockaddr_un addr = {AF_UNIX, SOCKPATH}; socklen_t len = set_dpy(&addr, getenv("DISPLAY")); if(!len) { fputs("chrwin: DISPLAY is not set properly\n", stderr); return EXIT_FAILURE; } puts(addr.sun_path); s = socket(addr.sun_family, SOCK_STREAM, 0); if(s < 0) { perror("chrwin: socket failed"); goto out_c; } if(connect(s, (struct sockaddr*)&addr, len) < 0) { perror("chrwin: connect failed"); goto out_s; } if(xconn(c, s) < 0) goto out_s; socklen_t clen = 0; socklen_t slen = 0; fd_set rfd; int nfds = MAX(c, s) + 1; for(;;) { FD_ZERO(&rfd); FD_SET(c, &rfd); FD_SET(s, &rfd); if(pselect(nfds, &rfd, 0, 0, 0, 0) < 0) { if(errno == EINTR) { continue; } perror("chrwin: select failed"); goto out_s; } if(FD_ISSET(c, &rfd)) { clen = read(c, &buf, sizeof(buf)); if(clen == 0) break; request(clen); clen -= write(s, &buf, clen); } if(FD_ISSET(s, &rfd)) { slen = read(s, &buf, sizeof(buf)); if(slen == 0) break; reply(slen); slen -= write(c, &buf, slen); } } retval = EXIT_SUCCESS; out_s: close(s); out_c: close(c); return retval; }
/// This function runs in a thread for every client, and reads incomming data. /// It also writes the incomming data to all other clients. void Seller::processMessage(int rfd) { // std::cout << "This is a seller (peer " << _peerId << "). I am selling " << goodsNames[_goods] << ". " << _amount << " items left.\n"; char buf[MAXLEN]; int buflen; //read incomming message. buflen = read(rfd, buf, sizeof(buf)); pthread_mutex_lock(&_mutex_state); FD_CLR(rfd, &_the_state); // free fd's from clients pthread_mutex_unlock(&_mutex_state); if (buflen <= 0) { std::cerr<<"[sellr-"<<_peerId<<"] Client disconnected."<<std::endl; close(rfd); pthread_exit(NULL); return; } // process the purchase request // check Fish 0 // purchase Salt 1 // std::cout << "[seller-" << _peerId << "] ";// << buf << std::endl; // printMessage(buf); std::string requestType; Goods goods; int var; std::vector<int> path; decodeMessage(buf, requestType, goods, var, path); int originPeerId = path[0]; int lastNbPeerId = path.back(); pthread_mutex_lock(&_mutex_state); bool isCloseSocket = true; if(requestType == "purchase") { if(goods == _goods) { if(_amount > 0) { // std::cout << "================================== end of the deal ==========================================\n"; // sendPeerMessage(originPeerId, msg.c_str()); std::string msg = encodeMessage("deal", _goods, -1, -1); reply(rfd, msg.c_str()); if(_amount > 1) { std::printf("[sellr-%03d] I just #sold# %s to peer #%d. I still have %d %s.\n", _peerId, goodsNames[_goods], path.front(), _amount - 1, goodsNames[_goods]); } else { std::printf("[sellr-%03d] I just #sold# %s to peer #%d. It's last one.\n", _peerId, goodsNames[_goods], path.front()); } _amount--; isCloseSocket = false; if(_amount == 0) { // std::cout << goodsNames[_goods] << " seld out.\n"; randPickGoods(goodsAmount); } } else { std::string msg = encodeMessage("fail_deal", _goods, -1, -1); reply(rfd, msg.c_str()); std::printf("[sellr-%03d] Peer #%d wants to buy %s from me. Too late!\n", _peerId, path.front(), goodsNames[goods]); } } else { std::string msg = encodeMessage("fail_deal", _goods, -1, -1); reply(rfd, msg.c_str()); std::printf("[sellr-%03d] Peer #%d wants to buy %s from me. Too late!\n", _peerId, path.front(), goodsNames[goods]); } } else if(requestType == "look_up") { if(goods == _goods && _amount > 0) { // std::cout << "\n============================ start of the deal (maybe) ====================================\n"; std::string msg = encodeMessage("reply", _goods, _peerId, path.begin(), path.end() - 1); sendPeerMessage(lastNbPeerId, msg.c_str()); std::printf("[sellr-%03d] Trying to sell %s to buyer %d. Path back is ", _peerId, goodsNames[_goods], path.front()); for(size_t i = path.size() - 1; i > 0; --i) std::printf("%d->", path[i]); std::printf("%d.\n", path[0]); } else { floodingMessage(buf); //std::printf("[messager-%03d] Peer #%d wants to buy %s. Hop count: %d. Path is ", _peerId, path.front(), goodsNames[goods], var); std::printf("[msger-%03d] Peer #%d wants to buy %s. Path is ", _peerId, path.front(), goodsNames[goods]); for(size_t i = 0; i < path.size() - 1; ++i) std::printf("%d->", path[i]); std::printf("%d.\n", path.back()); } } else if(requestType == "reply") { int sellerPeerId = var; std::string msg = encodeMessage("reply", goods, sellerPeerId, path.begin(), path.end() - 1); sendPeerMessage(lastNbPeerId, msg.c_str()); std::printf("[msger-%03d] Peer #%d wants to sell %s to peer #%d. Path back is ", _peerId, sellerPeerId, goodsNames[goods], path.front()); for(size_t i = path.size() - 1; i > 0; --i) std::printf("%d->", path[i]); std::printf("%d.\n", path[0]); } else { std::cerr << "[Error] Unrecognized request type " << requestType << std::endl; } _activeConnect--; pthread_mutex_unlock(&_mutex_state); //std::cout << std::endl; if(isCloseSocket) close(rfd); pthread_exit(NULL); }
/* Has one FileOut parameter. */ int do_base64_out (const char *file) { CLEANUP_FREE char *buf = NULL; struct stat statbuf; int r; FILE *fp; CLEANUP_FREE char *cmd = NULL; CLEANUP_FREE char *buffer = NULL; buffer = malloc (GUESTFS_MAX_CHUNK_SIZE); if (buffer == NULL) { reply_with_perror ("malloc"); return -1; } /* Check the filename exists and is not a directory (RHBZ#908322). */ buf = sysroot_path (file); if (buf == NULL) { reply_with_perror ("malloc"); return -1; } if (stat (buf, &statbuf) == -1) { reply_with_perror ("stat: %s", file); return -1; } if (S_ISDIR (statbuf.st_mode)) { reply_with_error ("%s: is a directory", file); return -1; } /* Construct the command. */ if (asprintf_nowarn (&cmd, "%s %Q", str_base64, buf) == -1) { reply_with_perror ("asprintf"); return -1; } if (verbose) fprintf (stderr, "%s\n", cmd); fp = popen (cmd, "r"); if (fp == NULL) { reply_with_perror ("%s", cmd); return -1; } /* Now we must send the reply message, before the file contents. After * this there is no opportunity in the protocol to send any error * message back. Instead we can only cancel the transfer. */ reply (NULL, NULL); while ((r = fread (buffer, 1, GUESTFS_MAX_CHUNK_SIZE, fp)) > 0) { if (send_file_write (buffer, r) < 0) { pclose (fp); return -1; } } if (ferror (fp)) { fprintf (stderr, "fread: %s: %m\n", file); send_file_end (1); /* Cancel. */ pclose (fp); return -1; } if (pclose (fp) != 0) { fprintf (stderr, "pclose: %s: %m\n", file); send_file_end (1); /* Cancel. */ return -1; } if (send_file_end (0)) /* Normal end of file. */ return -1; return 0; }
void pass2(void) { struct ext2fs_dinode *dp; struct inoinfo **inpp, *inp; struct inoinfo **inpend; struct inodesc curino; struct ext2fs_dinode dino; char pathbuf[MAXPATHLEN + 1]; switch (statemap[EXT2_ROOTINO]) { case USTATE: pfatal("ROOT INODE UNALLOCATED"); if (reply("ALLOCATE") == 0) errexit("%s\n", ""); if (allocdir(EXT2_ROOTINO, EXT2_ROOTINO, 0755) != EXT2_ROOTINO) errexit("CANNOT ALLOCATE ROOT INODE\n"); break; case DCLEAR: pfatal("DUPS/BAD IN ROOT INODE"); if (reply("REALLOCATE")) { freeino(EXT2_ROOTINO); if (allocdir(EXT2_ROOTINO, EXT2_ROOTINO, 0755) != EXT2_ROOTINO) errexit("CANNOT ALLOCATE ROOT INODE\n"); break; } if (reply("CONTINUE") == 0) errexit("%s\n", ""); break; case FSTATE: case FCLEAR: pfatal("ROOT INODE NOT DIRECTORY"); if (reply("REALLOCATE")) { freeino(EXT2_ROOTINO); if (allocdir(EXT2_ROOTINO, EXT2_ROOTINO, 0755) != EXT2_ROOTINO) errexit("CANNOT ALLOCATE ROOT INODE\n"); break; } if (reply("FIX") == 0) errexit("%s\n", ""); dp = ginode(EXT2_ROOTINO); dp->e2di_mode = htole16((letoh16(dp->e2di_mode) & ~IFMT) | IFDIR); inodirty(); break; case DSTATE: break; default: errexit("BAD STATE %d FOR ROOT INODE\n", statemap[EXT2_ROOTINO]); } /* * Sort the directory list into disk block order. */ qsort((char *)inpsort, (size_t)inplast, sizeof *inpsort, blksort); /* * Check the integrity of each directory. */ memset(&curino, 0, sizeof(struct inodesc)); curino.id_type = DATA; curino.id_func = pass2check; inpend = &inpsort[inplast]; for (inpp = inpsort; inpp < inpend; inpp++) { inp = *inpp; if (inp->i_isize == 0) continue; if (inp->i_isize < MINDIRSIZE) { direrror(inp->i_number, "DIRECTORY TOO SHORT"); inp->i_isize = roundup(MINDIRSIZE, sblock.e2fs_bsize); if (reply("FIX") == 1) { dp = ginode(inp->i_number); inossize(dp, inp->i_isize); inodirty(); } } else if ((inp->i_isize & (sblock.e2fs_bsize - 1)) != 0) { getpathname(pathbuf, sizeof pathbuf, inp->i_number, inp->i_number); pwarn("DIRECTORY %s: LENGTH %lu NOT MULTIPLE OF %d", pathbuf, (u_long)inp->i_isize, sblock.e2fs_bsize); if (preen) printf(" (ADJUSTED)\n"); inp->i_isize = roundup(inp->i_isize, sblock.e2fs_bsize); if (preen || reply("ADJUST") == 1) { dp = ginode(inp->i_number); inossize(dp, inp->i_isize); inodirty(); } } memset(&dino, 0, sizeof(struct ext2fs_dinode)); dino.e2di_mode = htole16(IFDIR); inossize(&dino, inp->i_isize); memcpy(&dino.e2di_blocks[0], &inp->i_blks[0], (size_t)inp->i_numblks); curino.id_number = inp->i_number; curino.id_parent = inp->i_parent; (void)ckinode(&dino, &curino); } /* * Now that the parents of all directories have been found, * make another pass to verify the value of `..' */ for (inpp = inpsort; inpp < inpend; inpp++) { inp = *inpp; if (inp->i_parent == 0 || inp->i_isize == 0) continue; if (inp->i_dotdot == inp->i_parent || inp->i_dotdot == (ino_t)-1) continue; if (inp->i_dotdot == 0) { inp->i_dotdot = inp->i_parent; fileerror(inp->i_parent, inp->i_number, "MISSING '..'"); if (reply("FIX") == 0) continue; (void)makeentry(inp->i_number, inp->i_parent, ".."); lncntp[inp->i_parent]--; continue; } fileerror(inp->i_parent, inp->i_number, "BAD INODE NUMBER FOR '..'"); if (reply("FIX") == 0) continue; lncntp[inp->i_dotdot]++; lncntp[inp->i_parent]--; inp->i_dotdot = inp->i_parent; (void)changeino(inp->i_number, "..", inp->i_parent); } /* * Mark all the directories that can be found from the root. */ propagate(); }