int cmd_mv (string str) { string t1, t2, *tmp; seteuid(geteuid(previous_object())); /* set it to the caller's perms */ if(this_player()->query_forced()) { write("Someone tried forcing you to mv "+str+"\n"); return 1; } if(!str||sscanf(str,"%s %s",t1,t2)!=2) { /* We should add checks for flags here. */ return help(); } else { #if 0 if(file_size(t2=resolv_path((string)this_player()->get_path(),t2)) > 0) { notify_fail("mv: "+t2+" already exists.\n"); return 0; } #endif t2=resolv_path((string)this_player()->get_path(),t2); rename(t1=resolv_path(this_player()->get_path(),t1),t2); if(file_size(t2) == -2) { tmp = explode(t1, "/"); t2 += "/" + tmp[sizeof(tmp)-1]; } write( ((file_size(t1)<0)&&(file_size(t2)!=-1)) ? t1+" -> "+t2+"\n" :"mv failed.\n"); } IMSTAT_D->add_stat(this_player()->query_name(), "mv", time()); return 1; }
int cmd_compress( string a ) /* a is the name of the file to be compressed */ { string old_file; string *old_lines; int number_lines; mixed arg; string old_file_name, new_file_name; if( !a ) { help(); notify_fail( "No argument passed.\n" ); return 0; } if( 2 != sscanf( a, "%s to %s", old_file_name, new_file_name ) && 2 != sscanf( a, "%s %s", old_file_name, new_file_name ) ) { old_file_name = a; new_file_name = a + ".comp"; } seteuid( getuid( previous_object() ) ); old_file_name = resolv_path( this_player()-> query( "cwd" ), old_file_name ); new_file_name = resolv_path( this_player()-> query( "cwd" ), new_file_name ); switch( file_size( old_file_name ) ) { case -2: notify_fail( "compress: " + old_file_name + ": directory\n" ); return 0; case -1: notify_fail( "compress: " + old_file_name + ": no such file\n" ); return 0; } if( !master()-> valid_read( old_file_name, (string)this_player()-> query( "name" ), "compress" ) ) { notify_fail( old_file_name + ": Permission denied.\n" ); return 0; } old_file = read_file( old_file_name ); if( !old_file ) { notify_fail( old_file_name + " is empty.\n" ); return 0; } if( !master()-> valid_write( new_file_name, (string)this_player()-> query( "name" ), "compress" ) ) { notify_fail( new_file_name + ": Permission denied.\n" ); return 0; } if( file_size( new_file_name ) != -1 ) { notify_fail( "compress: " + new_file_name + ": already exists.\n" ); return 0; } old_lines = explode( old_file, "\n" ); number_lines = sizeof( old_lines ); arg = ({ 0, /* line number to start on */ number_lines, /* the number of lines in the file */ old_lines, /* the file, as an array of its lines */ ({ }), /* an array for the new version to go into */ new_file_name, /* the file name for the compressed version */ this_player(), /* so messages can be given by the call_out */ 0, /* so text inside comment marks is unaltered */ });
int cmd_in(string str) { string room, cmd; mapping exits; object prev, act_ob,env; int s; if (!str || sscanf(str, "%s %s", room, cmd) != 2) { notify_fail("Usage:\tin <room|exit> <command>\n"); return 0; } env = environment(this_player()); act_ob = previous_object(); if (env) exits = env->query("exits"); if(!mapp(exits) || member_array(room,keys(exits)) == -1) { room = resolv_path((string)act_ob->query("cwd"), room); if (!room || ((s = strlen(room)) >= 2 && file_size( (room[s-2..s-1] == ".c") ? room : room + ".c") <= 0)) return 0; } else room = exits[room]; prev = environment(act_ob); if(act_ob->move(room) == MOVE_OK) { act_ob->force_me(cmd); act_ob->move(prev); return 1; } write("in: could not move to target.\n"); return 1; }
int cmd_rmdir(string str) { seteuid(geteuid(previous_object())); if( !str ) { return help(); } str = resolv_path(this_player()->get_path(), str); switch( file_size(str) ) { case -1: notify_fail("rmdir: "+str+": No such file.\n"); return 0; break; case -2: break; default: notify_fail("rmdir: "+str+": not a directory.\n"); return 0; break; } if( (int)master()->valid_write(str, this_object(), "rmdir") == 0 ) { notify_fail(str+": Permission denied.\n"); return 0; } write(rmdir(str) ? "Ok.\n" : str+": couldn't remove directory.\n"); IMSTAT_D->add_stat(this_player()->query_name(), "rmdir", time()); return 1; }
int cmd_du(string path) { seteuid(getuid(previous_object())); if (!path) path = (string)this_player()->get_path(); else path = resolv_path((string)this_player()->get_path(),path); disk_usage(path,0); return 1; }
varargs string *wild_card(string str, int keepdots) { string work; string *tmp, *pf; int i, s; // resolve pathname, with str either relative to cwd/absolute if ((work = resolv_path((string)this_object()->query("cwd"), str)) == "/") return ({ "/" }); /* Handle special case from resolv_path() */
int cmd_rmdir(string str) { int wipe; string rest; if (!str || str == "") { notify_fail( SYNTAX ); return 0; } if (origin() != ORIGIN_LOCAL) seteuid(geteuid(previous_object())); if (sscanf(str, "-r %s", str) == 1) wipe = 1; sscanf(str, "%s %s", str, rest); str = resolv_path("cwd", str); switch( file_size(str) ) { case -1: write("Rmdir: No such directory.\n"); return 1; break; // NOTREACHED case -2: break; default: write("Rmdir: Not a directory.\n"); return 1; break; // NOTREACHED } if ((int)master()->valid_write(str, geteuid(this_object())) == 0) { write("Rmdir: Permission denied.\n"); return 1; } if (wipe) { write("Are you sure you wish to remove \"" + str + "/\"? [y/n] "); input_to("remove_directory", 0, str, rest); return 1; } if (sizeof( get_dir(str + "/") )) { write("Rmdir: Directory is not empty.\n"); return 1; } write(rmdir(str) ? "Rmdir: Directory removed.\n" : "Rmdir: Could not remove directory.\n"); if (rest && rest != "") cmd_rmdir(rest); return 1; }
int cmd_destold(string str) { object ob, act_ob, *obs; string msg, opt; int clean, global, l, s; act_ob = previous_object(); seteuid(geteuid(act_ob)); notify_fail( SYNTAX ); if (!str || str == "") return 0; #ifdef GUEST_NO_DEST if (getuid(previous_object()) == "guest") { write ("Guest is not permitted to dest objects.\n") ; return 1 ; } #endif if (str == "all") return dest_all(act_ob, 0); if (sscanf(str, "-%s %s", opt, str) == 2) { if (strsrch(opt, 'a') != -1) clean = 1; if (strsrch(opt, 'g') != -1) global = 1; } if (global) { if (!adminp(geteuid(act_ob))) { write("Global Dest: Permission denied.\n"); return 1; } str = resolv_path("cwd", str); l = strlen(str); obs = objects(); s = sizeof(obs); write("Global destructing: " + str + "\n"); cnt = 0; while (s--) { if (!obs[s]) continue; if (strncmp(file_name(obs[s]), str, l) == 0) { if (clean) dest_all(obs[s], 1); cnt++; if (obs[s]) { catch(obs[s]->remove()); destruct(obs[s]); } } } write("object(s) destructed: " + cnt + "\n"); } else { if (!(ob = get_object(str))) {
int cmd_rehash(string path) { notify_fail("Rehash: Could not locate requested path.\n"); if(!path || path == "") path = this_player()->query("cwd"); else path = resolv_path("cwd", path); if(CMD_D->rehash(path)) { write("Rehash: " + path + " command table updated.\n"); return 1; } return 0; }
int cmd_gate(string str) { object prev, whatp, wherep; string prefix, loc, what, where, tmp_where; int ret; notify_fail(SYNTAX); // Parse the input into proper command request if( !str || str == "") return 0; if( sscanf(str, "%s in %s to %s", what, loc, where) != 3 && sscanf(str, "%s to %s", what, where) != 2 && sscanf(str, "%s %s", what, where) !=2) return 0; // Locate the object to be moved if(loc && loc != "") { if(get_object(loc)) whatp = present(what, get_object(loc)); } else whatp = get_object(what); if(!whatp) { write("Gate: Could not locate \"" + what + "\""); if(loc) write(" in \"" + loc + "\""); write(".\n"); return 1; } // See if you have permission to move the object if(wizardp(whatp) && whatp != this_player() && !adminp(geteuid(this_player()))) { write("You do not have permission to move that user.\n"); return 1; } // Locate where to move the object wherep = get_object(where); // Move living objects to environment, nonliving to actual object if(wherep && living(wherep) && living(whatp)) wherep = environment(wherep); if(!wherep) { tmp_where = resolv_path( "cwd", where ); catch( call_other( tmp_where, "???" ) ); // Load the poss. location
int cmd_convert(string s) { int i; string *f; if(!s || s == "") return notify_fail("Convert what file?\n"); s = resolv_path((string)this_player()->get_path(), s); if(!file_exists(s)) return notify_fail("No file to convert.\n"); i=sizeof(f=explode(read_file(s), "\n\r")); if(!i || i <= 1) return notify_fail("Error, couldnt find any Win32 line endings in the file.\n"); cp(s, s+".conv.bak"); rm(s); while(i--) { write_file(s, f[i]); } write("File written successfully. Original file backed up to *.conv.bak."); return 1; }
int cmd_tail(string file) { seteuid(getuid(previous_object())); if (!file) { notify_fail("usage: tail <file>\n"); return 0; } file = resolv_path(this_player()->query("cwd"), file); switch(file_size(file)) { case -2: notify_fail("tail: "+file+": directory\n"); return 0; case -1: notify_fail("tail: "+file+": no such file\n"); return 0; } tail(file); return 1; }
int cmd_load(string str) { mixed res; if(!str) { return help(); } seteuid( getuid( previous_object() ) ); str = resolv_path((string)this_player()->query("cwd"), str); if (extract(str, strlen(str)-2, strlen(str)-1) != ".c") str += ".c"; if (file_size(str) <= 0) { notify_fail("Load: " + str + " does not exist.\n"); return 0; } else write( (res=catch(call_other(str,"???")))?str+": "+res+"\n":"Ok.\n"); return 1; }
int cmd_goto(string str) { object ob; string tmp,flag ; int err; notify_fail( SYNTAX ); if(!str || str == "") return 0; if (sscanf(str,"%s %s",flag,tmp)==2) { if (flag!="-c") { notify_fail (flag+": unknown flag.\n") ; return 1 ; } str = tmp ; } if( ob = find_living(lower_case(str)) ) return goto_location( environment(ob) ); str = resolv_path("cwd", str); if (!flag || flag!="-c") { if(extract(str, strlen(str)-2, strlen(str)-1) != ".c") str += ".c"; if(!file_exists(str)) { write("Goto: No such location or living object found.\n"); return 1; } } err = catch( call_other(str, "???") ); // Load up the room if (!ob = find_object(str)) { write("Goto: Could not load " + str + "\n"); if(err) write(" " + err ); return 1; } goto_location( ob ); return 1; }
/* Raw 'cd' code used here */ int cd(string str) { str = resolv_path((string)this_player()->get_path(), str); if (sscanf(str,"//%s",temp) == 1) str = "/"+temp; if(!master()->valid_read(str, this_player(), "work")) { notify_fail(str+": permission denied\n"); return 0; } if (file_size(str) > -1) { notify_fail(str+": not a directory\n"); return 0; } if (file_size(str) == -1) { notify_fail(str+": no such file or directory\n"); return 0; } seteuid(getuid(previous_object())); this_player()->set_path(str); seteuid(getuid()); message("system", (string)this_player()->get_path() + ":", this_player()); return 1; }
int cmd_cat(string str) { string tmp; int max, a=0; if(!str) return notify_fail("Usage: <cat [file]>\n"); str = resolv_path((string)this_player()->get_path(), str); seteuid(geteuid(previous_object())); // if(!(max = sizeof(lines=explode(read_file(str), "\n")))) // return notify_fail("File not found.\n"); // if(!(tmp = read_file(str))) return notify_fail("File not found.\n"); if ((max = file_size(str)) < 0) return notify_fail("File not found.\n"); for (a = 0; a < max; a += 1025) { if( max - a < 1024 ) tmp = read_bytes(str, a, max - a); else tmp = read_bytes(str, a, 1024); write(tmp); } seteuid(getuid()); IMSTAT_D->add_stat(this_player()->query_name(), "cat", time()); return 1; }
int cmd_nog(string str) { mixed *tmp, *files; string flags, tpath, fpath, from, to, tmp1, tmp2; int loop, rflag, iflag, silent, dir_flag; seteuid( getuid(this_object()) ); notify_fail( SYNTAX ); if(!str || str == "") return 0; // Check for user requested flags if(sscanf(str, "-%s %s", flags, str) == 2) { if(sscanf(" " + flags + " ", "%sr%s", tmp1, tmp2) == 2) rflag = 1; if(sscanf(" " + flags + " ", "%si%s", tmp1, tmp2) == 2) iflag = 1; if(sscanf(" " + flags + " ", "%sf%s", tmp1, tmp2) == 2) iflag = 0; if(sscanf(" " + flags + " ", "%ss%s", tmp1, tmp2) == 2) silent = 1; } // Parse into source and destination if(sscanf(str, "%s to %s", from, to) != 2 && sscanf(str, "%s %s", from, to) !=2) return 0; // Check for use of "." for present dir copying if(to == ".") to = (string)this_player()->query("cwd"); // Check to see if the dest path is a directory. if(to[strlen(to)-1] == '/') dir_flag = 1; // Check for a directory cp request. if(from[strlen(from)-1] == '/') from += "*"; // Resolve paths of source and destination requests from = resolv_path("cwd", from); to = resolv_path("cwd", to); // Isolate source and destination directories fpath = get_path(from, 0); tpath = get_path(to ,dir_flag); // Check for existence of source and dest directories if(!directory_exists(fpath)) { write("Cp: No such directory : " + fpath + "\n"); return 1; } if(!directory_exists(tpath)) { write("Cp: No such directory : " + tpath + "\n"); return 1; } // Check user's permissions in source and dest directories /* if((int)master()->valid_read(fpath, previous_object(), "cp") == 0) { printf("Cp: Access denied in %s.\n", (fpath == "" ? "root directory" : fpath)); return 1; } if((int)master()->valid_write(tpath, previous_object(), "cp") == 0) { printf("Cp: Access denied in %s.\n", (tpath == "" ? "root directory" : tpath)); return 1; } */ // Process request for wildcard entry files = get_dir(from); files -= ({ "." }); files -= ({ ".." });
int cmd_ed(string file) { mixed *dir; int test; string tmp, err; if (in_edit(this_player())) { // get real! you can't do this! notify_fail("You are already editing a file.\n"); return 0; } // set our permissions. seteuid(geteuid(this_player())); // If they haven't given an arguement as to what file... if (!file) file=(string)this_player()->query("cwf"); if (!file) { write("Editing: [no file specified]\n"); ed(); return 1; } // get the filename to edit tmp = (string)this_player()->query("cwd"); file = resolv_path(tmp, file); // Check if there is such a directory .. dir = explode(file, "/"); if (file_size(implode( dir[0..sizeof(dir)-2], "/")) != -2) { write("Ed: No such directory file path.\n"); return 1; } // Check to make sure the file isn't actually a directory. if (directory_exists(file)) { notify_fail("Ed: Directory with that name already exists.\n"); return 0; } // Can we write here? err = catch( test = write_file(file, "") ); if (err) { write("Ed: Could not edit requested file.\n" + err ); return 1; } // now check and see if the file is being edited by someone else. if (test) { if (file_size(file) == 0) rm(file); if (!(file_lock(file, F_LOCK))) { // in this case, it is, so we make a temp copy. tmp = "/tmp/" + geteuid(this_player()) + "." + implode(explode(file, "/"), "_"); write("That file is being edited by " + capitalize(geteuid(query_lock_object(file))) + ".\n"); if (!(file_lock(tmp, F_LOCK))) { write("Ed: Unable to create temporary file.\n"); return 1; } // cp(file, tmp); // Is cp broken? if (file_size(tmp)) rm(tmp); if (file_size(file) > 0) write_file(tmp, read_file(file)); file = tmp; } } // Now let's make the message you see as you go into ed. tmp = "Editing: " + file; // Can we write here? err = catch( test = write_file(file, "") ); if (err) { write("Ed: Could not edit requested file.\n" + err ); file_lock(file, F_UNLOCK); return 1; } if (!test) tmp += " [read only]"; // is it new? else if (!file_size(file)) tmp += " [new file]"; tmp += "\n"; // write the message that we're editing a file... write(tmp); this_player()->set("cwf",file); // Yes, the evil admin logging... it can be circumvented, but // this tells us at least most of what gets changed. // actually, this would be better if it only logged when a crucial // file is actually changed. #ifdef ED_LOG tmp = capitalize(geteuid(TP)) + " : \"" + file + "\" "; if (!test) test += "[read only] "; tmp += "[" + extract(ctime(time()), 4, 15) + "]"; log_file(ED_LOG, wrap(tmp)); #endif // okay, let's invoke the editor, and have it go to the done function after. ed(file, "done_editing"); return 1; }
int cmd_ls(string arg) { int i; int active; string flags; string *output; seteuid(geteuid(previous_object())); if (!arg) arg = "-F "; else arg += " "; while (sscanf(arg, "-%s %s", flags, arg) > 1) { i = strlen(flags); while (i--) switch (flags[i]) { case 'F': active |= F_FLAG; break; case 's': active |= S_FLAG; break; case 'l': active |= L_FLAG; break; case 'a': active |= A_FLAG; break; case 't': active |= T_FLAG; break; case 'r': active |= R_FLAG; break; case 'x': active |= X_FLAG; break; case '1': active |= ONE_FLAG; break; case 'A': active |= CAP_A_FLAG; break; } } if (arg[<1..<1] == " ") arg = arg[0..<2]; if (arg == "/..") { write("ls: no such directory.\n"); return 1; } // Remove impossible flag combinations. if (active & L_FLAG) active &= ~S_FLAG; arg = resolv_path(this_player()->query("cwd"), arg); if (output = internal_ls(arg, active, 0)) { this_player()->more(output); } return 1; }
int cmd_update(string str) { object ob; string file, res, temp, *obs, logf; int i, deep_up, syslog_siz, mylog_siz; if (!str) str = (string)this_player()->query("cwf"); if (!str) { notify_fail("You have no current working file set.\n"); return 0; } if ( (strsrch(str,"/std/user#") != -1 ) || ( strsrch(str, "/std/connection#") != -1 ) ) { write("Updating a user or connection object isn't allowed!\n"); return 1; } if (str) // update the specified file { if(sscanf(str, "-r %s", temp)) { file = temp; deep_up = 1; } else if(sscanf(str, "-R %s", temp)) { file = temp; deep_up = 2; } else if(str == "-r") { file = 0; deep_up = 1; } else if(str == "-R") { file = 0; deep_up = 2; } else file = str; } // if(str) if(!file) { if(!environment(this_player())) { notify_fail("Update: You don't have an environment.\n"); return 0; } file = file_name(environment(this_player())); } else file = resolv_path("cwd", file); // Make sure that a ".c" is appended on the filename if(extract(file, strlen(file)-2, strlen(file)-1) != ".c") file += ".c"; this_player()->set("cwf",file); logf = (string) this_player()->query("name"); logf=user_path(logf) + "log"; // assume if can use update, has a name mylog_siz = file_size(logf); syslog_siz = file_size(LOG_DIR + "log"); seteuid(geteuid(previous_object())); /* Beek 091993 - doesn't dest virtual objects now */ if (find_object(file) && virtualp(find_object(file))) { notify_fail("That object is virtual and cannot be updated.\n"); return 0; } if(!file_exists(file)) { if(find_object(file)) { destruct(find_object(file)); notify_fail("Update: " + file + " does not exist.\n\tLoaded " + "copy of file removed from memory.\n"); } else notify_fail("Update: " + file + " does not exist.\n"); return 0; } ob = find_object(file); if (!ob) { res = catch(file->apply_load()); if(res) { display_errs(mylog_siz, logf); display_errs(syslog_siz, LOG_DIR + "log"); notify_fail("Failure to load object.\n"); return 0; } ob = find_object(file); }