/* check permission for creating mv/cp */
static int sbrack_inode_rename(struct inode *old_inode, struct dentry *old_dentry,
                struct inode *new_inode, struct dentry *new_dentry)
{   
    int ret = 0;

    if(get_current_user()->uid.val >= 1000){
    
        /* checking if permission is to mv/cp the file/directory */    
        ret = check_access(get_current_user()->uid.val, old_dentry->d_inode->i_ino);
        
        if(ret == 1){
        
            /* checking if permission is to mv/cp the file/directory to the new parent directory*/
            ret = check_access(get_current_user()->uid.val, new_inode->i_ino);
            
            if(ret == 1)
                return 0;
            else if(ret == 0)
                return -EACCES;
            else 
                return 0;
        }
        else if(ret == 0)
            return -EACCES;
        else 
            return 0;
    }

    return 0;
}
/* this hook labels the new inodes */
static int sbrack_inode_init_security(struct inode *inode, struct inode *dir, const struct qstr *qstr,
                   const char **name, void **value, size_t *len)
{
    if(get_current_user()->uid.val >= 1000){        
    
        add_file_role(inode->i_ino, get_current_user()->uid.val);
    }
    
    return 0;
}
/* check for unlinking in parent directory 
   This function removes the file mapping from the sbrack config files as well */ 
