/* Don't show the names of private rooms unless the viewing * user also knows the rooms. */ void GenerateRoomDisplay(char *real_room, CitContext *viewed, CitContext *viewer) { int ra; strcpy(real_room, viewed->room.QRname); if (viewed->room.QRflags & QR_MAILBOX) { strcpy(real_room, &real_room[11]); } if (viewed->room.QRflags & QR_PRIVATE) { CtdlRoomAccess(&viewed->room, &viewer->user, &ra, NULL); if ( (ra & UA_KNOWN) == 0) { strcpy(real_room, " "); } } if (viewed->cs_flags & CS_CHAT) { while (strlen(real_room) < 14) { strcat(real_room, " "); } strcpy(&real_room[14], "<chat>"); } }
// // Called once per room by nntp_list() to qualify and possibly output a single room // void nntp_list_backend(struct ctdlroom *qrbuf, void *data) { int ra; int view; struct nntp_list_data *nld = (struct nntp_list_data *)data; CtdlRoomAccess(qrbuf, &CC->user, &ra, &view); if (ra & UA_KNOWN) { output_roomname_in_list_format(qrbuf, nld->list_format, nld->wildmat_pattern); } }
/* * cmd_lkra() - List all known rooms */ void cmd_lkra_backend(struct ctdlroom *qrbuf, void *data) { int FloorBeingSearched = (-1); int ra; int view; FloorBeingSearched = *(int *)data; CtdlRoomAccess(qrbuf, &CC->user, &ra, &view); if ((( ra & (UA_KNOWN))) && ((qrbuf->QRfloor == (FloorBeingSearched)) || ((FloorBeingSearched) < 0))) list_roomname(qrbuf, ra, view, qrbuf->QRdefaultview); }
void cmd_lprm_backend(struct ctdlroom *qrbuf, void *data) { int FloorBeingSearched = (-1); int ra; int view; FloorBeingSearched = *(int *)data; CtdlRoomAccess(qrbuf, &CC->user, &ra, &view); if ( ((qrbuf->QRflags & QR_PRIVATE) == 0) && ((qrbuf->QRflags & QR_MAILBOX) == 0) && ((qrbuf->QRfloor == (FloorBeingSearched)) || ((FloorBeingSearched) < 0))) list_roomname(qrbuf, ra, view, qrbuf->QRdefaultview); }
// // Called once per room by nntp_newgroups() to qualify and possibly output a single room // void nntp_newgroups_backend(struct ctdlroom *qrbuf, void *data) { int ra; int view; time_t thetime = *(time_t *)data; CtdlRoomAccess(qrbuf, &CC->user, &ra, &view); /* * The "created after <date/time>" heuristics depend on the happy coincidence * that for a very long time we have used a unix timestamp as the room record's * generation number (QRgen). When this module is merged into the master * source tree we should rename QRgen to QR_create_time or something like that. */ if (ra & UA_KNOWN) { if (qrbuf->QRgen >= thetime) { output_roomname_in_list_format(qrbuf, NNTP_LIST_ACTIVE, NULL); } } }
void cmd_whok(char *cmdbuf) { struct ctdluser temp; struct cdbdata *cdbus; int ra; cprintf("%d Who knows room:\n", LISTING_FOLLOWS); cdb_rewind(CDB_USERS); while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) { memset(&temp, 0, sizeof temp); memcpy(&temp, cdbus->ptr, sizeof temp); cdb_free(cdbus); CtdlRoomAccess(&CC->room, &temp, &ra, NULL); if ((!IsEmptyStr(temp.fullname)) && (CC->room.QRflags & QR_INUSE) && (ra & UA_KNOWN) ) cprintf("%s\n", temp.fullname); } cprintf("000\n"); }
/* * Implements the GETACL command. */ void imap_getacl(int num_parms, ConstStr *Params) { char roomname[ROOMNAMELEN]; char savedroom[ROOMNAMELEN]; int msgs, new; int ret; struct ctdluser temp; struct cdbdata *cdbus; int ra; StrBuf *rights; if (num_parms != 3) { IReply("BAD usage error"); return; } /* * Search for the specified room or folder */ ret = imap_grabroom(roomname, Params[2].Key, 1); if (ret != 0) { IReply("NO Invalid mailbox name or access denied"); return; } /* * CtdlUserGoto() formally takes us to the desired room. (If another * folder is selected, save its name so we can return there!!!!!) */ if (IMAP->selected) { strcpy(savedroom, CC->room.QRname); } CtdlUserGoto(roomname, 0, 0, &msgs, &new, NULL, NULL); IAPuts("* ACL "); IPutCParamStr(2); /* * Traverse the userlist */ rights = NewStrBuf(); cdb_rewind(CDB_USERS); while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) { memset(&temp, 0, sizeof temp); memcpy(&temp, cdbus->ptr, sizeof temp); cdb_free(cdbus); CtdlRoomAccess(&CC->room, &temp, &ra, NULL); if (!IsEmptyStr(temp.fullname)) { imap_acl_flags(rights, ra); if (StrLength(rights) > 0) { IAPuts(" "); IPutStr(temp.fullname, strlen(temp.fullname)); IAPuts(" "); iaputs(SKEY( rights)); } } } FreeStrBuf(&rights); IAPuts("\r\n"); /* * If another folder is selected, go back to that room so we can resume * our happy day without violent explosions. */ if (IMAP->selected) { CtdlUserGoto(savedroom, 0, 0, &msgs, &new, NULL, NULL); }
/* * cmd_goto() - goto a new room */ void cmd_goto(char *gargs) { struct ctdlroom QRscratch; int c; int ok = 0; int ra; char augmented_roomname[ROOMNAMELEN]; char towhere[ROOMNAMELEN]; char password[32]; int transiently = 0; if (CtdlAccessCheck(ac_logged_in_or_guest)) return; extract_token(towhere, gargs, 0, '|', sizeof towhere); extract_token(password, gargs, 1, '|', sizeof password); transiently = extract_int(gargs, 2); CtdlGetUser(&CC->user, CC->curr_user); /* * Handle some of the macro named rooms */ convert_room_name_macros(towhere, sizeof towhere); /* First try a regular match */ c = CtdlGetRoom(&QRscratch, towhere); /* Then try a mailbox name match */ if (c != 0) { CtdlMailboxName(augmented_roomname, sizeof augmented_roomname, &CC->user, towhere); c = CtdlGetRoom(&QRscratch, augmented_roomname); if (c == 0) safestrncpy(towhere, augmented_roomname, sizeof towhere); } /* And if the room was found... */ if (c == 0) { /* Let internal programs go directly to any room. */ if (CC->internal_pgm) { memcpy(&CC->room, &QRscratch, sizeof(struct ctdlroom)); CtdlUserGoto(NULL, 1, transiently, NULL, NULL, NULL, NULL); return; } /* See if there is an existing user/room relationship */ CtdlRoomAccess(&QRscratch, &CC->user, &ra, NULL); /* normal clients have to pass through security */ if (ra & UA_GOTOALLOWED) { ok = 1; } if (ok == 1) { if ((QRscratch.QRflags & QR_MAILBOX) && ((ra & UA_GOTOALLOWED))) { memcpy(&CC->room, &QRscratch, sizeof(struct ctdlroom)); CtdlUserGoto(NULL, 1, transiently, NULL, NULL, NULL, NULL); return; } else if ((QRscratch.QRflags & QR_PASSWORDED) && ((ra & UA_KNOWN) == 0) && (strcasecmp(QRscratch.QRpasswd, password)) && (CC->user.axlevel < AxAideU) ) { cprintf("%d wrong or missing passwd\n", ERROR + PASSWORD_REQUIRED); return; } else if ((QRscratch.QRflags & QR_PRIVATE) && ((QRscratch.QRflags & QR_PASSWORDED) == 0) && ((QRscratch.QRflags & QR_GUESSNAME) == 0) && ((ra & UA_KNOWN) == 0) && (CC->user.axlevel < AxAideU) ) { syslog(LOG_DEBUG, "Failed to acquire private room\n"); } else { memcpy(&CC->room, &QRscratch, sizeof(struct ctdlroom)); CtdlUserGoto(NULL, 1, transiently, NULL, NULL, NULL, NULL); return; } } } cprintf("%d room '%s' not found\n", ERROR + ROOM_NOT_FOUND, towhere); }
// // Implements the GROUP and LISTGROUP commands // void nntp_group(const char *cmd) { if (CtdlAccessCheck(ac_logged_in_or_guest)) return; citnntp *nntpstate = (citnntp *) CC->session_specific_data; char verb[16]; char requested_group[1024]; char message_range[256]; char range_lo[256]; char range_hi[256]; char requested_room[ROOMNAMELEN]; char augmented_roomname[ROOMNAMELEN]; int c = 0; int ok = 0; int ra = 0; struct ctdlroom QRscratch; int msgs, new; long oldest,newest; struct listgroup_range lr; extract_token(verb, cmd, 0, ' ', sizeof verb); extract_token(requested_group, cmd, 1, ' ', sizeof requested_group); extract_token(message_range, cmd, 2, ' ', sizeof message_range); extract_token(range_lo, message_range, 0, '-', sizeof range_lo); extract_token(range_hi, message_range, 1, '-', sizeof range_hi); lr.lo = atoi(range_lo); lr.hi = atoi(range_hi); /* In LISTGROUP mode we can specify an empty name for 'currently selected' */ if ((!strcasecmp(verb, "LISTGROUP")) && (IsEmptyStr(requested_group))) { room_to_newsgroup(requested_group, CC->room.QRname, sizeof requested_group); } /* First try a regular match */ newsgroup_to_room(requested_room, requested_group, sizeof requested_room); c = CtdlGetRoom(&QRscratch, requested_room); /* Then try a mailbox name match */ if (c != 0) { CtdlMailboxName(augmented_roomname, sizeof augmented_roomname, &CC->user, requested_room); c = CtdlGetRoom(&QRscratch, augmented_roomname); if (c == 0) { safestrncpy(requested_room, augmented_roomname, sizeof(requested_room)); } } /* If the room exists, check security/access */ if (c == 0) { /* See if there is an existing user/room relationship */ CtdlRoomAccess(&QRscratch, &CC->user, &ra, NULL); /* normal clients have to pass through security */ if (ra & UA_KNOWN) { ok = 1; } } /* Fail here if no such room */ if (!ok) { cprintf("411 no such newsgroup\r\n"); return; } /* * CtdlUserGoto() formally takes us to the desired room, happily returning * the number of messages and number of new messages. */ memcpy(&CC->room, &QRscratch, sizeof(struct ctdlroom)); CtdlUserGoto(NULL, 0, 0, &msgs, &new, &oldest, &newest); cprintf("211 %d %ld %ld %s\r\n", msgs, oldest, newest, requested_group); // If this is a GROUP command, set the "current article number" to zero, and then stop here. if (!strcasecmp(verb, "GROUP")) { nntpstate->current_article_number = oldest; return; } // If we get to this point we are running a LISTGROUP command. Fetch those message numbers. CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, NULL, nntp_listgroup_backend, &lr); cprintf(".\r\n"); }