Branch: Tag:

2001-09-11

2001-09-11 15:17:19 by Per Hedbor <ph@opera.com>

Use the new AUTH API

Rev: server/modules/filesystems/filesystem.pike:1.111

7:   inherit "module";   inherit "socket";    - constant cvs_version= "$Id: filesystem.pike,v 1.110 2001/09/11 12:12:52 grubba Exp $"; + constant cvs_version= "$Id: filesystem.pike,v 1.111 2001/09/11 15:17:19 per Exp $";   constant thread_safe=1;      #include <module.h>
226:   #define FILTER_INTERNAL_FILE(f, id) \    (!id->misc->internal_get && sizeof (filter (internal_files, glob, (f/"/")[-1])))    + #define SETUID(X) \ +  if( access_as_user ) \ +  { \ +  User uid = id->conf->authenticate( id ); \ +  if( uid && uid->uid() ) \ +  privs=Privs(X, uid->uid(), uid->gid() ); \ +  } +    mixed stat_file( string f, RequestID id )   {    Stat fs;
242:    (fs=cache_lookup("stat_cache",f)))    return fs[0];    object privs; -  if (access_as_user && ((int)id->misc->uid) && ((int)id->misc->gid)) -  // NB: Root-access is prevented. -  privs=Privs("Statting file", (int)id->misc->uid, (int)id->misc->gid ); +  SETUID("Statting file");       /* No security currently in this function */    fs = file_stat(decode_path(f));
282:    (id->misc->internal_get ? " (internal)" : ""));       object privs; +  SETUID("Read dir");    -  if (((int)id->misc->uid) && ((int)id->misc->gid) && access_as_user ) -  // NB: Root-access is prevented. -  privs=Privs("Getting dir", (int)id->misc->uid, (int)id->misc->gid ); -  +     if (catch {    f = NORMALIZE_PATH(decode_path(path + f));    } || !(dir = get_dir(f))) {
565:    TRACE_ENTER("Opening file \"" + f + "\"", 0);       object privs; -  if (access_as_user && -  ((int)id->misc->uid) && ((int)id->misc->gid)) -  // NB: Root-access is prevented. -  privs=Privs("Getting file", (int)id->misc->uid, (int)id->misc->gid ); +  SETUID("Open file");       o = Stdio.File( );    if(!o->open(norm_f, "r" )) o = 0;
625:    }    mkdirs++;    object privs; +  SETUID("Creating file");    -  if (((int)id->misc->uid) && ((int)id->misc->gid)) { -  // NB: Root-access is prevented. -  privs=Privs("Creating directory", -  (int)id->misc->uid, (int)id->misc->gid ); -  } -  +     if (query("no_symlinks") && (contains_symlinks(path, oldf))) {    privs = 0;    errors++;
692:    }       -  if (((int)id->misc->uid) && ((int)id->misc->gid)) { -  // NB: Root-access is prevented. -  privs=Privs("Saving file", (int)id->misc->uid, (int)id->misc->gid ); -  } +  SETUID("Saving file");       if (query("no_symlinks") && (contains_symlinks(path, oldf))) {    privs = 0;
795:    }       -  if (((int)id->misc->uid) && ((int)id->misc->gid)) { -  // NB: Root-access is prevented. -  privs=Privs("CHMODing file", (int)id->misc->uid, (int)id->misc->gid ); -  } +  SETUID("CHMODing file");       if (query("no_symlinks") && (contains_symlinks(path, oldf))) {    privs = 0;
875:    return 0;    }    -  if (((int)id->misc->uid) && ((int)id->misc->gid)) { -  // NB: Root-access is prevented. -  privs=Privs("Moving file", (int)id->misc->uid, (int)id->misc->gid ); -  } +  SETUID("Moving file");       if (query("no_symlinks") &&    ((contains_symlinks(path, oldf)) ||
977:    return 0;    }    -  if (((int)id->misc->uid) && ((int)id->misc->gid)) { -  // NB: Root-access is prevented. -  privs=Privs("Moving file", (int)id->misc->uid, (int)id->misc->gid ); -  } +  SETUID("Moving file");       if (query("no_symlinks") &&    ((contains_symlinks(path, f)) ||
1045:    report_notice(LOCALE(49,"DELETING the file %s.\n"),f);    accesses++;    -  if (((int)id->misc->uid) && ((int)id->misc->gid)) { -  // NB: Root-access is prevented. -  privs=Privs("Deleting file", id->misc->uid, id->misc->gid ); -  } +  SETUID("Deleting file");       /* Clear the stat-cache for this file */    if (stat_cache) {