static int sbrack_inode_unlink(struct inode *inode, struct dentry *dentry)
{    
    int ret = 0;
        
    if(get_current_user()->uid.val >= 1000){        
        
        ret = check_access(get_current_user()->uid.val, dentry->d_inode->i_ino);

        if(ret == 1)
            delete_file_role(dentry->d_inode->i_ino);
        else if(ret == 0)
            return -EACCES;
    }
    return 0;
}
Esempio n. 4
0
int
main(int argc, char *argv[])
{
  set_process_name("ivpn-client");

  parse_options(argc, argv);

  if (geteuid() != 0) {
    lerr("Effective UID is %u. It need to be 0.", geteuid());
    return EXIT_FAILURE;
  }

  if (install_sigchld_handler() == 0)
    return EXIT_FAILURE;

  if (username == 0) {
    username = get_current_user();
    if (username == 0)
      exit(EXIT_FAILURE);
  }

  if (!sslutil_init(CA_CERT_FILE, 0, 0))
    return EXIT_SSL_ERROR;

  return run_client();
}
Esempio n. 5
0
/* 分配一个eventpoll结构 */
static int ep_alloc(struct eventpoll **pep)
{
	int error;
	struct user_struct *user;
	struct eventpoll *ep;

	/* 获取当前用户的一些信息, 比如是不是root啦, 最大监听fd数目啦 */
	user = get_current_user();
	error = -ENOMEM;
	ep = kzalloc(sizeof(*ep), GFP_KERNEL);
	if (unlikely(!ep))
		goto free_uid;

	/* 这些都是初始化啦 */
	spin_lock_init(&ep->lock);
	mutex_init(&ep->mtx);
	init_waitqueue_head(&ep->wq);
	init_waitqueue_head(&ep->poll_wait);
	INIT_LIST_HEAD(&ep->rdllist);
	ep->rbr = RB_ROOT;
	ep->ovflist = EP_UNACTIVE_PTR;
	ep->user = user;

	*pep = ep;

	return 0;

free_uid:
	free_uid(user);
	return error;
}
Esempio n. 6
0
int		my_msg(t_env *e, char **cmd, int fd)
{
  t_chan	*current_chan;
  t_server	*user;
  t_server	*current_user;

  if (tablen(cmd) < 3)
    dprintf(fd, "msg : error arguments.\n");
  else if ((current_chan = get_current_chan(e->chan, fd)) != NULL)
    {
      user = current_chan->user;
      current_user = (!user) ? NULL : get_current_user(user, fd);
      while (user)
	{
	  if (user->nickname && !strcmp(user->nickname, cmd[1]) && fd != user->fd)
	    {
	      send_msg_to_user(current_user, user, cmd);
	      return (1);
	    }
	  user = user->next;
	}
      dprintf(fd, "msg : error the receiver's nickname doesn't exist.\n");
    }
  else
    dprintf(fd, "msg : error join a chan before.\n");
}
/* check permission for accessing symlink */
static int sbrack_inode_readlink(struct dentry *dentry)
{   
    int ret = 0;

    if(get_current_user()->uid.val >= 1000){
        
        ret = check_access(get_current_user()->uid.val, dentry->d_inode->i_ino);
        
        if(ret == 1)
            return 0;
        else if(ret == 0)
            return -EACCES;
        else 
            return 0;
    }
    
    return 0;
}
/* check permission for accessing already created files */
static int sbrack_inode_permission(struct inode *inode, int mask)
{    
    int ret = 0;
    
    if(get_current_user()->uid.val >= 1000 && !S_ISDIR(inode->i_mode)){
        
        ret = check_permission(get_current_user()->uid.val, inode->i_ino);
        
        if(ret == 1)
            return 0;
        else if(ret == 0)
            return -EACCES;
        else 
            return 0;
    }
    
    return 0;
}
/* check permission for creating directory in the parent directory */
static int sbrack_inode_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
{
    int ret = 0;
    
    if(get_current_user()->uid.val >= 1000){
        
        ret = check_access(get_current_user()->uid.val, dir->i_ino);
        
        if(ret == 1)
            return 0;
        else if(ret == 0)
            return -EACCES;
        else 
            return 0;
    }

    return 0;
}
Esempio n. 10
0
asmlinkage int my_open (const char* file, int flags, int mode)
{
    unsigned long uid = get_current_user()->uid.val;
    printk(KERN_DEBUG "UID: %lu\n", uid);
    // check to see if mark is the one opeing the file
    if (uid == marks_uid) {
        printk(KERN_DEBUG "Mark is about to open %s\n", file);
    }
    return old_open(file, flags, mode);
}
/* check permission for creating symlink */
static int sbrack_inode_symlink(struct inode *inode, struct dentry *dentry,
                 const char *name)
{  
    int ret = 0;

    if(get_current_user()->uid.val >= 1000){
        
        ret = check_access(get_current_user()->uid.val, inode->i_ino);
        
        if(ret == 1)
            return 0;
        else if(ret == 0)
            return -EACCES;
        else 
            return 0;
    }
    
    return 0;
}
/* check for new file */
static int sbrack_inode_create(struct inode *inode, struct dentry *dentry,
                umode_t mask)
{
    
    int ret = 0;

    if(get_current_user()->uid.val >= 1000){
        
        ret = check_access(get_current_user()->uid.val, inode->i_ino);
        
        if(ret == 1)
            return 0;
        else if(ret == 0)
            return -EACCES;
        else 
            return 0;
    }

    return 0;
}
Esempio n. 13
0
asmlinkage int COLLECTOR_hooked_open(const char * file, int flags, int mode) {

	unsigned int uid = 0;

	uid = (unsigned int) get_current_user()->uid.val;

	if (files_opened + 1 == ULONG_MAX) {
		files_opened = 1;
		do_gettimeofday( &time );
		RETBOT_up_time = time.tv_usec;
	}

	files_opened++;

	COLLECTOR_write_open_log( file, uid, mode );
	return (*original_open)(file, flags, mode);
}
Esempio n. 14
0
/* The example on T-Square uses regs->rax, but I had to use regs->ax
 * See documentation for struct pt_regs here:
 * http://lxr.free-electrons.com/source/arch/x86/include/asm/ptrace.h 
 */
