MudOS 对象操作函数代码分析及潜在问题
// object.c
varargs int getoid(object ob) { int id;
if (!ob) ob = previous_object();
sscanf(file_name(ob), '%*s#%d', id);
return id;
}
// Get the owner of a file. Used by log_error() in master.c. string file_owner(string file) { string name, rest, dir;
if (file[0] != '/')
{
file = '/' + file;
}
if (sscanf(file, '/u/%s/%s/%s', dir, name, rest) == 3)
{
return name;
}
return 0;
}
// domain_file should return the domain associated with a given file. string domain_file(string file) { string domain;
if (sscanf(file, '/d/%s/%*s', domain))
return domain;
return ROOT_UID;
}
// creator_file should return the name of the creator of a specific file. string creator_file(string file) { string *path;
path = explode(file, '/') - ({ 0 });
switch (path[0])
{
case 'adm':
if (file == SIMUL_EFUN_OB) return 'MudOS';
else return ROOT_UID;
case 'cmds':
case 'shadow':
return ROOT_UID;
case 'u':
if (sizeof(path) >= 3) return path[1];
case 'd':
return 'Domain';
case 'clone':
return 'Clone';
case 'feature':
return 'Feature';
case 'kungfu':
return 'Kungfu';
case 'inherit':
return 'Inherit';
default:
return 'Unknow';
}
}
// author_file should return the name of the author of a specific file. string author_file(string file) { string name;
if (sscanf(file, '/u/%*s/%s/%*s', name))
return name;
return ROOT_UID;
}
// check the object's euid wehter is root int is_root(mixed ob) { if (stringp(ob)) return (SECURITY_D->get_status(ob) == '(admin)');
if (objectp(ob))
{
if (geteuid(ob) == ROOT_UID)
// Root object want to execute
return 1;
return (SECURITY_D->get_status(geteuid(ob)) == '(admin)');
}
return 1;
}
void destruct(object ob) { if (ob) { if (previous_object()) ob->remove(geteuid(previous_object())); else ob->remove(0); } if(environment(ob)) tell_room(environment(ob),ZJOBOUT+'look '+file_name(ob)+' '); efun::destruct(ob); }
object present( mixed str, object ob ) { object obj;
if(!ob&&previous_object())
{
ob = environment(previous_object());
}
if(stringp(str)&&(obj=find_object(str)))
{
if(ob) return efun::present(obj,ob);
else return efun::present(obj);
}
if(ob) return efun::present(str,ob);
else return efun::present(str);
}
这段代码主要是一些关于对象操作的函数。其中,getoid()函数用于获取对象的id,file_owner()函数用于获取文件的拥有者,domain_file()函数用于获取文件所属的域名,creator_file()函数用于获取创建该文件的用户,author_file()函数用于获取文件的作者。is_root()函数用于检测当前对象是否为root对象。destruct()函数用于销毁对象,并在销毁之前通知其所在的环境。present()函数用于查找当前环境中是否存在某个对象。
在这些函数中,可能存在一些潜在的逻辑问题和bug,比如:
-
在getoid()函数中,sscanf()函数的参数可能存在问题,未考虑到某些特殊情况,可能会导致获取的id不正确。
-
在file_owner()函数中,如果文件名不是以'/'开头,会自动添加'/',可能会导致路径错误。
-
在creator_file()函数中,对于某些文件,可能会返回错误的创建者。
-
在present()函数中,对于字符串类型的参数,可能会找到错误的对象。
需要对这些函数进行进一步的测试和调试,确保其正确性。
原文地址: https://www.cveoy.top/t/topic/m5za 著作权归作者所有。请勿转载和采集!