/* 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;
}
コード例 #2
0
/* open door file for the given JVM */
static int open_door(pid_t pid) {
    char path[PATH_MAX + 1];
    int fd;

    sprintf(path, DOOR_FILE_PATTERN, pid);
    fd = file_open(path, O_RDONLY);
    if (fd < 0) {
        set_jvm_error(JVM_ERR_CANT_OPEN_DOOR);
        print_debug("cannot open door file %s\n", path);
        return -1;
    }
    print_debug("opened door file %s\n", path);
    if (check_permission(path) != 0) {
        set_jvm_error(JVM_ERR_DOOR_FILE_PERMISSION);
        print_debug("check permission failed for %s\n", path);
        file_close(fd);
        fd = -1;
    }
    return fd;
}
コード例 #3
0
static int configurable_checkaccess(Npfid* fid, const char* path, u8 mode) {
    uid_t user;
    struct in_addr remote_addr;
    /*
    char check_path[PATH_MAX];

    	if ( !fid->path ) {
    		memcpy(check_path, path, strlen(path) + 1);
    	} else if ( !path ) {
    		memcpy(check_path, fid->path, strlen(fid->path) + 1);
    	} else {
    		int fid_path_length = strlen(fid->path) + 1;
    		memcpy(check_path, fid->path, fid_path_length);
    		check_path[fid_path_length] = '/';
    		memcpy(check_path + fid_path_length + 1, path, strlen(path) + 1);
    	}
    */
    user = fid->user->uid;
    convert_addr(fid->conn->address, &remote_addr);

    return check_permission(user, remote_addr, path, mode2rights(mode)) == true ? 1 : 0; // 1 if access is ok
}
コード例 #4
0
static void do_search_port(snd_seq_t *seq, int perm, action_func_t do_action)
{
	snd_seq_client_info_t *cinfo;
	snd_seq_port_info_t *pinfo;
	int count;

	snd_seq_client_info_alloca(&cinfo);
	snd_seq_port_info_alloca(&pinfo);
	snd_seq_client_info_set_client(cinfo, -1);
	while (snd_seq_query_next_client(seq, cinfo) >= 0) {
		/* reset query info */
		snd_seq_port_info_set_client(pinfo, snd_seq_client_info_get_client(cinfo));
		snd_seq_port_info_set_port(pinfo, -1);
		count = 0;
		while (snd_seq_query_next_port(seq, pinfo) >= 0) {
			if (check_permission(pinfo, perm)) {
				do_action(seq, cinfo, pinfo, count);
				count++;
			}
		}
	}
}
コード例 #5
0
ファイル: vsupport.c プロジェクト: Lundex/lima
//:FUNCTION direct_smell_obj
//Handle parser checks for "smell OBJ" rule.
mixed direct_smell_obj(object ob)
{
    if(!default_object_checks())
      return 0;
    return check_permission("smell");
}
コード例 #6
0
ファイル: vsupport.c プロジェクト: Lundex/lima
//:FUNCTION direct_put_obj_wrd_obj
//Handle parser checks for "put OBJ WRD OBJ"     
mixed direct_put_obj_wrd_obj(object ob1, object ob2)
{
  return check_permission("put");
}
コード例 #7
0
ファイル: alsa.cpp プロジェクト: Harrypoppins/grim_mouse
int MidiDriver_ALSA::open() {
	if (_isOpen)
		return MERR_ALREADY_OPEN;
	_isOpen = true;

	if (my_snd_seq_open(&seq_handle) < 0) {
		error("Can't open sequencer");
		return -1;
	}

	my_client = snd_seq_client_id(seq_handle);
	if (snd_seq_set_client_name(seq_handle, "RESIDUALVM") < 0) {
		error("Can't set sequencer client name");
	}
	snd_seq_set_client_group(seq_handle, "input");

	// According to http://www.alsa-project.org/~tiwai/alsa-subs.html
	// you can set read or write capabilities to allow other clients to
	// read or write the port. I don't think we need that, unless maybe
	// to be able to record the sound, but I can't get that to work even
	// with those capabilities.

	my_port = snd_seq_create_simple_port(seq_handle, "RESIDUALVM port 0", 0,
	                                     SND_SEQ_PORT_TYPE_MIDI_GENERIC | SND_SEQ_PORT_TYPE_APPLICATION);

	if (my_port < 0) {
		snd_seq_close(seq_handle);
		error("Can't create port");
		return -1;
	}

	if (seq_client != SND_SEQ_ADDRESS_SUBSCRIBERS) {
		// Subscribe to MIDI port. Prefer one that doesn't already have
		// any connections, unless we've forced a port number already.
		if (seq_port == -1) {
			snd_seq_client_info_t *cinfo;
			snd_seq_port_info_t *pinfo;

			snd_seq_client_info_alloca(&cinfo);
			snd_seq_port_info_alloca(&pinfo);

			snd_seq_get_any_client_info(seq_handle, seq_client, cinfo);

			int first_port = -1;
			int found_port = -1;

			snd_seq_port_info_set_client(pinfo, seq_client);
			snd_seq_port_info_set_port(pinfo, -1);
			while (found_port == -1 && snd_seq_query_next_port(seq_handle, pinfo) >= 0) {
				if (check_permission(pinfo)) {
					if (first_port == -1)
						first_port = snd_seq_port_info_get_port(pinfo);
					if (found_port == -1 && snd_seq_port_info_get_write_use(pinfo) == 0)
						found_port = snd_seq_port_info_get_port(pinfo);
				}
			}

			if (found_port == -1) {
				// Should we abort here? For now, use the first
				// available port.
				seq_port = first_port;
				warning("MidiDriver_ALSA: All ports on client %d (%s) are already in use", seq_client, snd_seq_client_info_get_name(cinfo));
			} else {
				seq_port = found_port;
			}
		}

		if (snd_seq_connect_to(seq_handle, my_port, seq_client, seq_port) < 0) {
			error("Can't subscribe to MIDI port (%d:%d) see README for help", seq_client, seq_port);
		}
	}

	printf("Connected to Alsa sequencer client [%d:%d]\n", seq_client, seq_port);
	printf("ALSA client initialized [%d:0]\n", my_client);

	return 0;
}
コード例 #8
0
ファイル: syntax.c プロジェクト: federicosan/ponyc
// Check whether the given entity has illegal parts
static ast_result_t syntax_entity(pass_opt_t* opt, ast_t* ast,
  int entity_def_index)
{
  assert(ast != NULL);
  assert(entity_def_index >= 0 && entity_def_index < DEF_ENTITY_COUNT);
  ast_result_t r = AST_OK;

  const permission_def_t* def = &_entity_def[entity_def_index];
  AST_GET_CHILDREN(ast, id, typeparams, defcap, provides, members, c_api);

  // Check if we're called Main
  if(def->permissions[ENTITY_MAIN] == 'N' && ast_name(id) == stringtab("Main"))
  {
    ast_error(opt->check.errors, ast, "Main must be an actor");
    r = AST_ERROR;
  }

  if(!check_id_type(opt, id, def->desc))
    r = AST_ERROR;

  if(!check_permission(opt, def, ENTITY_CAP, defcap, "default capability",
    defcap))
    r = AST_ERROR;

  if(!check_permission(opt, def, ENTITY_C_API, c_api, "C api", c_api))
    r = AST_ERROR;

  if(ast_id(c_api) == TK_AT)
  {
    if(ast_id(typeparams) != TK_NONE)
    {
      ast_error(opt->check.errors, typeparams,
        "generic actor cannot specify C api");
      r = AST_ERROR;
    }
  }

  if(entity_def_index != DEF_TYPEALIAS)
  {
    // Check referenced traits
    if(ast_id(provides) != TK_NONE &&
      !check_provides_type(opt, provides, "provides"))
      r = AST_ERROR;
  }
  else
  {
    // Check for a type alias
    if(ast_id(provides) == TK_NONE)
    {
      ast_error(opt->check.errors, provides,
        "a type alias must specify a type");
      r = AST_ERROR;
    }
  }

  // Check for illegal members
  if(!check_members(opt, members, entity_def_index))
    r = AST_ERROR;

  return r;
}
コード例 #9
0
/*------------------------------------------------------------------------------------------------------------------
-- FUNCTION: startServer
--
-- DATE: March 14, 2014
--
-- REVISIONS: March 16 - added printing users list and users quitting
--            March 17 - added messaging specific users
--            March 20 - added role based users
--
-- DESIGNER: Damien Sathanielle
--
-- PROGRAMMER: Damien Sathanielle
--
-- INTERFACE: void startServer(
--                             int port - port number for server
--                             )
--
-- RETURNS: void
--
-- NOTES: The server will run in a forever loop checking and updating connections using select()
--        Special commands such as kicking a user and promoting a user are also handled by the server
--
------------------------------------------------------------------------------------------------------------------*/
void startServer(int port)
{
    char serverName[BUFLEN];
    printf("Please enter a server name: \n");
    fgets(serverName, BUFLEN, stdin);

    signal(SIGINT, catch_int_server);

    int  listen_sd, new_sd, sockfd,
         maxfd,
         maxi,
         bytes_to_read,
         i, j, k,
         promotion,
         nready,
         lengthOfClientName;

    char sbuf[BUFLEN],
        *bp,
         buf[BUFLEN],
         msgUser[30],
         ctrlCharacter1,
         ctrlCharacter2,
         ctrlCharacter3,
         clientName[BUFLEN];

    socklen_t client_len;

    struct sockaddr_in server, client_addr;

    ssize_t n;
    fd_set rset, allset;
    printf("Server name: %s", serverName);
    printf("Server listening on port: %d\n", port);

    listen_socket(&listen_sd, &server, port);

    if (bind(listen_sd, (struct sockaddr *)&server, sizeof(server)) == -1)
        SystemFatal("bind error");

    listen(listen_sd, LISTENQ);

    maxfd = listen_sd;
    maxi = -1;
    numClients = 0;

    for(i = 0; i < FD_SETSIZE; i++)
        client[i] = -1;
    FD_ZERO(&allset);
    FD_SET(listen_sd, &allset);
    /* set sockets in client struct to -1 */
    for(i = 0; i < MAX_CLIENTS; i++)
        client_list[i].socket = -1;


    while(1)
    {
        memset(buf, 0, BUFLEN);
        rset = allset;               // structure assignment
        nready = select(maxfd + 1, &rset, NULL, NULL, NULL);

        if (FD_ISSET(listen_sd, &rset)) // new client connection
        {
            client_len = sizeof(client_addr);
            if ((new_sd = accept(listen_sd, (struct sockaddr *) &client_addr, &client_len)) == -1)
                SystemFatal("accept error");

            bp = buf;
            read(new_sd, bp, BUFLEN);
            sscanf(bp, "%c %c %d %s %c", &ctrlCharacter1, &ctrlCharacter2, &lengthOfClientName, clientName, &ctrlCharacter3);



            for (i = 0; i < FD_SETSIZE; i++)
            {
                if (client[i] < 0)
                {
                    client[i] = new_sd;    // save descriptor

                    printf("%s has connected with the remote address of %s\n", clientName, inet_ntoa(client_addr.sin_addr));
                    // send server name
                    memset(sbuf, 0, BUFLEN);
                    sprintf(sbuf, "%c %c %zu %s %c", SYN, 0x03, strlen(serverName), serverName, EOT);
                    write(client[i], sbuf, BUFLEN);

                    for(j = 0; j < MAX_CLIENTS; j++)
                    {
                        if(client_list[j].socket == -1)
                        {
                            if(numClients == 0)
                                addClient(j, i, 'a', clientName, inet_ntoa(client_addr.sin_addr));
                            else
                                addClient(j, i, 'n', clientName, inet_ntoa(client_addr.sin_addr));
                            break;
                        }
                    }

                    break;
                }
            }
            if (i == FD_SETSIZE)
            {
                printf ("Too many clients\n");
                exit(1);
            }

            memset(sbuf, 0, BUFLEN);
            strcat(sbuf, inet_ntoa(client_addr.sin_addr));
            strcat(sbuf, " ");
            strcat(sbuf, clientName);
            strcat(sbuf, " joined the chat channel.\n");

            /* notify other users that a new user has joined the chat */
            for(j = 0; j <= maxfd; j++)
            {
                if(client[j] < 0)
                    continue;
                if(client[j] == new_sd)
                    continue;
                write(client[j], sbuf, BUFLEN);
            }


            FD_SET (new_sd, &allset);     // add new descriptor to set


            if (new_sd > maxfd)
                maxfd = new_sd;    // for select

            if (i > maxi)
                maxi = i;    // new max index in client[] array

            if (--nready <= 0)
                continue;    // no more readable descriptors
        }

        for (i = 0; i <= maxi; i++)    // check all clients for data
        {
            if ((sockfd = client[i]) < 0)
                continue;

            if (FD_ISSET(sockfd, &rset))
            {
                bp = buf;
                bytes_to_read = BUFLEN;

                while ((n = read(sockfd, bp, bytes_to_read)) > 0)
                {
                    bp += n;
                    bytes_to_read -= n;
                }
                /* displays list of current users and their status */
                if(strstr(buf, "/users"))
                {
                    for(k = 0; k < MAX_CLIENTS; k++)
                    {
                        if(client_list[k].socket > -1)
                        {
                            for(j = 0; j <= maxfd; j++)
                            {
                                if(j == i)
                                {
                                    sprintf(buf, "%c", client_list[k].role);
                                    strcat(buf, " ");
                                    strcat(buf, client_list[k].username);
                                    strcat(buf,"\n");
                                    write(client[j], buf, BUFLEN);
                                }
                            }
                        }
                    }
                    sprintf(buf, "%d", numClients);
                    strcat(buf, " users in chat.\n\n");
                    write(client[i], buf, BUFLEN);
                    break;
                }

                if(strstr(buf, "/msg"))
                {
                    strcpy(msgUser, getName(buf));
                    trim(msgUser);
                    for(k = 0; k < MAX_CLIENTS; k++)
                    {
                        if((client_list[k].socket > -1) && !strcmp(client_list[k].username, msgUser))
                        {
                            for(j = 0; j <= maxfd; j++)
                            {
                                if(j == client_list[k].socket)
                                    write(client[j], buf, BUFLEN);
                            }
                        }
                    }
                    break;
                }

                if(strstr(buf, "/kick"))
                {
                    if(check_permission(i))
                    {
                        buf[strlen(buf) - 1] = 0;
                        strcpy(msgUser, getName(buf));
                        trim(msgUser);
                        for(k = 0; k < MAX_CLIENTS; k++)
                        {
                            if((client_list[k].socket > -1) && !strcmp(client_list[k].username, msgUser))
                            {
                                for(j = 0; j <= maxfd; j++)
                                {
                                    if(j == client_list[k].socket)
                                    {
                                        write(client[j], "you have been kicked\n", BUFLEN);
                                        removeClient(j);
                                        client[j] = -1;
                                    }
                                }
                            }
                        }
                        break;
                    }else
                        write(client[i], "you don't have permission\n", BUFLEN);
                }
                /* promote a user to admin or remove admin status from user */
                if(strstr(buf, "/promote") || strstr(buf, "/demote"))
                {
                    if(check_permission(i))
                    {
                        if(strstr(buf, "/promote"))
                            promotion = 1;
                        else
                            promotion = 0;

                        buf[strlen(buf) - 1] = 0;
                        strcpy(msgUser, getName(buf));
                        trim(msgUser);
                        for(k = 0; k < MAX_CLIENTS; k++)
                        {
                            if((client_list[k].socket > -1) && !strcmp(client_list[k].username, msgUser))
                            {
                                for(j = 0; j <= maxfd; j++)
                                {
                                    if(j == client_list[k].socket)
                                    {
                                        if(promotion)
                                        {
                                            client_list[j].role = 'a';
                                            write(client[j], "you have been promoted!!\n", BUFLEN);
                                        }else
                                        {
                                            client_list[j].role = 'n';
                                            write(client[j], "you have been demoted\n", BUFLEN);
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    }else
                        write(client[i], "you don't have permission\n", BUFLEN);
                }
                /* disconnected signal */
                if(strstr(buf, "has left the chat"))
                {
                    for(j = 0; j <= maxfd; j++)
                    {
                        if(j == i)
                        {
                            removeClient(j);
                            client[i] = -1;
                        }

                        else
                            write(client[j], buf, BUFLEN);
                    }
                    break;
                }

                /* if users enters invalid command */
                if(strstr(buf, "/"))
                {
                    write(client[i], "type /help for a list of commands\n", BUFLEN);
                }else
                {
                    for(j = 0; j <= maxfd; j++)
                    {
                        if(j != i)
                            write(client[j], buf, BUFLEN);
                    }
                }

                if (--nready <= 0)
                    break;        // no more readable descriptors
            }
        }
    }
    close(sockfd);
    exit(0);
}
コード例 #10
0
ファイル: perm.c プロジェクト: Akheon23/at
int
main(int argc, char *argv[])
{
  printf("check_permission() ==> %d\n", check_permission());
  return 0;
}
コード例 #11
0
ファイル: count_large.c プロジェクト: royalchan2436/C-BasicC
int main(int argc, char *argv[])
{   
	/* System call shell command */
    
	system("ls -l >> assignment.txt");
    
    /* Read shell command results */

    char temp_hold[LENGTH];
    char permission_hold[LENGTH];
    char *filesize_hold;
    int permission_check = 0;
    int filesize_check = 0;
    char *delim = " ";
    int loop_control;
    char *permission_argv;
    int condition = 0;
    char *filesize_temp;
    int temp_int = 0;
    int flag = 0;


	FILE *fp;
	fp = fopen("./assignment.txt", "r");
    if(fp == NULL)
    {
    	printf("No Such File !!!\n");
    }
    fgets(temp_hold, STRING, fp);
    


	char *num = "1234567890";
	char *p;
    if(argc == 2)
    {  
       p = strpbrk(argv[1], num);
       if(!p)
       {  
          //Only Permission Check
       	  while(!feof(fp))
          {  
             flag = 2;
             fgets(temp_hold, STRING, fp);
             strcpy(permission_hold, strtok(temp_hold, delim));
             permission_argv = strndup(permission_hold+1, 9);
             condition = check_permission(permission_argv, argv[1]);
             if(condition == 1)
             {
                permission_check += 1;
             }

          }
       }
       else
       {  
          //Only Filesize Check
          while(!feof(fp))
          { 
            flag = 1;
            loop_control = 0;
            fgets(temp_hold, STRING, fp);
            filesize_hold = strtok_r(temp_hold, " ", &filesize_temp);
            while(filesize_hold != NULL)
            {   
                if(loop_control == 4)
                {
                   break;
                }
                filesize_hold = strtok_r(NULL, " ", &filesize_temp);
                loop_control++;
            }
            if(filesize_hold)
            {
                temp_int = atoi(filesize_hold);
                if(temp_int >= atoi(argv[1]))
                {
                    filesize_check += 1;

                }
            }
            
          }
       }
    }
    else if(argc == 3)
    {
         while(!feof(fp))
          {
            loop_control = 0;
            fgets(temp_hold, STRING, fp);
            filesize_hold = strtok_r(temp_hold, " ", &filesize_temp);
            while (filesize_hold != NULL)
            {   
                if(loop_control == 4)
                {
                   break;
                }
                filesize_hold = strtok_r(NULL, " ", &filesize_temp);
                loop_control++;
            }
            if(filesize_hold)
            {
                temp_int = atoi(filesize_hold);
                if(temp_int >= atoi(argv[1]))
                {
                    filesize_check += 1;

                }
            }
            
          }

        fclose(fp);

        FILE *fptr;
        fptr = fopen("./assignment.txt", "r");
        if(fptr == NULL)
        {
            printf("No Such File !!!\n");
        }
        fgets(temp_hold, STRING, fptr);
        while(!feof(fptr))
        {  
             fgets(temp_hold, STRING, fptr);
             strcpy(permission_hold, strtok(temp_hold, delim));
             permission_argv = strndup(permission_hold+1, 9);
             condition = check_permission(permission_argv, argv[2]);
             if(condition == 1)
             {
                permission_check += 1;
             }

        }
        fclose(fptr);

    }
    else if(argc == 1)
    {
    	printf("No argument !!\n");
    }
    permission_check = permission_check - 1;
    if(argc == 2)
    {
        if(flag == 1)
        {
           printf("%d \n", filesize_check);
        }
        if(flag == 2)
        {
           printf("%d \n", permission_check);
        }
    }
    if(argc == 3)
    {   
        if(filesize_check > permission_check)
        {
            printf("%d \n", permission_check);
        }
        else
        {
            printf("%d \n", filesize_check);
        }
    }

    return 0;
}