From 402affb0d70d10feefbaa214206210496ebbf700 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 1 Mar 2007 21:56:54 +0000 Subject: r21641: Add test code for POSIX pathname calls into smbclient. Jeremy. (This used to be commit 9858e5b72526360fc415b848a84042e09d9b2453) --- source3/client/client.c | 147 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) (limited to 'source3/client') diff --git a/source3/client/client.c b/source3/client/client.c index 8109dea37d..b132c31fd8 100644 --- a/source3/client/client.c +++ b/source3/client/client.c @@ -1747,6 +1747,146 @@ static int cmd_open(void) return 0; } +/**************************************************************************** +****************************************************************************/ + +static int cmd_posix_open(void) +{ + pstring mask; + pstring buf; + struct cli_state *targetcli; + pstring targetname; + mode_t mode; + int fnum; + + pstrcpy(mask,cur_dir); + + if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) { + d_printf("posix_open 0\n"); + return 1; + } + pstrcat(mask,buf); + if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) { + d_printf("posix_open 0\n"); + return 1; + } + mode = (mode_t)strtol(buf, (char **)NULL, 8); + + if (!cli_resolve_path( "", cli, mask, &targetcli, targetname )) { + d_printf("posix_open %s: %s\n", mask, cli_errstr(cli)); + return 1; + } + + fnum = cli_posix_open(targetcli, targetname, O_CREAT|O_RDWR, mode); + if (fnum == -1) { + fnum = cli_posix_open(targetcli, targetname, O_CREAT|O_RDONLY, mode); + if (fnum != -1) { + d_printf("posix_open file %s: for read/write fnum %d\n", targetname, fnum); + } else { + d_printf("Failed to open file %s. %s\n", targetname, cli_errstr(cli)); + } + } else { + d_printf("posix_open file %s: for read/write fnum %d\n", targetname, fnum); + } + + return 0; +} + +static int cmd_posix_mkdir(void) +{ + pstring mask; + pstring buf; + struct cli_state *targetcli; + pstring targetname; + mode_t mode; + int fnum; + + pstrcpy(mask,cur_dir); + + if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) { + d_printf("posix_mkdir 0\n"); + return 1; + } + pstrcat(mask,buf); + if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) { + d_printf("posix_mkdir 0\n"); + return 1; + } + mode = (mode_t)strtol(buf, (char **)NULL, 8); + + if (!cli_resolve_path( "", cli, mask, &targetcli, targetname )) { + d_printf("posix_mkdir %s: %s\n", mask, cli_errstr(cli)); + return 1; + } + + fnum = cli_posix_mkdir(targetcli, targetname, mode); + if (fnum == -1) { + d_printf("Failed to open file %s. %s\n", targetname, cli_errstr(cli)); + } else { + d_printf("posix_mkdir created directory %s\n", targetname); + } + + return 0; +} + +static int cmd_posix_unlink(void) +{ + pstring mask; + pstring buf; + struct cli_state *targetcli; + pstring targetname; + + pstrcpy(mask,cur_dir); + + if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) { + d_printf("posix_unlink \n"); + return 1; + } + pstrcat(mask,buf); + + if (!cli_resolve_path( "", cli, mask, &targetcli, targetname )) { + d_printf("posix_unlink %s: %s\n", mask, cli_errstr(cli)); + return 1; + } + + if (!cli_posix_unlink(targetcli, targetname)) { + d_printf("Failed to unlink file %s. %s\n", targetname, cli_errstr(cli)); + } else { + d_printf("posix_unlink deleted file %s\n", targetname); + } + + return 0; +} + +static int cmd_posix_rmdir(void) +{ + pstring mask; + pstring buf; + struct cli_state *targetcli; + pstring targetname; + + pstrcpy(mask,cur_dir); + + if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) { + d_printf("posix_rmdir \n"); + return 1; + } + pstrcat(mask,buf); + + if (!cli_resolve_path( "", cli, mask, &targetcli, targetname)) { + d_printf("posix_rmdir %s: %s\n", mask, cli_errstr(cli)); + return 1; + } + + if (!cli_posix_rmdir(targetcli, targetname)) { + d_printf("Failed to unlink directory %s. %s\n", targetname, cli_errstr(cli)); + } else { + d_printf("posix_rmdir deleted directory %s\n", targetname); + } + + return 0; +} + static int cmd_close(void) { fstring buf; @@ -1797,6 +1937,9 @@ static int cmd_posix(void) if (caplow & CIFS_UNIX_POSIX_PATHNAMES_CAP) { pstrcat(caps, "pathnames "); } + if (caplow & CIFS_UNIX_POSIX_PATH_OPERATIONS_CAP) { + pstrcat(caps, "posix_path_operations "); + } if (strlen(caps) > 0 && caps[strlen(caps)-1] == ' ') { caps[strlen(caps)-1] = '\0'; @@ -3035,6 +3178,10 @@ static struct {"newer",cmd_newer," only mget files newer than the specified local file",{COMPL_LOCAL,COMPL_NONE}}, {"open",cmd_open," open a file",{COMPL_REMOTE,COMPL_NONE}}, {"posix", cmd_posix, "turn on all POSIX capabilities", {COMPL_REMOTE,COMPL_NONE}}, + {"posix_open",cmd_posix_open," 0 open_flags mode open a file using POSIX interface",{COMPL_REMOTE,COMPL_NONE}}, + {"posix_mkdir",cmd_posix_mkdir," 0 creates a directory using POSIX interface",{COMPL_REMOTE,COMPL_NONE}}, + {"posix_rmdir",cmd_posix_rmdir," removes a directory using POSIX interface",{COMPL_REMOTE,COMPL_NONE}}, + {"posix_unlink",cmd_posix_unlink," removes a file using POSIX interface",{COMPL_REMOTE,COMPL_NONE}}, {"print",cmd_print," print a file",{COMPL_NONE,COMPL_NONE}}, {"prompt",cmd_prompt,"toggle prompting for filenames for mget and mput",{COMPL_NONE,COMPL_NONE}}, {"put",cmd_put," [remote name] put a file",{COMPL_LOCAL,COMPL_REMOTE}}, -- cgit