Ignore:
Timestamp:
Nov 14, 2012, 12:59:34 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to 3.6.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/utils/smbcquotas.c

    r414 r740  
    22   Unix SMB/CIFS implementation.
    33   QUOTA get/set utility
    4    
     4
    55   Copyright (C) Andrew Tridgell                2000
    66   Copyright (C) Tim Potter                     2000
    77   Copyright (C) Jeremy Allison                 2000
    88   Copyright (C) Stefan (metze) Metzmacher      2003
    9    
     9
    1010   This program is free software; you can redistribute it and/or modify
    1111   it under the terms of the GNU General Public License as published by
    1212   the Free Software Foundation; either version 3 of the License, or
    1313   (at your option) any later version.
    14    
     14
    1515   This program is distributed in the hope that it will be useful,
    1616   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1717   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1818   GNU General Public License for more details.
    19    
     19
    2020   You should have received a copy of the GNU General Public License
    2121   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2323
    2424#include "includes.h"
     25#include "popt_common.h"
     26#include "rpc_client/cli_pipe.h"
     27#include "../librpc/gen_ndr/ndr_lsa.h"
     28#include "rpc_client/cli_lsarpc.h"
     29#include "fake_file.h"
     30#include "../libcli/security/security.h"
     31#include "libsmb/libsmb.h"
    2532
    2633static char *server;
     
    7380                got_policy_hnd = True;
    7481        }
    75        
     82
    7683        return True;
    7784}
    7885
    7986/* convert a SID to a string, either numeric or username/group */
    80 static void SidToString(fstring str, DOM_SID *sid, bool _numeric)
     87static void SidToString(fstring str, struct dom_sid *sid, bool _numeric)
    8188{
    8289        char **domains = NULL;
     
    103110                 domains[0], lp_winbind_separator(),
    104111                 names[0]);
    105        
    106112}
    107113
    108114/* convert a string to a SID, either numeric or username/group */
    109 static bool StringToSid(DOM_SID *sid, const char *str)
     115static bool StringToSid(struct dom_sid *sid, const char *str)
    110116{
    111117        enum lsa_SidType *types = NULL;
    112         DOM_SID *sids = NULL;
     118        struct dom_sid *sids = NULL;
    113119        bool result = True;
    114120
    115         if (strncmp(str, "S-", 2) == 0) {
    116                 return string_to_sid(sid, str);
     121        if (string_to_sid(sid, str)) {
     122                return true;
    117123        }
    118124
     
    224230}
    225231
     232
     233static const char *quota_str_static(uint64_t val, bool special, bool _numeric)
     234{
     235        const char *result;
     236
     237        if (!_numeric&&special&&(val == SMB_NTQUOTAS_NO_LIMIT)) {
     238                return "NO LIMIT";
     239        }
     240        result = talloc_asprintf(talloc_tos(), "%"PRIu64, val);
     241        SMB_ASSERT(result != NULL);
     242        return result;
     243}
     244
     245static void dump_ntquota(SMB_NTQUOTA_STRUCT *qt, bool _verbose,
     246                         bool _numeric,
     247                         void (*_sidtostring)(fstring str,
     248                                              struct dom_sid *sid,
     249                                              bool _numeric))
     250{
     251        TALLOC_CTX *frame = talloc_stackframe();
     252
     253        if (!qt) {
     254                smb_panic("dump_ntquota() called with NULL pointer");
     255        }
     256
     257        switch (qt->qtype) {
     258        case SMB_USER_FS_QUOTA_TYPE:
     259        {
     260                d_printf("File System QUOTAS:\n");
     261                d_printf("Limits:\n");
     262                d_printf(" Default Soft Limit: %15s\n",
     263                         quota_str_static(qt->softlim,True,_numeric));
     264                d_printf(" Default Hard Limit: %15s\n",
     265                         quota_str_static(qt->hardlim,True,_numeric));
     266                d_printf("Quota Flags:\n");
     267                d_printf(" Quotas Enabled: %s\n",
     268                         ((qt->qflags&QUOTAS_ENABLED)
     269                          ||(qt->qflags&QUOTAS_DENY_DISK))?"On":"Off");
     270                d_printf(" Deny Disk:      %s\n",
     271                         (qt->qflags&QUOTAS_DENY_DISK)?"On":"Off");
     272                d_printf(" Log Soft Limit: %s\n",
     273                         (qt->qflags&QUOTAS_LOG_THRESHOLD)?"On":"Off");
     274                d_printf(" Log Hard Limit: %s\n",
     275                         (qt->qflags&QUOTAS_LOG_LIMIT)?"On":"Off");
     276        }
     277        break;
     278        case SMB_USER_QUOTA_TYPE:
     279        {
     280                fstring username_str = {0};
     281
     282                if (_sidtostring) {
     283                        _sidtostring(username_str,&qt->sid,_numeric);
     284                } else {
     285                        sid_to_fstring(username_str, &qt->sid);
     286                }
     287
     288                if (_verbose) {
     289                        d_printf("Quotas for User: %s\n",username_str);
     290                        d_printf("Used Space: %15s\n",
     291                                 quota_str_static(qt->usedspace,False,
     292                                                  _numeric));
     293                        d_printf("Soft Limit: %15s\n",
     294                                 quota_str_static(qt->softlim,True,
     295                                                  _numeric));
     296                        d_printf("Hard Limit: %15s\n",
     297                                 quota_str_static(qt->hardlim,True,_numeric));
     298                } else {
     299                        d_printf("%-30s: ",username_str);
     300                        d_printf("%15s/",quota_str_static(
     301                                         qt->usedspace,False,_numeric));
     302                        d_printf("%15s/",quota_str_static(
     303                                         qt->softlim,True,_numeric));
     304                        d_printf("%15s\n",quota_str_static(
     305                                         qt->hardlim,True,_numeric));
     306                }
     307        }
     308        break;
     309        default:
     310                d_printf("dump_ntquota() invalid qtype(%d)\n",qt->qtype);
     311        }
     312        TALLOC_FREE(frame);
     313        return;
     314}
     315
     316static void dump_ntquota_list(SMB_NTQUOTA_LIST **qtl, bool _verbose,
     317                              bool _numeric,
     318                              void (*_sidtostring)(fstring str,
     319                                                   struct dom_sid *sid,
     320                                                   bool _numeric))
     321{
     322        SMB_NTQUOTA_LIST *cur;
     323
     324        for (cur = *qtl;cur;cur = cur->next) {
     325                if (cur->quotas)
     326                        dump_ntquota(cur->quotas,_verbose,_numeric,
     327                                     _sidtostring);
     328        }
     329}
     330
    226331static int do_quota(struct cli_state *cli,
    227332                enum SMB_QUOTA_TYPE qtype,
     
    234339        SMB_NTQUOTA_LIST *qtl = NULL;
    235340        SMB_NTQUOTA_STRUCT qt;
     341        NTSTATUS status;
     342
    236343        ZERO_STRUCT(qt);
    237344
    238         if (!cli_get_fs_attr_info(cli, &fs_attrs)) {
     345        status = cli_get_fs_attr_info(cli, &fs_attrs);
     346        if (!NT_STATUS_IS_OK(status)) {
    239347                d_printf("Failed to get the filesystem attributes %s.\n",
    240                         cli_errstr(cli));
     348                         nt_errstr(status));
    241349                return -1;
    242350        }
     
    247355        }
    248356
    249         if (!NT_STATUS_IS_OK(cli_get_quota_handle(cli, &quota_fnum))) {
     357        status = cli_get_quota_handle(cli, &quota_fnum);
     358        if (!NT_STATUS_IS_OK(status)) {
    250359                d_printf("Quotas are not enabled on this share.\n");
    251360                d_printf("Failed to open %s  %s.\n",
    252                         FAKE_FILE_NAME_QUOTA_WIN32,cli_errstr(cli));
     361                         FAKE_FILE_NAME_QUOTA_WIN32,
     362                         nt_errstr(status));
    253363                return -1;
    254364        }
     
    263373                        switch(cmd) {
    264374                                case QUOTA_GET:
    265                                         if (!cli_get_user_quota(cli, quota_fnum, &qt)) {
     375                                        status = cli_get_user_quota(
     376                                                cli, quota_fnum, &qt);
     377                                        if (!NT_STATUS_IS_OK(status)) {
    266378                                                d_printf("%s cli_get_user_quota %s\n",
    267                                                          cli_errstr(cli),username_str);
     379                                                         nt_errstr(status),
     380                                                         username_str);
    268381                                                return -1;
    269382                                        }
     
    272385                                case QUOTA_SETLIM:
    273386                                        pqt->sid = qt.sid;
    274                                         if (!cli_set_user_quota(cli, quota_fnum, pqt)) {
     387                                        status = cli_set_user_quota(
     388                                                cli, quota_fnum, pqt);
     389                                        if (!NT_STATUS_IS_OK(status)) {
    275390                                                d_printf("%s cli_set_user_quota %s\n",
    276                                                          cli_errstr(cli),username_str);
    277                                                 return -1;
    278                                         }
    279                                         if (!cli_get_user_quota(cli, quota_fnum, &qt)) {
     391                                                         nt_errstr(status),
     392                                                         username_str);
     393                                                return -1;
     394                                        }
     395                                        status = cli_get_user_quota(
     396                                                cli, quota_fnum, &qt);
     397                                        if (!NT_STATUS_IS_OK(status)) {
    280398                                                d_printf("%s cli_get_user_quota %s\n",
    281                                                          cli_errstr(cli),username_str);
     399                                                         nt_errstr(status),
     400                                                         username_str);
    282401                                                return -1;
    283402                                        }
     
    285404                                        break;
    286405                                case QUOTA_LIST:
    287                                         if (!cli_list_user_quota(cli, quota_fnum, &qtl)) {
     406                                        status = cli_list_user_quota(
     407                                                cli, quota_fnum, &qtl);
     408                                        if (!NT_STATUS_IS_OK(status)) {
    288409                                                d_printf("%s cli_set_user_quota %s\n",
    289                                                          cli_errstr(cli),username_str);
     410                                                         nt_errstr(status),
     411                                                         username_str);
    290412                                                return -1;
    291413                                        }
     
    301423                        switch(cmd) {
    302424                                case QUOTA_GET:
    303                                         if (!cli_get_fs_quota_info(cli, quota_fnum, &qt)) {
     425                                        status = cli_get_fs_quota_info(
     426                                                cli, quota_fnum, &qt);
     427                                        if (!NT_STATUS_IS_OK(status)) {
    304428                                                d_printf("%s cli_get_fs_quota_info\n",
    305                                                          cli_errstr(cli));
     429                                                         nt_errstr(status));
    306430                                                return -1;
    307431                                        }
     
    309433                                        break;
    310434                                case QUOTA_SETLIM:
    311                                         if (!cli_get_fs_quota_info(cli, quota_fnum, &qt)) {
     435                                        status = cli_get_fs_quota_info(
     436                                                cli, quota_fnum, &qt);
     437                                        if (!NT_STATUS_IS_OK(status)) {
    312438                                                d_printf("%s cli_get_fs_quota_info\n",
    313                                                          cli_errstr(cli));
     439                                                         nt_errstr(status));
    314440                                                return -1;
    315441                                        }
    316442                                        qt.softlim = pqt->softlim;
    317443                                        qt.hardlim = pqt->hardlim;
    318                                         if (!cli_set_fs_quota_info(cli, quota_fnum, &qt)) {
     444                                        status = cli_set_fs_quota_info(
     445                                                cli, quota_fnum, &qt);
     446                                        if (!NT_STATUS_IS_OK(status)) {
    319447                                                d_printf("%s cli_set_fs_quota_info\n",
    320                                                          cli_errstr(cli));
    321                                                 return -1;
    322                                         }
    323                                         if (!cli_get_fs_quota_info(cli, quota_fnum, &qt)) {
     448                                                         nt_errstr(status));
     449                                                return -1;
     450                                        }
     451                                        status = cli_get_fs_quota_info(
     452                                                cli, quota_fnum, &qt);
     453                                        if (!NT_STATUS_IS_OK(status)) {
    324454                                                d_printf("%s cli_get_fs_quota_info\n",
    325                                                          cli_errstr(cli));
     455                                                         nt_errstr(status));
    326456                                                return -1;
    327457                                        }
     
    329459                                        break;
    330460                                case QUOTA_SETFLAGS:
    331                                         if (!cli_get_fs_quota_info(cli, quota_fnum, &qt)) {
     461                                        status = cli_get_fs_quota_info(
     462                                                cli, quota_fnum, &qt);
     463                                        if (!NT_STATUS_IS_OK(status)) {
    332464                                                d_printf("%s cli_get_fs_quota_info\n",
    333                                                          cli_errstr(cli));
     465                                                         nt_errstr(status));
    334466                                                return -1;
    335467                                        }
    336468                                        qt.qflags = pqt->qflags;
    337                                         if (!cli_set_fs_quota_info(cli, quota_fnum, &qt)) {
     469                                        status = cli_set_fs_quota_info(
     470                                                cli, quota_fnum, &qt);
     471                                        if (!NT_STATUS_IS_OK(status)) {
    338472                                                d_printf("%s cli_set_fs_quota_info\n",
    339                                                          cli_errstr(cli));
    340                                                 return -1;
    341                                         }
    342                                         if (!cli_get_fs_quota_info(cli, quota_fnum, &qt)) {
     473                                                         nt_errstr(status));
     474                                                return -1;
     475                                        }
     476                                        status = cli_get_fs_quota_info(
     477                                                cli, quota_fnum, &qt);
     478                                        if (!NT_STATUS_IS_OK(status)) {
    343479                                                d_printf("%s cli_get_fs_quota_info\n",
    344                                                          cli_errstr(cli));
     480                                                         nt_errstr(status));
    345481                                                return -1;
    346482                                        }
     
    395531                                            get_cmdline_auth_info_password(smbcquotas_auth_info),
    396532                                            flags,
    397                                             get_cmdline_auth_info_signing_state(smbcquotas_auth_info),
    398                                             NULL);
     533                                            get_cmdline_auth_info_signing_state(smbcquotas_auth_info));
    399534        if (!NT_STATUS_IS_OK(nt_status)) {
    400535                DEBUG(0,("cli_full_connection failed! (%s)\n", nt_errstr(nt_status)));
     
    460595
    461596        /* set default debug level to 1 regardless of what smb.conf sets */
    462         setup_logging( "smbcquotas", True );
    463         DEBUGLEVEL_CLASS[DBGC_ALL] = 1;
    464         dbf = x_stderr;
    465         x_setbuf( x_stderr, NULL );
     597        setup_logging( "smbcquotas", DEBUG_STDERR);
     598        lp_set_cmdline("log level", "1");
    466599
    467600        setlinebuf(stdout);
     
    608741                        break;
    609742                default:
    610                        
    611743                        result = EXIT_FAILED;
    612744                        break;
Note: See TracChangeset for help on using the changeset viewer.