access_table() challenge status

Andrew Tridgell tridge at
Tue Jan 18 11:59:26 GMT 2000

Thanks for all the contributions!

The submission from Paul Mackerras is the leader so far. Mattys
submission would be the best (by a long way!) if it handled the
DENY_FCB case. Mattys certainly gives the most insight into how this
stuff works.

Here is Mattys in case anyone missed it. It is very simple
conceptually (only two ugly conditionals) but doesn't even attempt

static BOOL is_compatible(int old_deny, int old_mode, int new_deny,
                        int new_mode, BOOL same_process, BOOL is_exe)
        switch (old_deny) {
                case DENY_ALL:
                        return 0;
                case DENY_NONE:
                        return 1;
                case DENY_READ:
                        return (new_mode == DOS_OPEN_WRONLY);
                case DENY_WRITE:
                        return (new_mode == DOS_OPEN_RDONLY);
                case DENY_DOS:
                        return is_exe || ((old_mode == DOS_OPEN_RDONLY)
                                        && (new_mode == DOS_OPEN_RDONLY))
                                || (same_process && (old_deny == DENY_DOS)
                                        && (new_deny == DENY_DOS));

static BOOL is_allowed(int new_deny, int new_mode, int old_deny,
                        int old_mode, BOOL same_process, BOOL is_exe)
        if ((old_deny == DENY_DOS) && (old_mode == DOS_OPEN_RDONLY)
                && (new_mode != DOS_OPEN_RDONLY) && same_process && !is_exe)
                return 0;

        return is_compatible(old_deny, old_mode, new_deny, new_mode,
                                                same_process, is_exe)
                && is_compatible(new_deny, new_mode, old_deny, old_mode,
                                                same_process, is_exe);

static int access_table2(int new_deny,int old_deny,int old_mode,
			 BOOL same_pid, BOOL isexe)
	BOOL r, w;

	r = is_allowed(new_deny, DOS_OPEN_RDONLY, old_deny, old_mode, same_pid,
	w = is_allowed(new_deny, DOS_OPEN_WRONLY, old_deny, old_mode, same_pid,
	if (r && w) return AALL;
	if (r) return AREAD;
	if (w) return AWRITE;
	return AFAIL;

More information about the samba-technical mailing list