コード例 #1
0
ファイル: cli.c プロジェクト: TakumiKomada/trema
int main(int argc, char **argv)
{
    char instance[PATH_MAX];
    int ret;

    memset(instance, '\0', sizeof(instance));

    log_init(LOG_WARN, LOG_OUT_STDOUT);

    cli_set_program_name(basename(argv[0]));

    if((argc > 2) && (strcmp(argv[1], "-i") == 0)){
        strncpy(instance, argv[2], PATH_MAX - 1);
        argc -= 2;
        argv += 2;
    }
    else{
        strncpy(instance, CLI_DEFAULT_INSTANCE, PATH_MAX - 1);
    }

    cli_init(instance);

    ret = cli_parse_args(argc, argv);
    if(ret < 0){
        log_err("cannot execute.");
    }

    cli_close();
    log_close();

    return 0;
}
コード例 #2
0
ファイル: smbspool.c プロジェクト: OPSF/uClinux
static int				/* O - 0 = success, non-0 = failure */
smb_print(struct cli_state *cli,	/* I - SMB connection */
          char             *title,	/* I - Title/job name */
          FILE             *fp)		/* I - File to print */
{
  int	fnum;		/* File number */
  int	nbytes,		/* Number of bytes read */
	tbytes;		/* Total bytes read */
  char	buffer[8192],	/* Buffer for copy */
	*ptr;		/* Pointer into tile */


 /*
  * Sanitize the title...
  */

  for (ptr = title; *ptr; ptr ++)
    if (!isalnum((int)*ptr) && !isspace((int)*ptr))
      *ptr = '_';

 /*
  * Open the printer device...
  */

  if ((fnum = cli_open(cli, title, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE)) == -1)
  {
    fprintf(stderr, "ERROR: %s opening remote spool %s\n",
            cli_errstr(cli), title);
    return (1);
  }

 /*
  * Copy the file to the printer...
  */

  if (fp != stdin)
    rewind(fp);

  tbytes = 0;

  while ((nbytes = fread(buffer, 1, sizeof(buffer), fp)) > 0)
  {
    if (cli_write(cli, fnum, 0, buffer, tbytes, nbytes) != nbytes)
    {
      fprintf(stderr, "ERROR: Error writing spool: %s\n", cli_errstr(cli));
      break;
    }

    tbytes += nbytes;
  } 

  if (!cli_close(cli, fnum))
  {
    fprintf(stderr, "ERROR: %s closing remote spool %s\n",
            cli_errstr(cli), title);
    return (1);
  }
  else
    return (0);
}
コード例 #3
0
bool cli_rpc_pipe_close(struct rpc_pipe_client *cli)
{
	bool ret;

	if (!cli) {
		return false;
	}

	ret = cli_close(cli->cli, cli->fnum);

	if (!ret) {
		DEBUG(1,("cli_rpc_pipe_close: cli_close failed on pipe %s, "
                         "fnum 0x%x "
                         "to machine %s.  Error was %s\n",
                         cli->pipe_name,
                         (int) cli->fnum,
                         cli->cli->desthost,
                         cli_errstr(cli->cli)));
	}

	if (cli->auth.cli_auth_data_free_func) {
		(*cli->auth.cli_auth_data_free_func)(&cli->auth);
	}

	DEBUG(10,("cli_rpc_pipe_close: closed pipe %s to machine %s\n",
		cli->pipe_name, cli->cli->desthost ));

	DLIST_REMOVE(cli->cli->pipe_list, cli);
	talloc_destroy(cli->mem_ctx);
	return ret;
}
コード例 #4
0
ファイル: cli_np_tstream.c プロジェクト: Alexandr-Galko/samba
static int tstream_cli_np_destructor(struct tstream_cli_np *cli_nps)
{
	NTSTATUS status;

	if (!cli_state_is_connected(cli_nps->cli)) {
		return 0;
	}

	/*
	 * TODO: do not use a sync call with a destructor!!!
	 *
	 * This only happens, if a caller does talloc_free(),
	 * while the everything was still ok.
	 *
	 * If we get an unexpected failure within a normal
	 * operation, we already do an async cli_close_send()/_recv().
	 *
	 * Once we've fixed all callers to call
	 * tstream_disconnect_send()/_recv(), this will
	 * never be called.
	 */
	status = cli_close(cli_nps->cli, cli_nps->fnum);
	if (!NT_STATUS_IS_OK(status)) {
		DEBUG(1, ("tstream_cli_np_destructor: cli_close "
			  "failed on pipe %s. Error was %s\n",
			  cli_nps->npipe, nt_errstr(status)));
	}
	/*
	 * We can't do much on failure
	 */
	return 0;
}
コード例 #5
0
ファイル: gpo_filesync.c プロジェクト: AllardJ/Tomato
NTSTATUS gpo_copy_file(TALLOC_CTX *mem_ctx,
		       struct cli_state *cli,
		       const char *nt_path,
		       const char *unix_path)
{
	NTSTATUS result;
	int fnum;
	int fd = 0;
	char *data = NULL;
	static int io_bufsize = 64512;
	int read_size = io_bufsize;
	off_t start = 0;
	off_t nread = 0;

	if ((fnum = cli_open(cli, nt_path, O_RDONLY, DENY_NONE)) == -1) {
		result = NT_STATUS_NO_SUCH_FILE;
		goto out;
	}

	if ((fd = sys_open(unix_path, O_WRONLY|O_CREAT|O_TRUNC, 0644)) == -1) {
		result = map_nt_error_from_unix(errno);
		goto out;
	}
	 
	if ((data = (char *)SMB_MALLOC(read_size)) == NULL) {
		result = NT_STATUS_NO_MEMORY;
		goto out;
	}

	while (1) {

		int n = cli_read(cli, fnum, data, nread + start, read_size);

		if (n <= 0)
			break;

		if (write(fd, data, n) != n) {
			break;
		}

		nread += n;
	}

	result = NT_STATUS_OK;

 out:
	SAFE_FREE(data);
	if (fnum) {
		cli_close(cli, fnum);
	}
	if (fd) {
		close(fd);
	}

	return result;
}
コード例 #6
0
void nb_close(int handle)
{
	int i;
	i = find_handle(handle);
	if (!NT_STATUS_IS_OK(cli_close(c, ftable[i].fd))) {
		printf("(%d) close failed on handle %d\n", line_count, handle);
		exit(1);
	}
	ftable[i].handle = 0;
}
コード例 #7
0
ファイル: masktest.c プロジェクト: AllardJ/Tomato
static void testpair(struct cli_state *cli1, struct cli_state *cli2,
		     char *mask, char *file)
{
	int fnum;
	fstring res1, res2;
	char *res3;
	static int count;

	count++;

	fstrcpy(res1, "---");
	fstrcpy(res2, "---");

	fnum = cli_open(cli1, file, O_CREAT|O_TRUNC|O_RDWR, 0);
	if (fnum == -1) {
		DEBUG(0,("Can't create %s on cli1\n", file));
		return;
	}
	cli_close(cli1, fnum);

	fnum = cli_open(cli2, file, O_CREAT|O_TRUNC|O_RDWR, 0);
	if (fnum == -1) {
		DEBUG(0,("Can't create %s on cli2\n", file));
		return;
	}
	cli_close(cli2, fnum);

	resultp = res1;
	cli_list(cli1, mask, aHIDDEN | aDIR, listfn);

	res3 = reg_test(mask, file);

	resultp = res2;
	cli_list(cli2, mask, aHIDDEN | aDIR, listfn);

	if (showall || strcmp(res1, res2)) {
		DEBUG(0,("%s %s %s %d mask=[%s] file=[%s]\n",
			 res1, res2, res3, count, mask, file));
	}

	cli_unlink(cli1, file);
	cli_unlink(cli2, file);
}
コード例 #8
0
ファイル: cli.c プロジェクト: TakumiKomada/trema
int cli_init(const char *instance)
{
    int ret;
    int flags;
    struct sockaddr_un saddr;

    if(instance == NULL){
        log_err("instance must be specified.");
        return -1;
    }

    memset(cli_server_sock_file, '\0', sizeof(cli_server_sock_file));
    snprintf(cli_server_sock_file, PATH_MAX - 1, "%s.%s",
             CMDIF_SERVER_SOCK_FILE, instance);

    memset(cli_client_sock_file, '\0', sizeof(cli_client_sock_file));
    snprintf(cli_client_sock_file, PATH_MAX - 1, "%s.%s",
             CMDIF_CLIENT_SOCK_FILE, instance);

    if(cli_fd >= 0){
        cli_close();
    }

    cli_fd = socket(PF_UNIX, SOCK_DGRAM, 0);
    
    if(cli_fd < 0){
        log_err("cannot create socket.");
        return -1;
    }

    memset(&saddr, 0, sizeof(saddr));
    saddr.sun_family = AF_UNIX;
    strcpy(saddr.sun_path, cli_client_sock_file);

    unlink(cli_client_sock_file);

    ret = bind(cli_fd, (struct sockaddr *)&saddr, sizeof(saddr));

    if(ret < 0){
        log_err("cannot bind socket.");
        return -1;
    }

    flags = fcntl(cli_fd, F_GETFL);
    ret = fcntl(cli_fd,  F_SETFL, O_NONBLOCK|flags);

    if(ret < 0){
        log_err("cannot turn on non-blocking mode.");
        return -1;
    }

    srand(time(NULL));

    return 0;
}
コード例 #9
0
ファイル: nbio.c プロジェクト: AllardJ/Tomato
void nb_close(int handle)
{
	int i;
	for (i=0;i<MAX_FILES;i++) {
		if (ftable[i].handle == handle) break;
	}
	if (i == MAX_FILES) {
		printf("(%d) nb_close: handle %d was not open\n", 
		       line_count, handle);
		return;
	}
	cli_close(c, ftable[i].fd);
	ftable[i].handle = 0;
}
コード例 #10
0
ファイル: libsmb_file.c プロジェクト: Alexander--/samba
int
SMBC_close_ctx(SMBCCTX *context,
               SMBCFILE *file)
{
	TALLOC_CTX *frame = talloc_stackframe();

	if (!context || !context->internal->initialized) {
		errno = EINVAL;
		TALLOC_FREE(frame);
		return -1;
	}

	if (!file || !SMBC_dlist_contains(context->internal->files, file)) {
		errno = EBADF;
		TALLOC_FREE(frame);
		return -1;
	}

	/* IS a dir ... */
	if (!file->file) {
		TALLOC_FREE(frame);
		return smbc_getFunctionClosedir(context)(context, file);
	}

	if (!NT_STATUS_IS_OK(cli_close(file->targetcli, file->cli_fd))) {
		SMBCSRV *srv;
		DEBUG(3, ("cli_close failed on %s. purging server.\n",
			  file->fname));
		/* Deallocate slot and remove the server
		 * from the server cache if unused */
		errno = SMBC_errno(context, file->targetcli);
		srv = file->srv;
		DLIST_REMOVE(context->internal->files, file);
		SAFE_FREE(file->fname);
		SAFE_FREE(file);
		smbc_getFunctionRemoveUnusedServer(context)(context, srv);
		TALLOC_FREE(frame);
		return -1;
	}

	DLIST_REMOVE(context->internal->files, file);
	SAFE_FREE(file->fname);
	SAFE_FREE(file);
	TALLOC_FREE(frame);
	return 0;
}
コード例 #11
0
static void close_files(struct cli_state *cli[NSERVERS][NCONNECTIONS], 
			uint16_t fnum[NSERVERS][NCONNECTIONS][NFILES])
{
	int server, conn, f; 

	for (server=0;server<NSERVERS;server++)
	for (conn=0;conn<NCONNECTIONS;conn++)
	for (f=0;f<NFILES;f++) {
		if (fnum[server][conn][f] != (uint16_t)-1) {
			cli_close(cli[server][conn], fnum[server][conn][f]);
			fnum[server][conn][f] = (uint16_t)-1;
		}
	}
	for (server=0;server<NSERVERS;server++) {
		cli_unlink(cli[server][0], FILENAME, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
	}
}
コード例 #12
0
ファイル: locktest.c プロジェクト: DeezNuts12/freestyledash
static void close_files(struct cli_state *cli[NSERVERS][NCONNECTIONS], 
			int fnum[NSERVERS][NCONNECTIONS][NFILES])
{
	int server, conn, f; 

	for (server=0;server<NSERVERS;server++)
	for (conn=0;conn<NCONNECTIONS;conn++)
	for (f=0;f<NFILES;f++) {
		if (fnum[server][conn][f] != -1) {
			cli_close(cli[server][conn], fnum[server][conn][f]);
			fnum[server][conn][f] = -1;
		}
	}
	for (server=0;server<NSERVERS;server++) {
		cli_unlink(cli[server][0], FILENAME);
	}
}
コード例 #13
0
ファイル: rpc_transport_np.c プロジェクト: endisd/samba
static int rpc_transport_np_state_destructor(struct rpc_transport_np_state *s)
{
    if (s->cli->fd == -1) {
        DEBUG(10, ("socket was closed, no need to send close request.\n"));
        return 0;
    }

    if (!NT_STATUS_IS_OK(cli_close(s->cli, s->fnum))) {
        DEBUG(1, ("rpc_transport_np_state_destructor: cli_close "
                  "failed on pipe %s. Error was %s\n", s->pipe_name,
                  cli_errstr(s->cli)));
    }
    DEBUG(10, ("rpc_pipe_destructor: closed %s\n", s->pipe_name));
    /*
     * We can't do much on failure
     */
    return 0;
}
コード例 #14
0
ファイル: test_cleanup.c プロジェクト: DanilKorotenko/samba
bool run_cleanup1(int dummy)
{
	struct cli_state *cli;
	const char *fname = "\\cleanup1";
	uint16_t fnum;
	NTSTATUS status;

	printf("CLEANUP1: Checking that a conflicting share mode is cleaned "
	       "up\n");

	if (!torture_open_connection(&cli, 0)) {
		return false;
	}
	status = cli_openx(cli, fname, O_RDWR|O_CREAT, DENY_ALL, &fnum);
	if (!NT_STATUS_IS_OK(status)) {
		printf("open of %s failed (%s)\n", fname, nt_errstr(status));
		return false;
	}
	status = smbXcli_conn_samba_suicide(cli->conn, 1);
	if (!NT_STATUS_IS_OK(status)) {
		printf("smbXcli_conn_samba_suicide failed: %s\n",
		       nt_errstr(status));
		return false;
	}

	if (!torture_open_connection(&cli, 1)) {
		return false;
	}
	status = cli_ntcreate(
		cli, fname, 0,
		FILE_GENERIC_READ|FILE_GENERIC_WRITE|DELETE_ACCESS,
		FILE_ATTRIBUTE_NORMAL,
		FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
		FILE_OPEN, FILE_DELETE_ON_CLOSE, 0, &fnum, NULL);
	if (!NT_STATUS_IS_OK(status)) {
		printf("2nd open of %s failed (%s)\n", fname,
		       nt_errstr(status));
		return false;
	}
	cli_close(cli, fnum);

	torture_close_connection(cli);
	return NT_STATUS_IS_OK(status);
}
コード例 #15
0
ファイル: smbw.c プロジェクト: livebox/livebox2
/***************************************************** 
a wrapper for close()
*******************************************************/
int smbw_close(int fd)
{
	struct smbw_file *file;

	smbw_busy++;

	file = smbw_file(fd);
	if (!file) {
		int ret = smbw_dir_close(fd);
		smbw_busy--;
		return ret;
	}
	
	if (file->f->ref_count == 1 &&
	    !cli_close(&file->srv->cli, file->f->cli_fd)) {
		errno = smbw_errno(&file->srv->cli);
		smbw_busy--;
		return -1;
	}


	bitmap_clear(smbw_file_bmap, file->fd);
	close(file->fd);
	
	DLIST_REMOVE(smbw_files, file);

	file->f->ref_count--;
	if (file->f->ref_count == 0) {
		SAFE_FREE(file->f->fname);
		SAFE_FREE(file->f);
	}
	ZERO_STRUCTP(file);
	SAFE_FREE(file);
	
	smbw_busy--;

	return 0;
}
コード例 #16
0
static void reconnect(struct cli_state *cli[NSERVERS][NCONNECTIONS], uint16_t fnum[NSERVERS][NCONNECTIONS][NFILES],
		      char *share[NSERVERS])
{
	int server, conn, f;

	for (server=0;server<NSERVERS;server++)
	for (conn=0;conn<NCONNECTIONS;conn++) {
		if (cli[server][conn]) {
			for (f=0;f<NFILES;f++) {
				if (fnum[server][conn][f] != (uint16_t)-1) {
					cli_close(cli[server][conn], fnum[server][conn][f]);
					fnum[server][conn][f] = (uint16_t)-1;
				}
			}
			cli_ulogoff(cli[server][conn]);
			cli_shutdown(cli[server][conn]);
		}
		cli[server][conn] = connect_one(share[server], server);
		if (!cli[server][conn]) {
			DEBUG(0,("Failed to connect to %s\n", share[server]));
			exit(1);
		}
	}
}
コード例 #17
0
ファイル: testalter.c プロジェクト: jiajw0426/easyscada
int main()
{
    char* databaseName = "testalter";
    char* filePath = "testalter.fdb";
    int i, rc;
    int session;
    int statement;
    cli_oid_t oid;
    foo f;
    alter_foo af;
    time_t start = time(NULL);

    session = cli_create(databaseName,  filePath, 0, 0, 4*1024*1024, 4*1024*1024, 512*1024, 0);
    if (session < 0) {
	fprintf(stderr, "cli_open failed with code %d\n", session);
	return EXIT_FAILURE;
    }

    rc = cli_create_table(session, 
                          "foo", 
                          sizeof(foo_descriptor)/sizeof(cli_field_descriptor), 
			  foo_descriptor);
    if (rc != cli_ok) { 
	fprintf(stderr, "cli_create_table failed with code %d\n", rc);
	return EXIT_FAILURE;
    } 
    for (i = 0; i < N_RECORDS; i++) { 
        char buf[32];
        sprintf(buf, "%d", i);
        f.x = i;
        f.y = buf;
        f.z = i + (double)i / 10;        
        rc = cli_insert_struct(session, "foo", &f, &oid);
        if (rc != cli_ok) { 
            fprintf(stderr, "cli_insert failed with code %d\n", rc);
            return EXIT_FAILURE;
        }
    }
    printf("Elapsed time for inserting %d records: %d seconds\n", N_RECORDS, (int)(time(NULL) - start));
    start = time(NULL);
    rc = cli_alter_table(session, 
                         "foo", 
                         sizeof(alter_foo_descriptor)/sizeof(cli_field_descriptor), 
                         alter_foo_descriptor);
    if (rc != cli_ok) { 
	fprintf(stderr, "cli_alter_table failed with code %d\n", rc);
	return EXIT_FAILURE;
    } 
    printf("Elapsed time for reformating %d records: %d seconds\n", N_RECORDS, (int)(time(NULL) - start));
    start = time(NULL);    
    statement = cli_prepare_query(session, "select * from foo where x=%i");
    if (statement < 0) { 
        fprintf(stderr, "cli_statement failed with code %d\n", rc);
        return EXIT_FAILURE;
    }
    for (i = 0; i < N_RECORDS; i++) { 
        char buf[32];
        sprintf(buf, "%d", i);
        rc = cli_execute_query(statement, cli_view_only, &af, i);
        if (rc != 1) { 
            fprintf(stderr, "cli_execute_query failed with code %d\n", rc);
            return EXIT_FAILURE;
        }
        rc = cli_get_next(statement);
        if (rc != cli_ok) { 
            fprintf(stderr, "cli_get_next failed with code %d\n", rc);
            return EXIT_FAILURE;
        }
        if (af.x != i || strcmp(buf, af.y) != 0 || *af.a != '\0' || (int)((af.z+0.01)*10) != i*10+i || af.b != 0) { 
            fprintf(stderr, "Conversion error: i=%d, f.x=%ld, f.y=%s, f.a=%s, f.z=%f, f.b=%d\n", i, (long)af.x, af.y, af.a, af.z, af.b);
            return EXIT_FAILURE;
        }
    }
    printf("Elapsed time for %d index searches: %d seconds\n", N_RECORDS, (int)(time(NULL) - start));
    rc = cli_drop_table(session, "foo");
    if (rc != 0) { 
        fprintf(stderr, "cli_drop_table failed with code %d\n", rc);
        return EXIT_FAILURE;
    }
    rc = cli_close(session);
    if (rc != cli_ok) { 
        fprintf(stderr, "cli_close failed with code %d\n", rc);
        return EXIT_FAILURE;	
    }
    printf("*** CLI alter test sucessfully passed!\n");
    return EXIT_SUCCESS;
}
コード例 #18
0
ファイル: utable.c プロジェクト: Arkhont/samba
bool torture_casetable(int dummy)
{
	static struct cli_state *cli;
	char *fname;
	uint16_t fnum;
	int c, i;
#define MAX_EQUIVALENCE 8
	smb_ucs2_t equiv[0x10000][MAX_EQUIVALENCE];
	printf("starting casetable\n");

	if (!torture_open_connection(&cli, 0)) {
		return False;
	}

	memset(equiv, 0, sizeof(equiv));

	cli_unlink(cli, "\\utable\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
	cli_rmdir(cli, "\\utable");
	if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\utable"))) {
		printf("Failed to create utable directory!\n");
		return False;
	}

	for (c=1; c < 0x10000; c++) {
		SMB_OFF_T size;

		if (c == '.' || c == '\\') continue;

		printf("%04x (%c)\n", c, isprint(c)?c:'.');

		fname = form_name(c);
		if (!NT_STATUS_IS_OK(cli_ntcreate(cli, fname, 0,
					  GENERIC_ALL_ACCESS, 
					  FILE_ATTRIBUTE_NORMAL,
					  FILE_SHARE_NONE,
					  FILE_OPEN_IF, 0, 0, &fnum))) {
			printf("Failed to create file with char %04x\n", c);
			continue;
		}

		size = 0;

		if (!NT_STATUS_IS_OK(cli_qfileinfo_basic(
					     cli, fnum, NULL, &size,
					     NULL, NULL, NULL, NULL, NULL))) {
			continue;
		}

		if (size > 0) {
			/* found a character equivalence! */
			int c2[MAX_EQUIVALENCE];

			if (size/sizeof(int) >= MAX_EQUIVALENCE) {
				printf("too many chars match?? size=%ld c=0x%04x\n",
				       (unsigned long)size, c);
				cli_close(cli, fnum);
				return False;
			}

			cli_read(cli, fnum, (char *)c2, 0, size);
			printf("%04x: ", c);
			equiv[c][0] = c;
			for (i=0; i<size/sizeof(int); i++) {
				printf("%04x ", c2[i]);
				equiv[c][i+1] = c2[i];
			}
			printf("\n");
			fflush(stdout);
		}

		cli_writeall(cli, fnum, 0, (uint8_t *)&c, size, sizeof(c),
			     NULL);
		cli_close(cli, fnum);
	}

	cli_unlink(cli, "\\utable\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
	cli_rmdir(cli, "\\utable");

	return True;
}
コード例 #19
0
ファイル: utable.c プロジェクト: Arkhont/samba
bool torture_utable(int dummy)
{
	struct cli_state *cli;
	fstring fname, alt_name;
	uint16_t fnum;
	smb_ucs2_t c2;
	int c, len, fd;
	int chars_allowed=0, alt_allowed=0;
	uint8 valid[0x10000];

	printf("starting utable\n");

	if (!torture_open_connection(&cli, 0)) {
		return False;
	}

	memset(valid, 0, sizeof(valid));

	cli_mkdir(cli, "\\utable");
	cli_unlink(cli, "\\utable\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);

	for (c=1; c < 0x10000; c++) {
		size_t size = 0;
		char *p;

		SSVAL(&c2, 0, c);
		fstrcpy(fname, "\\utable\\x");
		p = fname+strlen(fname);
		if (!convert_string(CH_UTF16LE, CH_UNIX,
				     &c2, 2, 
				     p, sizeof(fname)-strlen(fname),&size)) {
			d_printf("convert_string %s failed !\n", fname);
			continue;
		}
		len = size;
		p[len] = 0;
		fstrcat(fname,"_a_long_extension");

		if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR | O_CREAT | O_TRUNC, 
				DENY_NONE, &fnum))) {
			continue;
		}

		chars_allowed++;

		cli_qpathinfo_alt_name(cli, fname, alt_name);

		if (strncmp(alt_name, "X_A_L", 5) != 0) {
			alt_allowed++;
			valid[c] = 1;
			d_printf("fname=[%s] alt_name=[%s]\n", fname, alt_name);
		}

		cli_close(cli, fnum);
		cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);

		if (c % 100 == 0) {
			printf("%d (%d/%d)\r", c, chars_allowed, alt_allowed);
		}
	}
	printf("%d (%d/%d)\n", c, chars_allowed, alt_allowed);

	cli_rmdir(cli, "\\utable");

	d_printf("%d chars allowed   %d alt chars allowed\n", chars_allowed, alt_allowed);

	fd = open("valid.dat", O_WRONLY|O_CREAT|O_TRUNC, 0644);
	if (fd == -1) {
		d_printf("Failed to create valid.dat - %s", strerror(errno));
		return False;
	}
	if (write(fd, valid, 0x10000) != 0x10000) {
		d_printf("Failed to create valid.dat - %s", strerror(errno));
		close(fd);
		return false;
	}
	close(fd);
	d_printf("wrote valid.dat\n");

	return True;
}
コード例 #20
0
ファイル: smbspool.c プロジェクト: Alexandr-Galko/samba
static int			/* O - 0 = success, non-0 = failure */
smb_print(struct cli_state * cli,	/* I - SMB connection */
	  char *title,		/* I - Title/job name */
	  FILE * fp)
{				/* I - File to print */
	uint16_t             fnum;	/* File number */
	int             nbytes,	/* Number of bytes read */
	                tbytes;	/* Total bytes read */
	char            buffer[8192],	/* Buffer for copy */
	               *ptr;	/* Pointer into title */
	NTSTATUS nt_status;


	/*
         * Sanitize the title...
         */

	for (ptr = title; *ptr; ptr++) {
		if (!isalnum((int) *ptr) && !isspace((int) *ptr)) {
			*ptr = '_';
		}
	}

	/*
         * Open the printer device...
         */

	nt_status = cli_open(cli, title, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE,
			  &fnum);
	if (!NT_STATUS_IS_OK(nt_status)) {
		fprintf(stderr, "ERROR: %s opening remote spool %s\n",
			nt_errstr(nt_status), title);
		return get_exit_code(cli, nt_status);
	}

	/*
         * Copy the file to the printer...
         */

	if (fp != stdin)
		rewind(fp);

	tbytes = 0;

	while ((nbytes = fread(buffer, 1, sizeof(buffer), fp)) > 0) {
		NTSTATUS status;

		status = cli_writeall(cli, fnum, 0, (uint8_t *)buffer,
				      tbytes, nbytes, NULL);
		if (!NT_STATUS_IS_OK(status)) {
			int ret = get_exit_code(cli, status);
			fprintf(stderr, "ERROR: Error writing spool: %s\n",
				nt_errstr(status));
			fprintf(stderr, "DEBUG: Returning status %d...\n",
				ret);
			cli_close(cli, fnum);

			return (ret);
		}
		tbytes += nbytes;
	}

	nt_status = cli_close(cli, fnum);
	if (!NT_STATUS_IS_OK(nt_status)) {
		fprintf(stderr, "ERROR: %s closing remote spool %s\n",
			nt_errstr(nt_status), title);
		return get_exit_code(cli, nt_status);
	} else {
		return (0);
	}
}
コード例 #21
0
ファイル: clitar.c プロジェクト: niubl/camera_project
static void do_atar(char *rname,char *lname,file_info *finfo1)
{
	int fnum;
	SMB_BIG_UINT nread=0;
	char ftype;
	file_info2 finfo;
	BOOL close_done = False;
	BOOL shallitime=True;
	char data[65520];
	int read_size = 65520;
	int datalen=0;

	struct timeval tp_start;

	GetTimeOfDay(&tp_start);

	ftype = '0'; /* An ordinary file ... */

	if (finfo1) {
		finfo.size  = finfo1 -> size;
		finfo.mode  = finfo1 -> mode;
		finfo.uid   = finfo1 -> uid;
		finfo.gid   = finfo1 -> gid;
		finfo.mtime = finfo1 -> mtime;
		finfo.atime = finfo1 -> atime;
		finfo.ctime = finfo1 -> ctime;
		finfo.name  = finfo1 -> name;
	} else {
		finfo.size  = def_finfo.size;
		finfo.mode  = def_finfo.mode;
		finfo.uid   = def_finfo.uid;
		finfo.gid   = def_finfo.gid;
		finfo.mtime = def_finfo.mtime;
		finfo.atime = def_finfo.atime;
		finfo.ctime = def_finfo.ctime;
		finfo.name  = def_finfo.name;
	}

	if (dry_run) {
		DEBUG(3,("skipping file %s of size %12.0f bytes\n", finfo.name,
				(double)finfo.size));
		shallitime=0;
		ttarf+=finfo.size + TBLOCK - (finfo.size % TBLOCK);
		ntarf++;
		return;
	}

	fnum = cli_open(cli, rname, O_RDONLY, DENY_NONE);

	dos_clean_name(rname);

	if (fnum == -1) {
		DEBUG(0,("%s opening remote file %s (%s)\n",
				cli_errstr(cli),rname, cur_dir));
		return;
	}

	finfo.name = string_create_s(strlen(rname));
	if (finfo.name == NULL) {
		DEBUG(0, ("Unable to allocate space for finfo.name in do_atar\n"));
		return;
	}

	safe_strcpy(finfo.name,rname, strlen(rname));
	if (!finfo1) {
		if (!cli_getattrE(cli, fnum, &finfo.mode, &finfo.size, NULL, &finfo.atime, &finfo.mtime)) {
			DEBUG(0, ("getattrE: %s\n", cli_errstr(cli)));
			return;
		}
		finfo.ctime = finfo.mtime;
	}

	DEBUG(3,("file %s attrib 0x%X\n",finfo.name,finfo.mode));

	if (tar_inc && !(finfo.mode & aARCH)) {
		DEBUG(4, ("skipping %s - archive bit not set\n", finfo.name));
		shallitime=0;
	} else if (!tar_system && (finfo.mode & aSYSTEM)) {
		DEBUG(4, ("skipping %s - system bit is set\n", finfo.name));
		shallitime=0;
	} else if (!tar_hidden && (finfo.mode & aHIDDEN)) {
		DEBUG(4, ("skipping %s - hidden bit is set\n", finfo.name));
		shallitime=0;
	} else {
		DEBUG(3,("getting file %s of size %.0f bytes as a tar file %s",
			finfo.name, (double)finfo.size, lname));
      
		/* write a tar header, don't bother with mode - just set to 100644 */
		writetarheader(tarhandle, rname, finfo.size, finfo.mtime, "100644 \0", ftype);

		while (nread < finfo.size && !close_done) {
	      
			DEBUG(3,("nread=%.0f\n",(double)nread));
	      
			datalen = cli_read(cli, fnum, data, nread, read_size);
	      
			if (datalen == -1) {
				DEBUG(0,("Error reading file %s : %s\n", rname, cli_errstr(cli)));
				break;
			}
	      
			nread += datalen;

			/* if file size has increased since we made file size query, truncate
				read so tar header for this file will be correct.
			*/

			if (nread > finfo.size) {
				datalen -= nread - finfo.size;
				DEBUG(0,("File size change - truncating %s to %.0f bytes\n",
							finfo.name, (double)finfo.size));
			}

			/* add received bits of file to buffer - dotarbuf will
			* write out in 512 byte intervals */

			if (dotarbuf(tarhandle,data,datalen) != datalen) {
				DEBUG(0,("Error writing to tar file - %s\n", strerror(errno)));
				break;
			}
	      
			if (datalen == 0) {
				DEBUG(0,("Error reading file %s. Got 0 bytes\n", rname));
				break;
			}

			datalen=0;
		}

		/* pad tar file with zero's if we couldn't get entire file */
		if (nread < finfo.size) {
			DEBUG(0, ("Didn't get entire file. size=%.0f, nread=%d\n",
						(double)finfo.size, (int)nread));
			if (padit(data, sizeof(data), finfo.size - nread))
				DEBUG(0,("Error writing tar file - %s\n", strerror(errno)));
		}

		/* round tar file to nearest block */
		if (finfo.size % TBLOCK)
			dozerobuf(tarhandle, TBLOCK - (finfo.size % TBLOCK));
      
		ttarf+=finfo.size + TBLOCK - (finfo.size % TBLOCK);
		ntarf++;
	}
  
	cli_close(cli, fnum);

	if (shallitime) {
		struct timeval tp_end;
		int this_time;

		/* if shallitime is true then we didn't skip */
		if (tar_reset && !dry_run)
			(void) do_setrattr(finfo.name, aARCH, ATTRRESET);
      
		GetTimeOfDay(&tp_end);
		this_time = (tp_end.tv_sec - tp_start.tv_sec)*1000 + (tp_end.tv_usec - tp_start.tv_usec)/1000;
		get_total_time_ms += this_time;
		get_total_size += finfo.size;

		if (tar_noisy) {
			DEBUG(0, ("%12.0f (%7.1f kb/s) %s\n",
				(double)finfo.size, finfo.size / MAX(0.001, (1.024*this_time)),
				finfo.name));
		}

		/* Thanks to Carel-Jan Engel ([email protected]) for this one */
		DEBUG(3,("(%g kb/s) (average %g kb/s)\n",
				finfo.size / MAX(0.001, (1.024*this_time)),
				get_total_size / MAX(0.001, (1.024*get_total_time_ms))));
	}
}
コード例 #22
0
ファイル: cli_pipe.c プロジェクト: Nymphetaminer/dsl-n55u
BOOL cli_nt_session_open(struct cli_state *cli, const int pipe_idx)
{
	int fnum;

	/* At the moment we can't have more than one pipe open over
           a cli connection. )-: */

	SMB_ASSERT(cli->nt_pipe_fnum == 0);
	
	/* The pipe index must fall within our array */

	SMB_ASSERT((pipe_idx >= 0) && (pipe_idx < PI_MAX_PIPES));

	if (cli->capabilities & CAP_NT_SMBS) {
		if ((fnum = cli_nt_create(cli, &pipe_names[pipe_idx].client_pipe[5], DESIRED_ACCESS_PIPE)) == -1) {
			DEBUG(0,("cli_nt_session_open: cli_nt_create failed on pipe %s to machine %s.  Error was %s\n",
				 &pipe_names[pipe_idx].client_pipe[5], cli->desthost, cli_errstr(cli)));
			return False;
		}

		cli->nt_pipe_fnum = (uint16)fnum;
	} else {
		if ((fnum = cli_open(cli, pipe_names[pipe_idx].client_pipe, O_CREAT|O_RDWR, DENY_NONE)) == -1) {
			DEBUG(1,("cli_nt_session_open: cli_open failed on pipe %s to machine %s.  Error was %s\n",
				 pipe_names[pipe_idx].client_pipe, cli->desthost, cli_errstr(cli)));
			return False;
		}

		cli->nt_pipe_fnum = (uint16)fnum;

		/**************** Set Named Pipe State ***************/
		if (!rpc_pipe_set_hnd_state(cli, pipe_names[pipe_idx].client_pipe, 0x4300)) {
			DEBUG(0,("cli_nt_session_open: pipe hnd state failed.  Error was %s\n",
				  cli_errstr(cli)));
			cli_close(cli, cli->nt_pipe_fnum);
			cli->nt_pipe_fnum = 0;
			return False;
		}
	}

	/******************* bind request on pipe *****************/

	if (!rpc_pipe_bind(cli, pipe_idx, global_myname())) {
		DEBUG(2,("cli_nt_session_open: rpc bind to %s failed\n",
			 get_pipe_name_from_index(pipe_idx)));
		cli_close(cli, cli->nt_pipe_fnum);
		cli->nt_pipe_fnum = 0;
		return False;
	}

	cli->pipe_idx = pipe_idx;

	/* 
	 * Setup the remote server name prefixed by \ and the machine account name.
	 */

	fstrcpy(cli->srv_name_slash, "\\\\");
	fstrcat(cli->srv_name_slash, cli->desthost);
	strupper_m(cli->srv_name_slash);

	fstrcpy(cli->clnt_name_slash, "\\\\");
	fstrcat(cli->clnt_name_slash, global_myname());
	strupper_m(cli->clnt_name_slash);

	fstrcpy(cli->mach_acct, global_myname());
	fstrcat(cli->mach_acct, "$");
	strupper_m(cli->mach_acct);

	/* Remember which pipe we're talking to */
	fstrcpy(cli->pipe_name, pipe_names[pipe_idx].client_pipe);

	return True;
}
コード例 #23
0
ファイル: libsmb_file.c プロジェクト: Alexander--/samba
/*
 * Set file info on an SMB server.  Use setpathinfo call first.  If that
 * fails, use setattrE..
 *
 * Access and modification time parameters are always used and must be
 * provided.  Create time, if zero, will be determined from the actual create
 * time of the file.  If non-zero, the create time will be set as well.
 *
 * "mode" (attributes) parameter may be set to -1 if it is not to be set.
 */
