- CtdlLogPrintf(CTDL_DEBUG, "... no it isn't.\n");
- return(0);
-}
-
-
-/*
- * the client is identifying itself to the server
- */
-void cmd_iden(char *argbuf)
-{
- int dev_code;
- int cli_code;
- int rev_level;
- char desc[128];
- char from_host[128];
- struct in_addr addr;
- int do_lookup = 0;
-
- if (num_parms(argbuf)<4) {
- cprintf("%d usage error\n", ERROR + ILLEGAL_VALUE);
- return;
- }
-
- dev_code = extract_int(argbuf,0);
- cli_code = extract_int(argbuf,1);
- rev_level = extract_int(argbuf,2);
- extract_token(desc, argbuf, 3, '|', sizeof desc);
-
- safestrncpy(from_host, config.c_fqdn, sizeof from_host);
- from_host[sizeof from_host - 1] = 0;
- if (num_parms(argbuf)>=5) extract_token(from_host, argbuf, 4, '|', sizeof from_host);
-
- CC->cs_clientdev = dev_code;
- CC->cs_clienttyp = cli_code;
- CC->cs_clientver = rev_level;
- safestrncpy(CC->cs_clientname, desc, sizeof CC->cs_clientname);
- CC->cs_clientname[31] = 0;
-
- if (!IsEmptyStr(from_host)) {
- if (CC->is_local_socket) do_lookup = 1;
- else if (is_public_client()) do_lookup = 1;
- }
-
- if (do_lookup) {
- CtdlLogPrintf(CTDL_DEBUG, "Looking up hostname '%s'\n", from_host);
- if ((addr.s_addr = inet_addr(from_host)) != -1) {
- locate_host(CC->cs_host, sizeof CC->cs_host,
- CC->cs_addr, sizeof CC->cs_addr,
- &addr);
- }
- else {
- safestrncpy(CC->cs_host, from_host, sizeof CC->cs_host);
- CC->cs_host[sizeof CC->cs_host - 1] = 0;
- }
- }
-
- CtdlLogPrintf(CTDL_NOTICE, "Client %d/%d/%01d.%02d (%s) from %s\n",
- dev_code,
- cli_code,
- (rev_level / 100),
- (rev_level % 100),
- desc,
- CC->cs_host
- );
- cprintf("%d Ok\n",CIT_OK);
-}
-
-
-/*
- * display system messages or help
- */
-void cmd_mesg(char *mname)
-{
- FILE *mfp;
- char targ[256];
- char buf[256];
- char buf2[256];
- char *dirs[2];
- DIR *dp;
- struct dirent *d;
-
- extract_token(buf, mname, 0, '|', sizeof buf);
-
- dirs[0] = strdup(ctdl_message_dir);
- dirs[1] = strdup(ctdl_hlp_dir);
-
- snprintf(buf2, sizeof buf2, "%s.%d.%d",
- buf, CC->cs_clientdev, CC->cs_clienttyp);
-
- /* If the client requested "?" then produce a listing */
- if (!strcmp(buf, "?")) {
- cprintf("%d %s\n", LISTING_FOLLOWS, buf);
- dp = opendir(dirs[1]);
- if (dp != NULL) {
- while (d = readdir(dp), d != NULL) {
- if (d->d_name[0] != '.') {
- cprintf(" %s\n", d->d_name);
- }
- }
- closedir(dp);
- }
- cprintf("000\n");
- free(dirs[0]);
- free(dirs[1]);
- return;
- }
-
- /* Otherwise, look for the requested file by name. */
- else {
- mesg_locate(targ, sizeof targ, buf2, 2, (const char **)dirs);
- if (IsEmptyStr(targ)) {
- snprintf(buf2, sizeof buf2, "%s.%d",
- buf, CC->cs_clientdev);
- mesg_locate(targ, sizeof targ, buf2, 2,
- (const char **)dirs);
- if (IsEmptyStr(targ)) {
- mesg_locate(targ, sizeof targ, buf, 2,
- (const char **)dirs);
- }
- }
- }
-
- free(dirs[0]);
- free(dirs[1]);
-
- if (IsEmptyStr(targ)) {
- cprintf("%d '%s' not found. (Searching in %s and %s)\n",
- ERROR + FILE_NOT_FOUND,
- mname,
- ctdl_message_dir,
- ctdl_hlp_dir
- );
- return;
- }
-
- mfp = fopen(targ, "r");
- if (mfp==NULL) {
- cprintf("%d Cannot open '%s': %s\n",
- ERROR + INTERNAL_ERROR, targ, strerror(errno));
- return;
- }
- cprintf("%d %s\n", LISTING_FOLLOWS,buf);
-
- while (fgets(buf, (sizeof buf - 1), mfp) != NULL) {
- buf[strlen(buf)-1] = 0;
- do_help_subst(buf);
- cprintf("%s\n",buf);
- }
-
- fclose(mfp);
- cprintf("000\n");
-}
-
-
-/*
- * enter system messages or help
- */
-void cmd_emsg(char *mname)
-{
- FILE *mfp;
- char targ[256];
- char buf[256];
- char *dirs[2];
- int a;
-
- unbuffer_output();
-
- if (CtdlAccessCheck(ac_aide)) return;
-
- extract_token(buf, mname, 0, '|', sizeof buf);
- for (a=0; !IsEmptyStr(&buf[a]); ++a) { /* security measure */
- if (buf[a] == '/') buf[a] = '.';
- }
-
- dirs[0] = strdup(ctdl_message_dir);
- dirs[1] = strdup(ctdl_hlp_dir);
-
- mesg_locate(targ, sizeof targ, buf, 2, (const char**)dirs);
- free(dirs[0]);
- free(dirs[1]);
-
- if (IsEmptyStr(targ)) {
- snprintf(targ, sizeof targ,
- "%s/%s",
- ctdl_hlp_dir, buf);
- }
-
- mfp = fopen(targ,"w");
- if (mfp==NULL) {
- cprintf("%d Cannot open '%s': %s\n",
- ERROR + INTERNAL_ERROR, targ, strerror(errno));
- return;
- }
- cprintf("%d %s\n", SEND_LISTING, targ);
-
- while (client_getln(buf, sizeof buf) >=0 && strcmp(buf, "000")) {
- fprintf(mfp, "%s\n", buf);
- }
-
- fclose(mfp);
-}
-
-
-/* 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, "<private room>");
- }
- }
-
- if (viewed->cs_flags & CS_CHAT) {
- while (strlen(real_room) < 14) {
- strcat(real_room, " ");
- }
- strcpy(&real_room[14], "<chat>");
- }
-
-}
-
-/*
- * Convenience function.
- */
-int CtdlAccessCheck(int required_level) {
-
- if (CC->internal_pgm) return(0);
- if (required_level >= ac_internal) {
- cprintf("%d This is not a user-level command.\n",
- ERROR + HIGHER_ACCESS_REQUIRED);
- return(-1);
- }
-
- if ((required_level >= ac_logged_in) && (CC->logged_in == 0)) {
- cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
- return(-1);
- }
-
- if (CC->user.axlevel >= 6) return(0);
- if (required_level >= ac_aide) {
- cprintf("%d This command requires Aide access.\n",
- ERROR + HIGHER_ACCESS_REQUIRED);
- return(-1);
- }
-
- if (is_room_aide()) return(0);
- if (required_level >= ac_room_aide) {
- cprintf("%d This command requires Aide or Room Aide access.\n",
- ERROR + HIGHER_ACCESS_REQUIRED);
- return(-1);
- }
-
- /* shhh ... succeed quietly */