#include "clilist.h"
#include "lib/cmdline/popt_common.h"
#include "librpc/gen_ndr/ndr_srvsvc.h"
+#include "librpc/gen_ndr/ndr_lsa.h"
#include "libcli/raw/libcliraw.h"
#include "system/time.h"
#include "system/dir.h"
if (NT_STATUS_IS_OK(status)) {
int i;
for (i=0;i<finfo.all_eas.out.num_eas;i++) {
- d_printf("\tEA[%d] flags=%d %s=%*.*s\n", i,
+ d_printf("\tEA[%d] flags=%d len=%d '%s'\n", i,
finfo.all_eas.out.eas[i].flags,
- finfo.all_eas.out.eas[i].name.s,
finfo.all_eas.out.eas[i].value.length,
- finfo.all_eas.out.eas[i].value.length,
- finfo.all_eas.out.eas[i].value.data);
+ finfo.all_eas.out.eas[i].name.s);
}
}
}
+/****************************************************************************
+shows EA contents
+****************************************************************************/
+static int cmd_eainfo(const char **cmd_ptr)
+{
+ pstring fname;
+ fstring buf;
+ int ret = 0;
+ TALLOC_CTX *mem_ctx;
+ union smb_fileinfo finfo;
+ NTSTATUS status;
+ int i;
+
+ pstrcpy(fname,cur_dir);
+
+ if (!next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
+ d_printf("eainfo <filename>\n");
+ return 1;
+ }
+ pstrcat(fname,buf);
+
+ mem_ctx = talloc_init("%s", fname);
+
+ finfo.generic.in.fname = fname;
+ finfo.generic.level = RAW_FILEINFO_ALL_EAS;
+ status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
+
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("RAW_FILEINFO_ALL_EAS - %s\n", nt_errstr(status));
+ talloc_destroy(mem_ctx);
+ return 1;
+ }
+
+ d_printf("%s has %d EAs\n", fname, finfo.all_eas.out.num_eas);
+
+ for (i=0;i<finfo.all_eas.out.num_eas;i++) {
+ d_printf("\tEA[%d] flags=%d len=%d '%s'\n", i,
+ finfo.all_eas.out.eas[i].flags,
+ finfo.all_eas.out.eas[i].value.length,
+ finfo.all_eas.out.eas[i].name.s);
+ fflush(stdout);
+ dump_data(0,
+ finfo.all_eas.out.eas[i].value.data,
+ finfo.all_eas.out.eas[i].value.length);
+ }
+
+ talloc_destroy(mem_ctx);
+
+ return ret;
+}
+
+
/****************************************************************************
show any ACL on a file
****************************************************************************/
}
pstrcat(fname,buf);
- fnum = smbcli_open(cli->tree, fname, O_RDONLY, DENY_NONE);
+ fnum = smbcli_nt_create_full(cli->tree, fname, 0,
+ SEC_STD_READ_CONTROL,
+ 0,
+ NTCREATEX_SHARE_ACCESS_DELETE|
+ NTCREATEX_SHARE_ACCESS_READ|
+ NTCREATEX_SHARE_ACCESS_WRITE,
+ NTCREATEX_DISP_OPEN,
+ 0, 0);
if (fnum == -1) {
d_printf("%s - %s\n", fname, smbcli_errstr(cli->tree));
return -1;
return ret;
}
+/****************************************************************************
+lookup a name or sid
+****************************************************************************/
+static int cmd_lookup(const char **cmd_ptr)
+{
+ fstring buf;
+ TALLOC_CTX *mem_ctx = talloc(NULL, 0);
+ NTSTATUS status;
+ struct dom_sid *sid;
+
+ if (!next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
+ d_printf("lookup <sid|name>\n");
+ talloc_free(mem_ctx);
+ return 1;
+ }
+
+ sid = dom_sid_parse_talloc(mem_ctx, buf);
+ if (sid == NULL) {
+ const char *sidstr;
+ status = smblsa_lookup_name(cli, buf, mem_ctx, &sidstr);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("lsa_LookupNames - %s\n", nt_errstr(status));
+ talloc_free(mem_ctx);
+ return 1;
+ }
+
+ d_printf("%s\n", sidstr);
+ } else {
+ const char *name;
+ status = smblsa_lookup_sid(cli, buf, mem_ctx, &name);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("lsa_LookupSids - %s\n", nt_errstr(status));
+ talloc_free(mem_ctx);
+ return 1;
+ }
+
+ d_printf("%s\n", name);
+ }
+
+ talloc_free(mem_ctx);
+
+ return 0;
+}
+
+/****************************************************************************
+show privileges for a user
+****************************************************************************/
+static int cmd_privileges(const char **cmd_ptr)
+{
+ fstring buf;
+ TALLOC_CTX *mem_ctx = talloc(NULL, 0);
+ NTSTATUS status;
+ struct dom_sid *sid;
+ struct lsa_RightSet rights;
+ unsigned i;
+
+ if (!next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
+ d_printf("privileges <sid|name>\n");
+ talloc_free(mem_ctx);
+ return 1;
+ }
+
+ sid = dom_sid_parse_talloc(mem_ctx, buf);
+ if (sid == NULL) {
+ const char *sid_str;
+ status = smblsa_lookup_name(cli, buf, mem_ctx, &sid_str);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("lsa_LookupNames - %s\n", nt_errstr(status));
+ talloc_free(mem_ctx);
+ return 1;
+ }
+ sid = dom_sid_parse_talloc(mem_ctx, sid_str);
+ }
+
+ status = smblsa_sid_privileges(cli, sid, mem_ctx, &rights);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("lsa_EnumAccountRights - %s\n", nt_errstr(status));
+ talloc_free(mem_ctx);
+ return 1;
+ }
+
+ for (i=0;i<rights.count;i++) {
+ d_printf("\t%s\n", rights.names[i].string);
+ }
+
+ talloc_free(mem_ctx);
+
+ return 0;
+}
+
+
+/****************************************************************************
+add privileges for a user
+****************************************************************************/
+static int cmd_addprivileges(const char **cmd_ptr)
+{
+ fstring buf;
+ TALLOC_CTX *mem_ctx = talloc(NULL, 0);
+ NTSTATUS status;
+ struct dom_sid *sid;
+ struct lsa_RightSet rights;
+
+ if (!next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
+ d_printf("addprivileges <sid|name> <privilege...>\n");
+ talloc_free(mem_ctx);
+ return 1;
+ }
+
+ sid = dom_sid_parse_talloc(mem_ctx, buf);
+ if (sid == NULL) {
+ const char *sid_str;
+ status = smblsa_lookup_name(cli, buf, mem_ctx, &sid_str);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("lsa_LookupNames - %s\n", nt_errstr(status));
+ talloc_free(mem_ctx);
+ return 1;
+ }
+ sid = dom_sid_parse_talloc(mem_ctx, sid_str);
+ }
+
+ ZERO_STRUCT(rights);
+ while (next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
+ rights.names = talloc_realloc_p(mem_ctx, rights.names,
+ struct lsa_String, rights.count+1);
+ rights.names[rights.count].string = talloc_strdup(mem_ctx, buf);
+ rights.count++;
+ }
+
+
+ status = smblsa_sid_add_privileges(cli, sid, mem_ctx, &rights);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("lsa_AddAccountRights - %s\n", nt_errstr(status));
+ talloc_free(mem_ctx);
+ return 1;
+ }
+
+ talloc_free(mem_ctx);
+
+ return 0;
+}
+
+/****************************************************************************
+delete privileges for a user
+****************************************************************************/
+static int cmd_delprivileges(const char **cmd_ptr)
+{
+ fstring buf;
+ TALLOC_CTX *mem_ctx = talloc(NULL, 0);
+ NTSTATUS status;
+ struct dom_sid *sid;
+ struct lsa_RightSet rights;
+
+ if (!next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
+ d_printf("delprivileges <sid|name> <privilege...>\n");
+ talloc_free(mem_ctx);
+ return 1;
+ }
+
+ sid = dom_sid_parse_talloc(mem_ctx, buf);
+ if (sid == NULL) {
+ const char *sid_str;
+ status = smblsa_lookup_name(cli, buf, mem_ctx, &sid_str);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("lsa_LookupNames - %s\n", nt_errstr(status));
+ talloc_free(mem_ctx);
+ return 1;
+ }
+ sid = dom_sid_parse_talloc(mem_ctx, sid_str);
+ }
+
+ ZERO_STRUCT(rights);
+ while (next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
+ rights.names = talloc_realloc_p(mem_ctx, rights.names,
+ struct lsa_String, rights.count+1);
+ rights.names[rights.count].string = talloc_strdup(mem_ctx, buf);
+ rights.count++;
+ }
+
+
+ status = smblsa_sid_del_privileges(cli, sid, mem_ctx, &rights);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("lsa_RemoveAccountRights - %s\n", nt_errstr(status));
+ talloc_free(mem_ctx);
+ return 1;
+ }
+
+ talloc_free(mem_ctx);
+
+ return 0;
+}
+
/****************************************************************************
****************************************************************************/
} commands[] =
{
{"?",cmd_help,"[command] give help on a command",{COMPL_NONE,COMPL_NONE}},
+ {"addprivileges",cmd_addprivileges,"<sid|name> <privilege...> add privileges for a user",{COMPL_NONE,COMPL_NONE}},
{"altname",cmd_altname,"<file> show alt name",{COMPL_NONE,COMPL_NONE}},
{"acl",cmd_acl,"<file> show file ACL",{COMPL_NONE,COMPL_NONE}},
{"allinfo",cmd_allinfo,"<file> show all possible info about a file",{COMPL_NONE,COMPL_NONE}},
{"chmod",cmd_chmod,"<src> <mode> chmod a file using UNIX permission",{COMPL_REMOTE,COMPL_REMOTE}},
{"chown",cmd_chown,"<src> <uid> <gid> chown a file using UNIX uids and gids",{COMPL_REMOTE,COMPL_REMOTE}},
{"del",cmd_del,"<mask> delete all matching files",{COMPL_REMOTE,COMPL_NONE}},
+ {"delprivileges",cmd_delprivileges,"<sid|name> <privilege...> remove privileges for a user",{COMPL_NONE,COMPL_NONE}},
{"deltree",cmd_deltree,"<dir> delete a whole directory tree",{COMPL_REMOTE,COMPL_NONE}},
{"dir",cmd_dir,"<mask> list the contents of the current directory",{COMPL_REMOTE,COMPL_NONE}},
{"du",cmd_du,"<mask> computes the total size of the current directory",{COMPL_REMOTE,COMPL_NONE}},
+ {"eainfo",cmd_eainfo,"<file> show EA contents for a file",{COMPL_NONE,COMPL_NONE}},
{"exit",cmd_quit,"logoff the server",{COMPL_NONE,COMPL_NONE}},
{"get",cmd_get,"<remote name> [local name] get a file",{COMPL_REMOTE,COMPL_LOCAL}},
{"help",cmd_help,"[command] give help on a command",{COMPL_NONE,COMPL_NONE}},
{"history",cmd_history,"displays the command history",{COMPL_NONE,COMPL_NONE}},
{"lcd",cmd_lcd,"[directory] change/report the local current working directory",{COMPL_LOCAL,COMPL_NONE}},
{"link",cmd_link,"<src> <dest> create a UNIX hard link",{COMPL_REMOTE,COMPL_REMOTE}},
+ {"lookup",cmd_lookup,"<sid|name> show SID for name or name for SID",{COMPL_NONE,COMPL_NONE}},
{"lowercase",cmd_lowercase,"toggle lowercasing of filenames for get",{COMPL_NONE,COMPL_NONE}},
{"ls",cmd_dir,"<mask> list the contents of the current directory",{COMPL_REMOTE,COMPL_NONE}},
{"mask",cmd_select,"<mask> mask all filenames against this",{COMPL_REMOTE,COMPL_NONE}},
{"mput",cmd_mput,"<mask> put all matching files",{COMPL_REMOTE,COMPL_NONE}},
{"newer",cmd_newer,"<file> only mget files newer than the specified local file",{COMPL_LOCAL,COMPL_NONE}},
{"open",cmd_open,"<mask> open a file",{COMPL_REMOTE,COMPL_NONE}},
+ {"privileges",cmd_privileges,"<user> show privileges for a user",{COMPL_NONE,COMPL_NONE}},
{"print",cmd_print,"<file name> print a file",{COMPL_NONE,COMPL_NONE}},
{"printmode",cmd_printmode,"<graphics or text> set the print mode",{COMPL_NONE,COMPL_NONE}},
{"prompt",cmd_prompt,"toggle prompting for filenames for mget and mput",{COMPL_NONE,COMPL_NONE}},