bool
SMBC_setatr(SMBCCTX * context, SMBCSRV *srv, char *path,
            time_t create_time,
            time_t access_time,
            time_t write_time,
            time_t change_time,
            uint16_t mode)
{
        uint16_t fd;
        int ret;
	TALLOC_CTX *frame = talloc_stackframe();

        /*
         * First, try setpathinfo (if qpathinfo succeeded), for it is the
         * modern function for "new code" to be using, and it works given a
         * filename rather than requiring that the file be opened to have its
         * attributes manipulated.
         */
        if (srv->no_pathinfo ||
            !NT_STATUS_IS_OK(cli_setpathinfo_basic(srv->cli, path,
						   create_time,
						   access_time,
						   write_time,
						   change_time,
						   mode))) {

                /*
                 * setpathinfo is not supported; go to plan B.
                 *
                 * cli_setatr() does not work on win98, and it also doesn't
                 * support setting the access time (only the modification
                 * time), so in all cases, we open the specified file and use
                 * cli_setattrE() which should work on all OS versions, and
                 * supports both times.
                 */

                /* Don't try {q,set}pathinfo() again, with this server */
                srv->no_pathinfo = True;

                /* Open the file */
                if (!NT_STATUS_IS_OK(cli_open(srv->cli, path, O_RDWR, DENY_NONE, &fd))) {
                        errno = SMBC_errno(context, srv->cli);
			TALLOC_FREE(frame);
                        return -1;
                }

                /* Set the new attributes */
                ret = NT_STATUS_IS_OK(cli_setattrE(srv->cli, fd,
                                   change_time,
                                   access_time,
                                   write_time));

                /* Close the file */
                cli_close(srv->cli, fd);

                /*
                 * Unfortunately, setattrE() doesn't have a provision for
                 * setting the access mode (attributes).  We'll have to try
                 * cli_setatr() for that, and with only this parameter, it
                 * seems to work on win98.
                 */
                if (ret && mode != (uint16_t) -1) {
                        ret = NT_STATUS_IS_OK(cli_setatr(srv->cli, path, mode, 0));
                }

                if (! ret) {
                        errno = SMBC_errno(context, srv->cli);
			TALLOC_FREE(frame);
                        return False;
                }
        }

	TALLOC_FREE(frame);
        return True;
}
コード例 #24
0
ファイル: libsmb_file.c プロジェクト: sprymak/samba
int
SMBC_close_ctx(SMBCCTX *context,
               SMBCFILE *file)
{
        SMBCSRV *srv;
	char *server = NULL, *share = NULL, *user = NULL, *password = NULL;
	char *path = NULL;
	char *targetpath = NULL;
	struct cli_state *targetcli = NULL;
	TALLOC_CTX *frame = talloc_stackframe();
	NTSTATUS status;

	if (!context || !context->internal->initialized) {
		errno = EINVAL;
		TALLOC_FREE(frame);
		return -1;
	}

	if (!file || !SMBC_dlist_contains(context->internal->files, file)) {
		errno = EBADF;
		TALLOC_FREE(frame);
		return -1;
	}

	/* IS a dir ... */
	if (!file->file) {
		TALLOC_FREE(frame);
		return smbc_getFunctionClosedir(context)(context, file);
	}

	/*d_printf(">>>close: parsing %s\n", file->fname);*/
	if (SMBC_parse_path(frame,
                            context,
                            file->fname,
                            NULL,
                            &server,
                            &share,
                            &path,
                            &user,
                            &password,
                            NULL)) {
                errno = EINVAL;
		TALLOC_FREE(frame);
                return -1;
        }

	/*d_printf(">>>close: resolving %s\n", path);*/
	status = cli_resolve_path(frame, "", context->internal->auth_info,
				  file->srv->cli, path,
				  &targetcli, &targetpath);
	if (!NT_STATUS_IS_OK(status)) {
		d_printf("Could not resolve %s\n", path);
                errno = ENOENT;
		TALLOC_FREE(frame);
		return -1;
	}
	/*d_printf(">>>close: resolved path as %s\n", targetpath);*/

	if (!NT_STATUS_IS_OK(cli_close(targetcli, file->cli_fd))) {
		DEBUG(3, ("cli_close failed on %s. purging server.\n", 
			  file->fname));
		/* Deallocate slot and remove the server 
		 * from the server cache if unused */
		errno = SMBC_errno(context, targetcli);
		srv = file->srv;
		DLIST_REMOVE(context->internal->files, file);
		SAFE_FREE(file->fname);
		SAFE_FREE(file);
		smbc_getFunctionRemoveUnusedServer(context)(context, srv);
		TALLOC_FREE(frame);
		return -1;
	}

	DLIST_REMOVE(context->internal->files, file);
	SAFE_FREE(file->fname);
	SAFE_FREE(file);
	TALLOC_FREE(frame);
	return 0;
}
コード例 #25
0
ファイル: mangle_test.c プロジェクト: DanilKorotenko/samba
static bool test_one(struct cli_state *cli, const char *name)
{
	uint16_t fnum;
	fstring shortname;
	fstring name2;
	NTSTATUS status;
	TDB_DATA data;

	total++;

	status = cli_openx(cli, name, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
	if (!NT_STATUS_IS_OK(status)) {
		printf("open of %s failed (%s)\n", name, nt_errstr(status));
		return False;
	}

	status = cli_close(cli, fnum);
	if (!NT_STATUS_IS_OK(status)) {
		printf("close of %s failed (%s)\n", name, nt_errstr(status));
		return False;
	}

	/* get the short name */
	status = cli_qpathinfo_alt_name(cli, name, shortname);
	if (!NT_STATUS_IS_OK(status)) {
		printf("query altname of %s failed (%s)\n", name, nt_errstr(status));
		return False;
	}

	fstr_sprintf(name2, "\\mangle_test\\%s", shortname);
	status = cli_unlink(cli, name2, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
	if (!NT_STATUS_IS_OK(status)) {
		printf("unlink of %s  (%s) failed (%s)\n", 
		       name2, name, nt_errstr(status));
		return False;
	}

	/* recreate by short name */
	status = cli_openx(cli, name2, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);
	if (!NT_STATUS_IS_OK(status)) {
		printf("open2 of %s failed (%s)\n", name2, nt_errstr(status));
		return False;
	}

	status = cli_close(cli, fnum);
	if (!NT_STATUS_IS_OK(status)) {
		printf("close of %s failed (%s)\n", name, nt_errstr(status));
		return False;
	}

	/* and unlink by long name */
	status = cli_unlink(cli, name, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
	if (!NT_STATUS_IS_OK(status)) {
		printf("unlink2 of %s  (%s) failed (%s)\n", 
		       name, name2, nt_errstr(status));
		failures++;
		cli_unlink(cli, name2, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
		return True;
	}

	/* see if the short name is already in the tdb */
	data = tdb_fetch_bystring(tdb, shortname);
	if (data.dptr) {
		/* maybe its a duplicate long name? */
		if (!strequal(name, (const char *)data.dptr)) {
			/* we have a collision */
			collisions++;
			printf("Collision between %s and %s   ->  %s "
				" (coll/tot: %u/%u)\n", 
				name, data.dptr, shortname, collisions, total);
		}
		free(data.dptr);
	} else {
		TDB_DATA namedata;
		/* store it for later */
		namedata.dptr = discard_const_p(uint8_t, name);
		namedata.dsize = strlen(name)+1;
		tdb_store_bystring(tdb, shortname, namedata, TDB_REPLACE);
	}

	return True;
}
コード例 #26
0
ファイル: cli_pipe.c プロジェクト: Nymphetaminer/dsl-n55u
NTSTATUS cli_nt_establish_netlogon(struct cli_state *cli, int sec_chan,
				   const uchar trust_password[16])
{
	NTSTATUS result;	
	uint32 neg_flags = NETLOGON_NEG_AUTH2_FLAGS;
	int fnum;

	cli_nt_netlogon_netsec_session_close(cli);

	if (lp_client_schannel() != False)
		neg_flags |= NETLOGON_NEG_SCHANNEL;

	result = cli_nt_setup_creds(cli, sec_chan, trust_password,
				    &neg_flags, 2);

	if (!NT_STATUS_IS_OK(result)) {
		cli_nt_session_close(cli);
		return result;
	}

	if ((lp_client_schannel() == True) &&
	    ((neg_flags & NETLOGON_NEG_SCHANNEL) == 0)) {

		DEBUG(3, ("Server did not offer schannel\n"));
		cli_nt_session_close(cli);
		return NT_STATUS_UNSUCCESSFUL;
	}

	if ((lp_client_schannel() == False) ||
	    ((neg_flags & NETLOGON_NEG_SCHANNEL) == 0)) {
		return NT_STATUS_OK;
		
		/* keep the existing connection to NETLOGON open */

	}

	/* Server offered schannel, so try it. */

	memcpy(cli->auth_info.sess_key, cli->sess_key,
	       sizeof(cli->auth_info.sess_key));

	cli->saved_netlogon_pipe_fnum = cli->nt_pipe_fnum;

	cli->pipe_auth_flags = AUTH_PIPE_NETSEC;
	cli->pipe_auth_flags |= AUTH_PIPE_SIGN;
	cli->pipe_auth_flags |= AUTH_PIPE_SEAL;

	if (cli->capabilities & CAP_NT_SMBS) {

		/* The secure channel connection must be opened on the same 
                   session (TCP connection) as the one the challenge was
                   requested from. */
		if ((fnum = cli_nt_create(cli, PIPE_NETLOGON_PLAIN,
					  DESIRED_ACCESS_PIPE)) == -1) {
			DEBUG(0,("cli_nt_create failed to %s machine %s. "
				 "Error was %s\n",
				 PIPE_NETLOGON, cli->desthost,
				 cli_errstr(cli)));
			return NT_STATUS_UNSUCCESSFUL;
		}
		
		cli->nt_pipe_fnum = (uint16)fnum;
	} else {
		if ((fnum = cli_open(cli, PIPE_NETLOGON,
				     O_CREAT|O_RDWR, DENY_NONE)) == -1) {
			DEBUG(0,("cli_open failed on pipe %s to machine %s. "
				 "Error was %s\n",
				 PIPE_NETLOGON, cli->desthost,
				 cli_errstr(cli)));
			return NT_STATUS_UNSUCCESSFUL;
		}

		cli->nt_pipe_fnum = (uint16)fnum;

		/**************** Set Named Pipe State ***************/
		if (!rpc_pipe_set_hnd_state(cli, PIPE_NETLOGON, 0x4300)) {
			DEBUG(0,("Pipe hnd state failed.  Error was %s\n",
				  cli_errstr(cli)));
			cli_close(cli, cli->nt_pipe_fnum);
			return NT_STATUS_UNSUCCESSFUL;
		}
	}
	
	if (!rpc_pipe_bind(cli, PI_NETLOGON, global_myname())) {
		DEBUG(2,("rpc bind to %s failed\n", PIPE_NETLOGON));
		cli_close(cli, cli->nt_pipe_fnum);
		return NT_STATUS_UNSUCCESSFUL;
	}

	return NT_STATUS_OK;
}
コード例 #27
0
ファイル: smbcquotas.c プロジェクト: Nymphetaminer/dsl-n55u
static int parse_quota_set(pstring set_str, pstring username_str, enum SMB_QUOTA_TYPE *qtype, int *cmd, SMB_NTQUOTA_STRUCT *pqt)
{
	char *p = set_str,*p2;
	int todo;
	BOOL stop = False;
	BOOL enable = False;
	BOOL deny = False;
	
	if (strnequal(set_str,"UQLIM:",6)) {
		p += 6;
		*qtype = SMB_USER_QUOTA_TYPE;
		*cmd = QUOTA_SETLIM;
		todo = PARSE_LIM;
		if ((p2=strstr(p,":"))==NULL) {
			return -1;
		}
		
		*p2 = '\0';
		p2++;
		
		fstrcpy(username_str,p);
		p = p2;
	} else if (strnequal(set_str,"FSQLIM:",7)) {
		p +=7;
		*qtype = SMB_USER_FS_QUOTA_TYPE;
		*cmd = QUOTA_SETLIM;
		todo = PARSE_LIM;
	} else if (strnequal(set_str,"FSQFLAGS:",9)) {
		p +=9;
		todo = PARSE_FLAGS;
		*qtype = SMB_USER_FS_QUOTA_TYPE;
		*cmd = QUOTA_SETFLAGS;
	} else {
		return -1;
	}

	switch (todo) {
		case PARSE_LIM:
#if defined(HAVE_LONGLONG)
			if (sscanf(p,"%llu/%llu",&pqt->softlim,&pqt->hardlim)!=2) {
#else
			if (sscanf(p,"%lu/%lu",&pqt->softlim,&pqt->hardlim)!=2) {
#endif
				return -1;
			}
			
			break;
		case PARSE_FLAGS:
			while (!stop) {

				if ((p2=strstr(p,"/"))==NULL) {
					stop = True;
				} else {
					*p2 = '\0';
					p2++;
				}

				if (strnequal(p,"QUOTA_ENABLED",13)) {
					enable = True;
				} else if (strnequal(p,"DENY_DISK",9)) {
					deny = True;
				} else if (strnequal(p,"LOG_SOFTLIMIT",13)) {
					pqt->qflags |= QUOTAS_LOG_THRESHOLD;
				} else if (strnequal(p,"LOG_HARDLIMIT",13)) {
					pqt->qflags |= QUOTAS_LOG_LIMIT;
				} else {
					return -1;
				}

				p=p2;
			}

			if (deny) {
				pqt->qflags |= QUOTAS_DENY_DISK;
			} else if (enable) {
				pqt->qflags |= QUOTAS_ENABLED;
			}
			
			break;	
	}

	return 0;
}

static int do_quota(struct cli_state *cli, enum SMB_QUOTA_TYPE qtype, uint16 cmd, pstring username_str, SMB_NTQUOTA_STRUCT *pqt)
{
	uint32 fs_attrs = 0;
	int quota_fnum = 0;
	SMB_NTQUOTA_LIST *qtl = NULL;
	SMB_NTQUOTA_STRUCT qt;
	ZERO_STRUCT(qt);

	if (!cli_get_fs_attr_info(cli, &fs_attrs)) {
		d_printf("Failed to get the filesystem attributes %s.\n",
			cli_errstr(cli));
		return -1;
	}

	if (!(fs_attrs & FILE_VOLUME_QUOTAS)) {
		d_printf("Quotas are not supported by the server.\n");
		return 0;	
	}

	if (!cli_get_quota_handle(cli, &quota_fnum)) {
		d_printf("Failed to open \\%s  %s.\n",
			FAKE_FILE_NAME_QUOTA,cli_errstr(cli));
		return -1;
	}

	switch(qtype) {
		case SMB_USER_QUOTA_TYPE:
			if (!StringToSid(&qt.sid, username_str)) {
				d_printf("StringToSid() failed for [%s]\n",username_str);
				return -1;
			}
			
			switch(cmd) {
				case QUOTA_GET:
					if (!cli_get_user_quota(cli, quota_fnum, &qt)) {
						d_printf("%s cli_get_user_quota %s\n",
							 cli_errstr(cli),username_str);
						return -1;
					}
					dump_ntquota(&qt,verbose,numeric,SidToString);
					break;
				case QUOTA_SETLIM:
					pqt->sid = qt.sid;
					if (!cli_set_user_quota(cli, quota_fnum, pqt)) {
						d_printf("%s cli_set_user_quota %s\n",
							 cli_errstr(cli),username_str);
						return -1;
					}
					if (!cli_get_user_quota(cli, quota_fnum, &qt)) {
						d_printf("%s cli_get_user_quota %s\n",
							 cli_errstr(cli),username_str);
						return -1;
					}
					dump_ntquota(&qt,verbose,numeric,SidToString);
					break;
				case QUOTA_LIST:
					if (!cli_list_user_quota(cli, quota_fnum, &qtl)) {
						d_printf("%s cli_set_user_quota %s\n",
							 cli_errstr(cli),username_str);
						return -1;
					}
					dump_ntquota_list(&qtl,verbose,numeric,SidToString);
					free_ntquota_list(&qtl);					
					break;
				default:
					d_printf("Unknown Error\n");
					return -1;
			} 
			break;
		case SMB_USER_FS_QUOTA_TYPE:
			switch(cmd) {
				case QUOTA_GET:
					if (!cli_get_fs_quota_info(cli, quota_fnum, &qt)) {
						d_printf("%s cli_get_fs_quota_info\n",
							 cli_errstr(cli));
						return -1;
					}
					dump_ntquota(&qt,True,numeric,NULL);
					break;
				case QUOTA_SETLIM:
					if (!cli_get_fs_quota_info(cli, quota_fnum, &qt)) {
						d_printf("%s cli_get_fs_quota_info\n",
							 cli_errstr(cli));
						return -1;
					}
					qt.softlim = pqt->softlim;
					qt.hardlim = pqt->hardlim;
					if (!cli_set_fs_quota_info(cli, quota_fnum, &qt)) {
						d_printf("%s cli_set_fs_quota_info\n",
							 cli_errstr(cli));
						return -1;
					}
					if (!cli_get_fs_quota_info(cli, quota_fnum, &qt)) {
						d_printf("%s cli_get_fs_quota_info\n",
							 cli_errstr(cli));
						return -1;
					}
					dump_ntquota(&qt,True,numeric,NULL);
					break;
				case QUOTA_SETFLAGS:
					if (!cli_get_fs_quota_info(cli, quota_fnum, &qt)) {
						d_printf("%s cli_get_fs_quota_info\n",
							 cli_errstr(cli));
						return -1;
					}
					qt.qflags = pqt->qflags;
					if (!cli_set_fs_quota_info(cli, quota_fnum, &qt)) {
						d_printf("%s cli_set_fs_quota_info\n",
							 cli_errstr(cli));
						return -1;
					}
					if (!cli_get_fs_quota_info(cli, quota_fnum, &qt)) {
						d_printf("%s cli_get_fs_quota_info\n",
							 cli_errstr(cli));
						return -1;
					}
					dump_ntquota(&qt,True,numeric,NULL);
					break;
				default:
					d_printf("Unknown Error\n");
					return -1;
			} 		
			break;
		default:
			d_printf("Unknown Error\n");
			return -1;
	}

	cli_close(cli, quota_fnum);

	return 0;
}
コード例 #28
0
ファイル: obexfs.c プロジェクト: zuckschwerdt/obexfs
static void ofs_destroy(void *UNUSED(private_data)) {
	fprintf(stderr, "terminating...\n");
	cli_close();
	return;
}
コード例 #29
0
ファイル: smbw.c プロジェクト: livebox/livebox2
/***************************************************** 
a wrapper for open()
*******************************************************/
int smbw_open(const char *fname, int flags, mode_t mode)
{
	fstring server, share;
	pstring path;
	struct smbw_server *srv=NULL;
	int eno=0, fd = -1;
	struct smbw_file *file=NULL;

	smbw_init();

	if (!fname) {
		errno = EINVAL;
		return -1;
	}

	smbw_busy++;	

	/* work out what server they are after */
	smbw_parse_path(fname, server, share, path);

	/* get a connection to the server */
	srv = smbw_server(server, share);
	if (!srv) {
		/* smbw_server sets errno */
		goto failed;
	}

	if (path[strlen(path)-1] == '\\') {
		fd = -1;
	} else {
		fd = cli_open(&srv->cli, path, flags, DENY_NONE);
	}
	if (fd == -1) {
		/* it might be a directory. Maybe we should use chkpath? */
		eno = smbw_errno(&srv->cli);
		fd = smbw_dir_open(fname);
		if (fd == -1) errno = eno;
		smbw_busy--;
		return fd;
	}

	file = (struct smbw_file *)malloc(sizeof(*file));
	if (!file) {
		errno = ENOMEM;
		goto failed;
	}

	ZERO_STRUCTP(file);

	file->f = (struct smbw_filedes *)malloc(sizeof(*(file->f)));
	if (!file->f) {
		errno = ENOMEM;
		goto failed;
	}

	ZERO_STRUCTP(file->f);

	file->f->cli_fd = fd;
	file->f->fname = strdup(path);
	if (!file->f->fname) {
		errno = ENOMEM;
		goto failed;
	}
	file->srv = srv;
	file->fd = open(SMBW_DUMMY, O_WRONLY);
	if (file->fd == -1) {
		errno = EMFILE;
		goto failed;
	}

	if (bitmap_query(smbw_file_bmap, file->fd)) {
		DEBUG(0,("ERROR: fd used in smbw_open\n"));
		errno = EIO;
		goto failed;
	}

	file->f->ref_count=1;

	bitmap_set(smbw_file_bmap, file->fd);

	DLIST_ADD(smbw_files, file);

	DEBUG(4,("opened %s\n", fname));

	smbw_busy--;
	return file->fd;

 failed:
	if (fd != -1) {
		cli_close(&srv->cli, fd);
	}
	if (file) {
		if (file->f) {
			SAFE_FREE(file->f->fname);
			SAFE_FREE(file->f);
		}
		SAFE_FREE(file);
	}
	smbw_busy--;
	return -1;
}
コード例 #30
0
ファイル: obexfs.c プロジェクト: zuckschwerdt/obexfs
int main(int argc, char *argv[])
{
	int res;
	
	while (1) {
		int option_index = 0;
		int c;
		static struct option long_options[] = {
			{"irda",	no_argument, NULL, 'i'},
			{"bluetooth",	required_argument, NULL, 'b'},
			{"channel",	required_argument, NULL, 'B'},
			{"hci",	required_argument, NULL, 'd'},
			{"usb",		required_argument, NULL, 'u'},
			{"tty",		required_argument, NULL, 't'},
			{"network",	required_argument, NULL, 'n'},
			{"nonblock",	no_argument, NULL, 'N'},
			{"help",	no_argument, NULL, 'h'},
			{"usage",	no_argument, NULL, 'h'},
			{0, 0, 0, 0}
		};
		
		c = getopt_long (argc, argv, "+ib:B:d:u:t:n:Nh",
				 long_options, &option_index);
		if (c == -1)
			break;

		switch (c) {
		
		case 'i':
			transport = OBEX_TRANS_IRDA;
			device = NULL;
			channel = 0;
			break;
		
		case 'b':
			transport = OBEX_TRANS_BLUETOOTH;
			device = optarg;
			channel = -1;
			break;
			
		case 'B':
			channel = atoi(optarg);
			break;

		case 'd':
			source = optarg;
			break;
			
		case 'u':
			if (geteuid() != 0)
				fprintf(stderr, "If USB doesn't work setup permissions in udev or run as superuser.\n");
			transport = OBEX_TRANS_USB;
			device = NULL;
			channel = atoi(optarg);
			break;
		
		case 't':
			transport = OBEX_TRANS_CUSTOM;
			device = optarg;
			channel = 0;
			break;
			
		case 'n':
			transport = OBEX_TRANS_INET;
			device = optarg;
			channel = 650;
			{
                                int n;
                                if (sscanf(optarg, "%d.%d.%d.%d", &n, &n, &n, &n) != 4)
                                        fprintf(stderr, "Please use dotted quad notation.\n");
                        }
			break;
			
		case 'N':
			nonblock = 1;
			break;

		case 'h':
			/* printf("ObexFS %s\n", VERSION); */
			printf("Usage: %s [-i | -b <dev> [-B <chan>] [-d <hci>] | -u <dev> | -t <dev> | -n <dev>] [-- <fuse options>]\n"
				"Transfer files from/to Mobile Equipment.\n"
				"Copyright (c) 2002-2005 Christian W. Zuckschwerdt\n"
				"\n"
				" -i, --irda                  connect using IrDA transport\n"
				" -b, --bluetooth <device>    connect to this bluetooth device\n"
				" -B, --channel <number>      use this bluetooth channel when connecting\n"
				" -d, --hci <no/address>      use source device with this address or number\n"
				" -u, --usb <interface>       connect to this usb interface number\n"
				" -t, --tty <device>          connect to this tty using a custom transport\n"
				" -n, --network <device>      connect to this network host\n\n"
				" -N, --nonblock              nonblocking mode\n\n"
				" -h, --help, --usage         this help text\n\n"
				"Options to fusermount need to be preceeded by two dashes (--).\n"
				"\n",
				argv[0]);
			exit(0);
			break;

		default:
			printf("Try `%s --help' for more information.\n",
				 argv[0]);
			exit(0);
		}
	}

	if (transport == 0) {
	       	fprintf(stderr, "No device selected. Use --help for help.\n");
		exit(0);
	}

	argv[optind-1] = argv[0];

        /* Open connection */
	res = cli_open();
	if(res < 0)
		return res; /* errno */
	
	/* loop */
	fuse_main(argc-optind+1, &argv[optind-1], &ofs_oper);
	
        /* Close connection */
	cli_close();

	return 0;
}