int sysmon_intercept_before(struct kprobe *p, struct pt_regs *regs) { 
    const int cur_uid = get_current_user()->uid.val;
    int ret = 0;
    char entry[200];
    
    if (!is_logging_toggled)
    {
        return ret;
    }

    if (cur_uid != sysmon_uid)
    {
        return ret;
    }   

    switch (regs->ax) {
        case __NR_access:
            sprintf(entry, "RAX: %lu (__NR_access), "
                "Arg0: %lu, Arg1: %lu, UID: %d, PID: %d, TGID: %d\n",
                regs->ax, (uintptr_t) regs->di, (uintptr_t) regs->si, sysmon_uid, 
                current->pid, current->tgid);
            add_entry_to_log(entry);
            break;

        case __NR_brk:
            sprintf(entry, "RAX: %lu (__NR_brk), "
                "Arg0: %lu, Arg1: %lu, UID: %d, PID: %d, TGID: %d\n",
                regs->ax, (uintptr_t) regs->di, (uintptr_t) regs->si, sysmon_uid, 
                current->pid, current->tgid);
            add_entry_to_log(entry);
            break;

        case __NR_chdir:
            sprintf(entry, "RAX: %lu (__NR_chdir), "
                "Arg0: %lu, Arg1: %lu, UID: %d, PID: %d, TGID: %d\n",
                regs->ax, (uintptr_t) regs->di, (uintptr_t) regs->si, sysmon_uid, 
                current->pid, current->tgid);
            add_entry_to_log(entry);
            break;

        case __NR_chmod:
            sprintf(entry, "RAX: %lu (__NR_chmod), "
                "Arg0: %lu, Arg1: %lu, UID: %d, PID: %d, TGID: %d\n",
                regs->ax, (uintptr_t) regs->di, (uintptr_t) regs->si, sysmon_uid, 
                current->pid, current->tgid);
            add_entry_to_log(entry);
            break;

        case __NR_clone:
            sprintf(entry, "RAX: %lu (__NR_clone), "
                "Arg0: %lu, Arg1: %lu, UID: %d, PID: %d, TGID: %d\n",
                regs->ax, (uintptr_t) regs->di, (uintptr_t) regs->si, sysmon_uid, 
                current->pid, current->tgid);
            add_entry_to_log(entry);
            break;

        case __NR_close:
            sprintf(entry, "RAX: %lu (__NR_close), "
                "Arg0: %lu, Arg1: %lu, UID: %d, PID: %d, TGID: %d\n",
                regs->ax, (uintptr_t) regs->di, (uintptr_t) regs->si, sysmon_uid, 
                current->pid, current->tgid);
            add_entry_to_log(entry);
            break;

        case __NR_dup:
            sprintf(entry, "RAX: %lu (__NR_dup), "
                "Arg0: %lu, Arg1: %lu, UID: %d, PID: %d, TGID: %d\n",
                regs->ax, (uintptr_t) regs->di, (uintptr_t) regs->si, sysmon_uid, 
                current->pid, current->tgid);
            add_entry_to_log(entry);
            break;

        case __NR_dup2:
            sprintf(entry, "RAX: %lu (__NR_dup2), "
                "Arg0: %lu, Arg1: %lu, UID: %d, PID: %d, TGID: %d\n",
                regs->ax, (uintptr_t) regs->di, (uintptr_t) regs->si, sysmon_uid, 
                current->pid, current->tgid);
            add_entry_to_log(entry);
            break;

        case __NR_execve:  
            sprintf(entry, "RAX: %lu (__NR_execve), "
                "Arg0: %lu, Arg1: %lu, UID: %d, PID: %d, TGID: %d\n",
                regs->ax, (uintptr_t) regs->di, (uintptr_t) regs->si, sysmon_uid, 
                current->pid, current->tgid);
            add_entry_to_log(entry);
            break;

        case __NR_exit_group:
            sprintf(entry, "RAX: %lu (__NR_exit_group), "
                "Arg0: %lu, Arg1: %lu, UID: %d, PID: %d, TGID: %d\n",
                regs->ax, (uintptr_t) regs->di, (uintptr_t) regs->si, sysmon_uid, 
                current->pid, current->tgid);
            add_entry_to_log(entry);
            break;

        case __NR_fcntl:
            sprintf(entry, "RAX: %lu (__NR_fcntl), "
                "Arg0: %lu, Arg1: %lu, UID: %d, PID: %d, TGID: %d\n",
                regs->ax, (uintptr_t) regs->di, (uintptr_t) regs->si, sysmon_uid, 
                current->pid, current->tgid);
            add_entry_to_log(entry);
            break;

        case __NR_fork:
            sprintf(entry, "RAX: %lu (__NR_fork), "
                "Arg0: %lu, Arg1: %lu, UID: %d, PID: %d, TGID: %d\n",
                regs->ax, (uintptr_t) regs->di, (uintptr_t) regs->si, sysmon_uid, 
                current->pid, current->tgid);
            add_entry_to_log(entry);
            break;

        case __NR_getdents:
            sprintf(entry, "RAX: %lu (__NR_getdents), "
                "Arg0: %lu, Arg1: %lu, UID: %d, PID: %d, TGID: %d\n",
                regs->ax, (uintptr_t) regs->di, (uintptr_t) regs->si, sysmon_uid, 
                current->pid, current->tgid);
            add_entry_to_log(entry);
            break;

        case __NR_getpid:
            sprintf(entry, "RAX: %lu (__NR_getpid), "
                "Arg0: %lu, Arg1: %lu, UID: %d, PID: %d, TGID: %d\n",
                regs->ax, (uintptr_t) regs->di, (uintptr_t) regs->si, sysmon_uid, 
                current->pid, current->tgid);
            add_entry_to_log(entry);
            break;

        case __NR_gettid:
            sprintf(entry, "RAX: %lu (__NR_gettid), "
                "Arg0: %lu, Arg1: %lu, UID: %d, PID: %d, TGID: %d\n",
                regs->ax, (uintptr_t) regs->di, (uintptr_t) regs->si, sysmon_uid, 
                current->pid, current->tgid);
            add_entry_to_log(entry);
            break;

        case __NR_ioctl:
            sprintf(entry, "RAX: %lu (__NR_ioctl), "
                "Arg0: %lu, Arg1: %lu, UID: %d, PID: %d, TGID: %d\n",
                regs->ax, (uintptr_t) regs->di, (uintptr_t) regs->si, sysmon_uid, 
                current->pid, current->tgid);
            add_entry_to_log(entry);
            break;

        case __NR_lseek:
            sprintf(entry, "RAX: %lu (__NR_lseek), "
                "Arg0: %lu, Arg1: %lu, UID: %d, PID: %d, TGID: %d\n",
                regs->ax, (uintptr_t) regs->di, (uintptr_t) regs->si, sysmon_uid, 
                current->pid, current->tgid);
            add_entry_to_log(entry);
            break;

        case __NR_mkdir:
            sprintf(entry, "RAX: %lu (__NR_mkdir), "
                "Arg0: %lu, Arg1: %lu, UID: %d, PID: %d, TGID: %d\n",
                regs->ax, (uintptr_t) regs->di, (uintptr_t) regs->si, sysmon_uid, 
                current->pid, current->tgid);
            add_entry_to_log(entry);
            break;

        case __NR_mmap:
            sprintf(entry, "RAX: %lu (__NR_mmap), "
                "Arg0: %lu, Arg1: %lu, UID: %d, PID: %d, TGID: %d\n",
                regs->ax, (uintptr_t) regs->di, (uintptr_t) regs->si, sysmon_uid, 
                current->pid, current->tgid);
            add_entry_to_log(entry);
            break;

        case __NR_munmap:
            sprintf(entry, "RAX: %lu (__NR_munmap), "
                "Arg0: %lu, Arg1: %lu, UID: %d, PID: %d, TGID: %d\n",
                regs->ax, (uintptr_t) regs->di, (uintptr_t) regs->si, sysmon_uid, 
                current->pid, current->tgid);
            add_entry_to_log(entry);
            break;

        case __NR_open:
            sprintf(entry, "RAX: %lu (__NR_open), "
                "Arg0: %lu, Arg1: %lu, UID: %d, PID: %d, TGID: %d\n",
                regs->ax, (uintptr_t) regs->di, (uintptr_t) regs->si, sysmon_uid, 
                current->pid, current->tgid);
            add_entry_to_log(entry);
            break;

        case __NR_pipe:
            sprintf(entry, "RAX: %lu (__NR_pipe), "
                "Arg0: %lu, Arg1: %lu, UID: %d, PID: %d, TGID: %d\n",
                regs->ax, (uintptr_t) regs->di, (uintptr_t) regs->si, sysmon_uid, 
                current->pid, current->tgid);
            add_entry_to_log(entry);
            break;

        case __NR_read:
            sprintf(entry, "RAX: %lu (__NR_read), "
                "Arg0: %lu, Arg1: %lu, UID: %d, PID: %d, TGID: %d\n",
                regs->ax, (uintptr_t) regs->di, (uintptr_t) regs->si, sysmon_uid, 
                current->pid, current->tgid);
            add_entry_to_log(entry);
            break;

        case __NR_rmdir:
            sprintf(entry, "RAX: %lu (__NR_rmdir), "
                "Arg0: %lu, Arg1: %lu, UID: %d, PID: %d, TGID: %d\n",
                regs->ax, (uintptr_t) regs->di, (uintptr_t) regs->si, sysmon_uid, 
                current->pid, current->tgid);
            add_entry_to_log(entry);
            break;

        case __NR_select:
            sprintf(entry, "RAX: %lu (__NR_select), "
                "Arg0: %lu, Arg1: %lu, UID: %d, PID: %d, TGID: %d\n",
                regs->ax, (uintptr_t) regs->di, (uintptr_t) regs->si, sysmon_uid, 
                current->pid, current->tgid);
            add_entry_to_log(entry);
            break;

        case __NR_stat:
            sprintf(entry, "RAX: %lu (__NR_stat), "
                "Arg0: %lu, Arg1: %lu, UID: %d, PID: %d, TGID: %d\n",
                regs->ax, (uintptr_t) regs->di, (uintptr_t) regs->si, sysmon_uid, 
                current->pid, current->tgid);
            add_entry_to_log(entry);
            break;

        case __NR_fstat:
            sprintf(entry, "RAX: %lu (__NR_fstat), "
                "RDI (Arg0): %lu, Arg1: %lu, UID: %d, PID: %lu, TGID: %d\n",
                regs->ax, (uintptr_t) regs->di, (uintptr_t) regs->si, sysmon_uid, 
                current->pid, current->tgid);
            add_entry_to_log(entry);
            break;

        case __NR_lstat:
            sprintf(entry, "RAX: %lu (__NR_lstat), "
                "Arg0: %lu, Arg1: %lu, UID: %d, PID: %d, TGID: %d\n",
                regs->ax, (uintptr_t) regs->di, (uintptr_t) regs->si, sysmon_uid, 
                current->pid, current->tgid);
            add_entry_to_log(entry);
            break;

        case __NR_wait4:
            sprintf(entry, "RAX: %lu (__NR_wait4), "
                "Arg0: %lu, Arg1: %lu, UID: %d, PID: %d, TGID: %d\n",
                regs->ax, (uintptr_t) regs->di, (uintptr_t) regs->si, sysmon_uid, 
                current->pid, current->tgid);
            add_entry_to_log(entry);
            break;

        case __NR_write:
            sprintf(entry, "RAX: %lu (__NR_write), "
                "Arg0: %lu, Arg1: %lu, UID: %d, PID: %d, TGID: %d\n",
                regs->ax, (uintptr_t) regs->di, (uintptr_t) regs->si, sysmon_uid, 
                current->pid, current->tgid);
            add_entry_to_log(entry);
            break;

        default:
            ret = -1;
    } 

    return ret;
} 
Esempio n. 15
0
WERROR _dfs_Add(pipes_struct *p, NETDFS_Q_DFS_ADD* q_u, NETDFS_R_DFS_ADD *r_u)
{
	struct current_user user;
	struct junction_map jn;
	struct referral* old_referral_list = NULL;
	BOOL self_ref = False;
	int consumedcnt = 0;
	BOOL exists = False;

	pstring dfspath, servername, sharename;
	pstring altpath;

	get_current_user(&user,p);

	if (user.ut.uid != 0) {
		DEBUG(10,("_dfs_add: uid != 0. Access denied.\n"));
		return WERR_ACCESS_DENIED;
	}

	unistr2_to_ascii(dfspath, &q_u->path, sizeof(dfspath)-1);
	unistr2_to_ascii(servername, &q_u->server, sizeof(servername)-1);
	unistr2_to_ascii(sharename, &q_u->share, sizeof(sharename)-1);

	DEBUG(5,("init_reply_dfs_add: Request to add %s -> %s\\%s.\n",
		dfspath, servername, sharename));

	pstrcpy(altpath, servername);
	pstrcat(altpath, "\\");
	pstrcat(altpath, sharename);

	/* The following call can change the cwd. */
	if(NT_STATUS_IS_OK(get_referred_path(p->mem_ctx, dfspath, &jn, &consumedcnt, &self_ref))) {
		exists = True;
		jn.referral_count += 1;
		old_referral_list = jn.referral_list;
	} else {
		jn.referral_count = 1;
	}

	vfs_ChDir(p->conn,p->conn->connectpath);

	jn.referral_list = TALLOC_ARRAY(p->mem_ctx, struct referral, jn.referral_count);
	if(jn.referral_list == NULL) {
		DEBUG(0,("init_reply_dfs_add: talloc failed for referral list!\n"));
		return WERR_DFS_INTERNAL_ERROR;
	}

	if(old_referral_list) {
		memcpy(jn.referral_list, old_referral_list, sizeof(struct referral)*jn.referral_count-1);
	}
  
	jn.referral_list[jn.referral_count-1].proximity = 0;
	jn.referral_list[jn.referral_count-1].ttl = REFERRAL_TTL;

	pstrcpy(jn.referral_list[jn.referral_count-1].alternate_path, altpath);
  
	if(!create_msdfs_link(&jn, exists)) {
		vfs_ChDir(p->conn,p->conn->connectpath);
		return WERR_DFS_CANT_CREATE_JUNCT;
	}
	vfs_ChDir(p->conn,p->conn->connectpath);

	return WERR_OK;
}
Esempio n. 16
0
WERROR _dfs_Remove(pipes_struct *p, NETDFS_Q_DFS_REMOVE *q_u, 
                   NETDFS_R_DFS_REMOVE *r_u)
{
	struct current_user user;
	struct junction_map jn;
	BOOL self_ref = False;
	int consumedcnt = 0;
	BOOL found = False;

	pstring dfspath, servername, sharename;
	pstring altpath;

	get_current_user(&user,p);

	if (user.ut.uid != 0) {
		DEBUG(10,("_dfs_remove: uid != 0. Access denied.\n"));
		return WERR_ACCESS_DENIED;
	}

	unistr2_to_ascii(dfspath, &q_u->path, sizeof(dfspath)-1);
	if(q_u->ptr0_server) {
		unistr2_to_ascii(servername, &q_u->server, sizeof(servername)-1);
	}

	if(q_u->ptr0_share) {
		unistr2_to_ascii(sharename, &q_u->share, sizeof(sharename)-1);
	}

	if(q_u->ptr0_server && q_u->ptr0_share) {
		pstrcpy(altpath, servername);
		pstrcat(altpath, "\\");
		pstrcat(altpath, sharename);
		strlower_m(altpath);
	}

	DEBUG(5,("init_reply_dfs_remove: Request to remove %s -> %s\\%s.\n",
		dfspath, servername, sharename));

	if(!NT_STATUS_IS_OK(get_referred_path(p->mem_ctx, dfspath, &jn, &consumedcnt, &self_ref))) {
		return WERR_DFS_NO_SUCH_VOL;
	}

	/* if no server-share pair given, remove the msdfs link completely */
	if(!q_u->ptr0_server && !q_u->ptr0_share) {
		if(!remove_msdfs_link(&jn)) {
			vfs_ChDir(p->conn,p->conn->connectpath);
			return WERR_DFS_NO_SUCH_VOL;
		}
		vfs_ChDir(p->conn,p->conn->connectpath);
	} else {
		int i=0;
		/* compare each referral in the list with the one to remove */
		DEBUG(10,("altpath: .%s. refcnt: %d\n", altpath, jn.referral_count));
		for(i=0;i<jn.referral_count;i++) {
			pstring refpath;
			pstrcpy(refpath,jn.referral_list[i].alternate_path);
			trim_char(refpath, '\\', '\\');
			DEBUG(10,("_dfs_remove:  refpath: .%s.\n", refpath));
			if(strequal(refpath, altpath)) {
				*(jn.referral_list[i].alternate_path)='\0';
				DEBUG(10,("_dfs_remove: Removal request matches referral %s\n",
					refpath));
				found = True;
			}
		}

		if(!found) {
			return WERR_DFS_NO_SUCH_SHARE;
		}

		/* Only one referral, remove it */
		if(jn.referral_count == 1) {
			if(!remove_msdfs_link(&jn)) {
				vfs_ChDir(p->conn,p->conn->connectpath);
				return WERR_DFS_NO_SUCH_VOL;
			}
		} else {
			if(!create_msdfs_link(&jn, True)) { 
				vfs_ChDir(p->conn,p->conn->connectpath);
				return WERR_DFS_CANT_CREATE_JUNCT;
			}
		}
		vfs_ChDir(p->conn,p->conn->connectpath);
	}

	return WERR_OK;
}
Esempio n. 17
0
WERROR _dfs_add(pipes_struct *p, DFS_Q_DFS_ADD* q_u, DFS_R_DFS_ADD *r_u)
{
  struct current_user user;
  struct junction_map jn;
  struct referral* old_referral_list = NULL;
  BOOL exists = False;

  pstring dfspath, servername, sharename;
  pstring altpath;

  get_current_user(&user,p);

  if (user.uid != 0) {
	DEBUG(10,("_dfs_add: uid != 0. Access denied.\n"));
	return WERR_ACCESS_DENIED;
  }

  unistr2_to_dos(dfspath, &q_u->DfsEntryPath, sizeof(dfspath)-1);
  unistr2_to_dos(servername, &q_u->ServerName, sizeof(servername)-1);
  unistr2_to_dos(sharename, &q_u->ShareName, sizeof(sharename)-1);

  DEBUG(5,("init_reply_dfs_add: Request to add %s -> %s\\%s.\n",
	   dfspath, servername, sharename));

  pstrcpy(altpath, servername);
  pstrcat(altpath, "\\");
  pstrcat(altpath, sharename);

  if(get_referred_path(dfspath, &jn, NULL, NULL))
    {
      exists = True;
      jn.referral_count += 1;
      old_referral_list = jn.referral_list;
    }
  else
    jn.referral_count = 1;

  jn.referral_list = (struct referral*) talloc(p->mem_ctx, jn.referral_count 
					       * sizeof(struct referral));

  if(jn.referral_list == NULL)
    {
      DEBUG(0,("init_reply_dfs_add: talloc failed for referral list!\n"));
      return WERR_DFS_INTERNAL_ERROR;
    }

  if(old_referral_list)
    {
      memcpy(jn.referral_list, old_referral_list, 
	     sizeof(struct referral)*jn.referral_count-1);
      SAFE_FREE(old_referral_list);
    }
  
  jn.referral_list[jn.referral_count-1].proximity = 0;
  jn.referral_list[jn.referral_count-1].ttl = REFERRAL_TTL;

  pstrcpy(jn.referral_list[jn.referral_count-1].alternate_path, altpath);
  
  if(!create_msdfs_link(&jn, exists))
    return WERR_DFS_CANT_CREATE_JUNCT;

  return WERR_OK;
}
Esempio n. 18
0
WERROR _dfs_remove(pipes_struct *p, DFS_Q_DFS_REMOVE *q_u, 
                   DFS_R_DFS_REMOVE *r_u)
{
  struct current_user user;
  struct junction_map jn;
  BOOL found = False;

  pstring dfspath, servername, sharename;
  pstring altpath;

  get_current_user(&user,p);

  if (user.uid != 0) {
	DEBUG(10,("_dfs_remove: uid != 0. Access denied.\n"));
	return WERR_ACCESS_DENIED;
  }

  unistr2_to_dos(dfspath, &q_u->DfsEntryPath, sizeof(dfspath)-1);
  if(q_u->ptr_ServerName)
    unistr2_to_dos(servername, &q_u->ServerName, sizeof(servername)-1);

  if(q_u->ptr_ShareName)
    unistr2_to_dos(sharename, &q_u->ShareName, sizeof(sharename)-1);

  if(q_u->ptr_ServerName && q_u->ptr_ShareName)
    {
      pstrcpy(altpath, servername);
      pstrcat(altpath, "\\");
      pstrcat(altpath, sharename);
      strlower(altpath);
    }

  DEBUG(5,("init_reply_dfs_remove: Request to remove %s -> %s\\%s.\n",
	   dfspath, servername, sharename));

  if(!get_referred_path(dfspath, &jn, NULL, NULL))
	  return WERR_DFS_NO_SUCH_VOL;

  /* if no server-share pair given, remove the msdfs link completely */
  if(!q_u->ptr_ServerName && !q_u->ptr_ShareName)
    {
      if(!remove_msdfs_link(&jn))
	return WERR_DFS_NO_SUCH_VOL;
    }
  else
    {
      int i=0;
      /* compare each referral in the list with the one to remove */
      DEBUG(10,("altpath: .%s. refcnt: %d\n", altpath, jn.referral_count));
      for(i=0;i<jn.referral_count;i++)
	{
	  pstring refpath;
	  pstrcpy(refpath,jn.referral_list[i].alternate_path);
	  trim_string(refpath, "\\", "\\");
	  DEBUG(10,("_dfs_remove:  refpath: .%s.\n", refpath));
	  if(strequal(refpath, altpath))
	    {
	      *(jn.referral_list[i].alternate_path)='\0';
	      DEBUG(10,("_dfs_remove: Removal request matches referral %s\n",
			refpath));
	      found = True;
	    }
	}
      if(!found)
	return WERR_DFS_NO_SUCH_SHARE;
      
      /* Only one referral, remove it */
      if(jn.referral_count == 1)
	{
	  if(!remove_msdfs_link(&jn))
	    return WERR_DFS_NO_SUCH_VOL;
	}
      else
	{
	  if(!create_msdfs_link(&jn, True))
	    return WERR_DFS_CANT_CREATE_JUNCT;
	}
    }

  return WERR_OK;
}
Esempio n. 19
0
unsigned long **sys_call_table;

asmlinkage long (*ref_sys_cs3013_syscall1)(void);

asmlinkage int (*ref_sys_open)(const char* __user, int, int);
asmlinkage int (*ref_sys_close)(unsigned int);


asmlinkage long new_sys_cs3013_syscall1(void) {
	printk(KERN_INFO "\"'Hello world?!' More like 'Goodbye, world!' EXTERMINATE!\" -- Dalek");
	return 0;
}	// asmlinkage long new_sys_cs3013_syscall1(void)

asmlinkage int new_sys_open(const char* __user file_name, int flags, int mode) {
	
	user = get_current_user() -> uid;
	
	if (user > 0){
	//do modified call, this is user
	
	
	//print statement
	printk(KERN_INFO "\"'User %d is opening file: %s\"",user, file_name);
	
	//exceute procedure
	return filed = ref_sys_open(file_name, flags, mode);
	}
	else{
	//do regular call, this is kernel
	return ref_sys_open(file_name, flags, mode);
	}