smbcquotas.c: fix a bug of -t
[obnox/samba/samba-obnox.git] / source3 / utils / smbcquotas.c
index 8cf1751578fe795082a85a7cd7c409fe3c88471c..bf1f95c25f87fd27cc10f2c264b371c1319f5dea 100644 (file)
 
 #include "includes.h"
 #include "popt_common.h"
+#include "rpc_client/cli_pipe.h"
 #include "../librpc/gen_ndr/ndr_lsa.h"
 #include "rpc_client/cli_lsarpc.h"
 #include "fake_file.h"
 #include "../libcli/security/security.h"
+#include "libsmb/libsmb.h"
 
 static char *server;
 
@@ -185,7 +187,9 @@ static int parse_quota_set(TALLOC_CTX *ctx,
 
        switch (todo) {
                case PARSE_LIM:
-                       if (sscanf(p,"%"PRIu64"/%"PRIu64,&pqt->softlim,&pqt->hardlim)!=2) {
+                       if (sscanf(p,"%"SCNu64"/%"SCNu64,&pqt->softlim,
+                           &pqt->hardlim) != 2)
+                       {
                                return -1;
                        }
 
@@ -227,6 +231,105 @@ static int parse_quota_set(TALLOC_CTX *ctx,
        return 0;
 }
 
+
+static const char *quota_str_static(uint64_t val, bool special, bool _numeric)
+{
+       const char *result;
+
+       if (!_numeric&&special&&(val == SMB_NTQUOTAS_NO_LIMIT)) {
+               return "NO LIMIT";
+       }
+       result = talloc_asprintf(talloc_tos(), "%"PRIu64, val);
+       SMB_ASSERT(result != NULL);
+       return result;
+}
+
+static void dump_ntquota(SMB_NTQUOTA_STRUCT *qt, bool _verbose,
+                        bool _numeric,
+                        void (*_sidtostring)(fstring str,
+                                             struct dom_sid *sid,
+                                             bool _numeric))
+{
+       TALLOC_CTX *frame = talloc_stackframe();
+
+       if (!qt) {
+               smb_panic("dump_ntquota() called with NULL pointer");
+       }
+
+       switch (qt->qtype) {
+       case SMB_USER_FS_QUOTA_TYPE:
+       {
+               d_printf("File System QUOTAS:\n");
+               d_printf("Limits:\n");
+               d_printf(" Default Soft Limit: %15s\n",
+                        quota_str_static(qt->softlim,True,_numeric));
+               d_printf(" Default Hard Limit: %15s\n",
+                        quota_str_static(qt->hardlim,True,_numeric));
+               d_printf("Quota Flags:\n");
+               d_printf(" Quotas Enabled: %s\n",
+                        ((qt->qflags&QUOTAS_ENABLED)
+                         ||(qt->qflags&QUOTAS_DENY_DISK))?"On":"Off");
+               d_printf(" Deny Disk:      %s\n",
+                        (qt->qflags&QUOTAS_DENY_DISK)?"On":"Off");
+               d_printf(" Log Soft Limit: %s\n",
+                        (qt->qflags&QUOTAS_LOG_THRESHOLD)?"On":"Off");
+               d_printf(" Log Hard Limit: %s\n",
+                        (qt->qflags&QUOTAS_LOG_LIMIT)?"On":"Off");
+       }
+       break;
+       case SMB_USER_QUOTA_TYPE:
+       {
+               fstring username_str = {0};
+
+               if (_sidtostring) {
+                       _sidtostring(username_str,&qt->sid,_numeric);
+               } else {
+                       sid_to_fstring(username_str, &qt->sid);
+               }
+
+               if (_verbose) {
+                       d_printf("Quotas for User: %s\n",username_str);
+                       d_printf("Used Space: %15s\n",
+                                quota_str_static(qt->usedspace,False,
+                                                 _numeric));
+                       d_printf("Soft Limit: %15s\n",
+                                quota_str_static(qt->softlim,True,
+                                                 _numeric));
+                       d_printf("Hard Limit: %15s\n",
+                                quota_str_static(qt->hardlim,True,_numeric));
+               } else {
+                       d_printf("%-30s: ",username_str);
+                       d_printf("%15s/",quota_str_static(
+                                        qt->usedspace,False,_numeric));
+                       d_printf("%15s/",quota_str_static(
+                                        qt->softlim,True,_numeric));
+                       d_printf("%15s\n",quota_str_static(
+                                        qt->hardlim,True,_numeric));
+               }
+       }
+       break;
+       default:
+               d_printf("dump_ntquota() invalid qtype(%d)\n",qt->qtype);
+       }
+       TALLOC_FREE(frame);
+       return;
+}
+
+static void dump_ntquota_list(SMB_NTQUOTA_LIST **qtl, bool _verbose,
+                             bool _numeric,
+                             void (*_sidtostring)(fstring str,
+                                                  struct dom_sid *sid,
+                                                  bool _numeric))
+{
+       SMB_NTQUOTA_LIST *cur;
+
+       for (cur = *qtl;cur;cur = cur->next) {
+               if (cur->quotas)
+                       dump_ntquota(cur->quotas,_verbose,_numeric,
+                                    _sidtostring);
+       }
+}
+
 static int do_quota(struct cli_state *cli,
                enum SMB_QUOTA_TYPE qtype,
                uint16 cmd,
@@ -403,12 +506,9 @@ static int do_quota(struct cli_state *cli,
 static struct cli_state *connect_one(const char *share)
 {
        struct cli_state *c;
-       struct sockaddr_storage ss;
        NTSTATUS nt_status;
        uint32_t flags = 0;
 
-       zero_sockaddr(&ss);
-
        if (get_cmdline_auth_info_use_machine_account(smbcquotas_auth_info) &&
            !set_cmdline_auth_info_machine_account_creds(smbcquotas_auth_info)) {
                return NULL;
@@ -422,8 +522,8 @@ static struct cli_state *connect_one(const char *share)
 
        set_cmdline_auth_info_getpass(smbcquotas_auth_info);
 
-       nt_status = cli_full_connection(&c, global_myname(), server, 
-                                           &ss, 0,
+       nt_status = cli_full_connection(&c, lp_netbios_name(), server,
+                                           NULL, 0,
                                            share, "?????",
                                            get_cmdline_auth_info_username(smbcquotas_auth_info),
                                            lp_workgroup(),
@@ -482,7 +582,7 @@ FSQLIM:<softlimit>/<hardlimit> for filesystem defaults\n\
 FSQFLAGS:QUOTA_ENABLED/DENY_DISK/LOG_SOFTLIMIT/LOG_HARD_LIMIT", "SETSTRING" },
                { "numeric", 'n', POPT_ARG_NONE, NULL, 'n', "Don't resolve sids or limits to names" },
                { "verbose", 'v', POPT_ARG_NONE, NULL, 'v', "be verbose" },
-               { "test-args", 't', POPT_ARG_NONE, NULL, 'r', "Test arguments"},
+               { "test-args", 't', POPT_ARG_NONE, NULL, 't', "Test arguments"},
                POPT_COMMON_SAMBA
                POPT_COMMON_CREDENTIALS
                { NULL }
@@ -498,9 +598,9 @@ FSQFLAGS:QUOTA_ENABLED/DENY_DISK/LOG_SOFTLIMIT/LOG_HARD_LIMIT", "SETSTRING" },
 
        setlinebuf(stdout);
 
-       fault_setup(NULL);
+       fault_setup();
 
-       lp_load(get_dyn_CONFIGFILE(),True,False,False,True);
+       lp_load_global(get_dyn_CONFIGFILE());
        load_interfaces();
 
        smbcquotas_auth_info = user_auth_info_init(frame);
@@ -590,6 +690,9 @@ FSQFLAGS:QUOTA_ENABLED/DENY_DISK/LOG_SOFTLIMIT/LOG_HARD_LIMIT", "SETSTRING" },
                exit(EXIT_PARSE_ERROR);
        }
 
+       poptFreeContext(pc);
+       popt_burn_cmdline_password(argc, argv);
+
        string_replace(path, '/', '\\');
 
        server = SMB_STRDUP(path+2);