r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text
[tprouty/samba.git] / source / utils / smbcquotas.c
index 9c7379ca2a9c94837213afe270d02cda8fb6d1d8..70d28a7e4a3991cb5d4363b41fc46a9c50eb9cb4 100644 (file)
@@ -9,7 +9,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -18,8 +18,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
@@ -34,7 +33,8 @@ static BOOL verbose;
 enum todo_values {NOOP_QUOTA=0,FS_QUOTA,USER_QUOTA,LIST_QUOTA,SET_QUOTA};
 enum exit_values {EXIT_OK, EXIT_FAILED, EXIT_PARSE_ERROR};
 
-static struct cli_state *cli_ipc = NULL;
+static struct cli_state *cli_ipc;
+static struct rpc_pipe_client *global_pipe_hnd;
 static POLICY_HND pol;
 static BOOL got_policy_hnd;
 
@@ -47,8 +47,10 @@ static BOOL cli_open_policy_hnd(void)
        /* Initialise cli LSA connection */
 
        if (!cli_ipc) {
+               NTSTATUS ret;
                cli_ipc = connect_one("IPC$");
-               if (!cli_nt_session_open (cli_ipc, PI_LSARPC)) {
+               global_pipe_hnd = cli_rpc_pipe_open_noauth(cli_ipc, PI_LSARPC, &ret);
+               if (!global_pipe_hnd) {
                                return False;
                }
        }
@@ -60,7 +62,7 @@ static BOOL cli_open_policy_hnd(void)
                /* Some systems don't support SEC_RIGHTS_MAXIMUM_ALLOWED,
                   but NT sends 0x2000000 so we might as well do it too. */
 
-               if (!NT_STATUS_IS_OK(cli_lsa_open_policy(cli_ipc, cli_ipc->mem_ctx, True, 
+               if (!NT_STATUS_IS_OK(rpccli_lsa_open_policy(global_pipe_hnd, cli_ipc->mem_ctx, True, 
                                                         GENERIC_EXECUTE_ACCESS, &pol))) {
                        return False;
                }
@@ -76,7 +78,7 @@ static void SidToString(fstring str, DOM_SID *sid, BOOL _numeric)
 {
        char **domains = NULL;
        char **names = NULL;
-       uint32 *types = NULL;
+       enum lsa_SidType *types = NULL;
 
        sid_to_string(str, sid);
 
@@ -85,7 +87,7 @@ static void SidToString(fstring str, DOM_SID *sid, BOOL _numeric)
        /* Ask LSA to convert the sid to a name */
 
        if (!cli_open_policy_hnd() ||
-           !NT_STATUS_IS_OK(cli_lsa_lookup_sids(cli_ipc, cli_ipc->mem_ctx,  
+           !NT_STATUS_IS_OK(rpccli_lsa_lookup_sids(global_pipe_hnd, cli_ipc->mem_ctx,  
                                                 &pol, 1, sid, &domains, 
                                                 &names, &types)) ||
            !domains || !domains[0] || !names || !names[0]) {
@@ -103,7 +105,7 @@ static void SidToString(fstring str, DOM_SID *sid, BOOL _numeric)
 /* convert a string to a SID, either numeric or username/group */
 static BOOL StringToSid(DOM_SID *sid, const char *str)
 {
-       uint32 *types = NULL;
+       enum lsa_SidType *types = NULL;
        DOM_SID *sids = NULL;
        BOOL result = True;
 
@@ -112,8 +114,8 @@ static BOOL StringToSid(DOM_SID *sid, const char *str)
        }
 
        if (!cli_open_policy_hnd() ||
-           !NT_STATUS_IS_OK(cli_lsa_lookup_names(cli_ipc, cli_ipc->mem_ctx, 
-                                                 &pol, 1, &str, &sids, 
+           !NT_STATUS_IS_OK(rpccli_lsa_lookup_names(global_pipe_hnd, cli_ipc->mem_ctx, 
+                                                 &pol, 1, &str, NULL, 1, &sids, 
                                                  &types))) {
                result = False;
                goto done;
@@ -140,7 +142,7 @@ static int parse_quota_set(pstring set_str, pstring username_str, enum SMB_QUOTA
        BOOL enable = False;
        BOOL deny = False;
        
-       if (strncasecmp(set_str,"UQLIM:",6)==0) {
+       if (strnequal(set_str,"UQLIM:",6)) {
                p += 6;
                *qtype = SMB_USER_QUOTA_TYPE;
                *cmd = QUOTA_SETLIM;
@@ -154,12 +156,12 @@ static int parse_quota_set(pstring set_str, pstring username_str, enum SMB_QUOTA
                
                fstrcpy(username_str,p);
                p = p2;
-       } else if (strncasecmp(set_str,"FSQLIM:",7)==0) {
+       } else if (strnequal(set_str,"FSQLIM:",7)) {
                p +=7;
                *qtype = SMB_USER_FS_QUOTA_TYPE;
                *cmd = QUOTA_SETLIM;
                todo = PARSE_LIM;
-       } else if (strncasecmp(set_str,"FSQFLAGS:",9)==0) {
+       } else if (strnequal(set_str,"FSQFLAGS:",9)) {
                p +=9;
                todo = PARSE_FLAGS;
                *qtype = SMB_USER_FS_QUOTA_TYPE;
@@ -189,13 +191,13 @@ static int parse_quota_set(pstring set_str, pstring username_str, enum SMB_QUOTA
                                        p2++;
                                }
 
-                               if (strncasecmp(p,"QUOTA_ENABLED",13)==0) {
+                               if (strnequal(p,"QUOTA_ENABLED",13)) {
                                        enable = True;
-                               } else if (strncasecmp(p,"DENY_DISK",9)==0) {
+                               } else if (strnequal(p,"DENY_DISK",9)) {
                                        deny = True;
-                               } else if (strncasecmp(p,"LOG_SOFTLIMIT",13)==0) {
+                               } else if (strnequal(p,"LOG_SOFTLIMIT",13)) {
                                        pqt->qflags |= QUOTAS_LOG_THRESHOLD;
-                               } else if (strncasecmp(p,"LOG_HARDLIMIT",13)==0) {
+                               } else if (strnequal(p,"LOG_HARDLIMIT",13)) {
                                        pqt->qflags |= QUOTAS_LOG_LIMIT;
                                } else {
                                        return -1;
@@ -236,8 +238,9 @@ static int do_quota(struct cli_state *cli, enum SMB_QUOTA_TYPE qtype, uint16 cmd
        }
 
        if (!cli_get_quota_handle(cli, &quota_fnum)) {
-               d_printf("Failed to open \\%s  %s.\n",
-                       FAKE_FILE_NAME_QUOTA,cli_errstr(cli));
+               d_printf("Quotas are not enabled on this share.\n");
+               d_printf("Failed to open %s  %s.\n",
+                       FAKE_FILE_NAME_QUOTA_WIN32,cli_errstr(cli));
                return -1;
        }
 
@@ -371,7 +374,8 @@ static struct cli_state *connect_one(const char *share)
                                                            &ip, 0,
                                                            share, "?????",  
                                                            cmdline_auth_info.username, lp_workgroup(),
-                                                           cmdline_auth_info.password, 0, NULL))) {
+                                                           cmdline_auth_info.password, 0,
+                                                           cmdline_auth_info.signing_state, NULL))) {
                return c;
        } else {
                DEBUG(0,("cli_full_connection failed! (%s)\n", nt_errstr(nt_status)));
@@ -391,7 +395,7 @@ static struct cli_state *connect_one(const char *share)
        pstring username_str = {0};
        pstring path = {0};
        pstring set_str = {0};
-       enum SMB_QUOTA_TYPE qtype;
+       enum SMB_QUOTA_TYPE qtype = SMB_INVALID_QUOTA_TYPE;
        int cmd = 0;
        static BOOL test_args = False;
        struct cli_state *cli;
@@ -416,18 +420,21 @@ FSQFLAGS:QUOTA_ENABLED/DENY_DISK/LOG_SOFTLIMIT/LOG_HARD_LIMIT", "SETSTRING" },
                { NULL }
        };
 
-       ZERO_STRUCT(qt);
+       load_case_tables();
 
-       setlinebuf(stdout);
+       ZERO_STRUCT(qt);
 
+       /* set default debug level to 1 regardless of what smb.conf sets */
+       setup_logging( "smbcquotas", True );
+       DEBUGLEVEL_CLASS[DBGC_ALL] = 1;
        dbf = x_stderr;
+       x_setbuf( x_stderr, NULL );
 
-       fault_setup(NULL);
-
-       setup_logging(argv[0],True);
+       setlinebuf(stdout);
 
+       fault_setup(NULL);
 
-       lp_load(dyn_CONFIGFILE,True,False,False);
+       lp_load(dyn_CONFIGFILE,True,False,False,True);
        load_interfaces();
 
        pc = poptGetContext("smbcquotas", argc, argv, long_options, 0);
@@ -492,11 +499,8 @@ FSQFLAGS:QUOTA_ENABLED/DENY_DISK/LOG_SOFTLIMIT/LOG_HARD_LIMIT", "SETSTRING" },
        pstrcpy(server,path+2);
        share = strchr_m(server,'\\');
        if (!share) {
-               share = strchr_m(server,'/');
-               if (!share) {
-                       printf("Invalid argument: %s\n", share);
-                       exit(EXIT_PARSE_ERROR);
-               }
+               printf("Invalid argument: %s\n", share);
+               exit(EXIT_PARSE_ERROR);
        }
 
        *share = 0;