Changeset 740 for vendor/current/source3/utils/smbcquotas.c
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/utils/smbcquotas.c
r414 r740 2 2 Unix SMB/CIFS implementation. 3 3 QUOTA get/set utility 4 4 5 5 Copyright (C) Andrew Tridgell 2000 6 6 Copyright (C) Tim Potter 2000 7 7 Copyright (C) Jeremy Allison 2000 8 8 Copyright (C) Stefan (metze) Metzmacher 2003 9 9 10 10 This program is free software; you can redistribute it and/or modify 11 11 it under the terms of the GNU General Public License as published by 12 12 the Free Software Foundation; either version 3 of the License, or 13 13 (at your option) any later version. 14 14 15 15 This program is distributed in the hope that it will be useful, 16 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 18 GNU General Public License for more details. 19 19 20 20 You should have received a copy of the GNU General Public License 21 21 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 23 23 24 24 #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" 25 32 26 33 static char *server; … … 73 80 got_policy_hnd = True; 74 81 } 75 82 76 83 return True; 77 84 } 78 85 79 86 /* convert a SID to a string, either numeric or username/group */ 80 static void SidToString(fstring str, DOM_SID*sid, bool _numeric)87 static void SidToString(fstring str, struct dom_sid *sid, bool _numeric) 81 88 { 82 89 char **domains = NULL; … … 103 110 domains[0], lp_winbind_separator(), 104 111 names[0]); 105 106 112 } 107 113 108 114 /* convert a string to a SID, either numeric or username/group */ 109 static bool StringToSid( DOM_SID*sid, const char *str)115 static bool StringToSid(struct dom_sid *sid, const char *str) 110 116 { 111 117 enum lsa_SidType *types = NULL; 112 DOM_SID*sids = NULL;118 struct dom_sid *sids = NULL; 113 119 bool result = True; 114 120 115 if (str ncmp(str, "S-", 2) == 0) {116 return string_to_sid(sid, str);121 if (string_to_sid(sid, str)) { 122 return true; 117 123 } 118 124 … … 224 230 } 225 231 232 233 static 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 245 static 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"AS_ENABLED) 269 ||(qt->qflags"AS_DENY_DISK))?"On":"Off"); 270 d_printf(" Deny Disk: %s\n", 271 (qt->qflags"AS_DENY_DISK)?"On":"Off"); 272 d_printf(" Log Soft Limit: %s\n", 273 (qt->qflags"AS_LOG_THRESHOLD)?"On":"Off"); 274 d_printf(" Log Hard Limit: %s\n", 275 (qt->qflags"AS_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 316 static 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 226 331 static int do_quota(struct cli_state *cli, 227 332 enum SMB_QUOTA_TYPE qtype, … … 234 339 SMB_NTQUOTA_LIST *qtl = NULL; 235 340 SMB_NTQUOTA_STRUCT qt; 341 NTSTATUS status; 342 236 343 ZERO_STRUCT(qt); 237 344 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)) { 239 347 d_printf("Failed to get the filesystem attributes %s.\n", 240 cli_errstr(cli));348 nt_errstr(status)); 241 349 return -1; 242 350 } … … 247 355 } 248 356 249 if (!NT_STATUS_IS_OK(cli_get_quota_handle(cli, "a_fnum))) { 357 status = cli_get_quota_handle(cli, "a_fnum); 358 if (!NT_STATUS_IS_OK(status)) { 250 359 d_printf("Quotas are not enabled on this share.\n"); 251 360 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)); 253 363 return -1; 254 364 } … … 263 373 switch(cmd) { 264 374 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)) { 266 378 d_printf("%s cli_get_user_quota %s\n", 267 cli_errstr(cli),username_str); 379 nt_errstr(status), 380 username_str); 268 381 return -1; 269 382 } … … 272 385 case QUOTA_SETLIM: 273 386 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)) { 275 390 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)) { 280 398 d_printf("%s cli_get_user_quota %s\n", 281 cli_errstr(cli),username_str); 399 nt_errstr(status), 400 username_str); 282 401 return -1; 283 402 } … … 285 404 break; 286 405 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)) { 288 409 d_printf("%s cli_set_user_quota %s\n", 289 cli_errstr(cli),username_str); 410 nt_errstr(status), 411 username_str); 290 412 return -1; 291 413 } … … 301 423 switch(cmd) { 302 424 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)) { 304 428 d_printf("%s cli_get_fs_quota_info\n", 305 cli_errstr(cli));429 nt_errstr(status)); 306 430 return -1; 307 431 } … … 309 433 break; 310 434 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)) { 312 438 d_printf("%s cli_get_fs_quota_info\n", 313 cli_errstr(cli));439 nt_errstr(status)); 314 440 return -1; 315 441 } 316 442 qt.softlim = pqt->softlim; 317 443 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)) { 319 447 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)) { 324 454 d_printf("%s cli_get_fs_quota_info\n", 325 cli_errstr(cli));455 nt_errstr(status)); 326 456 return -1; 327 457 } … … 329 459 break; 330 460 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)) { 332 464 d_printf("%s cli_get_fs_quota_info\n", 333 cli_errstr(cli));465 nt_errstr(status)); 334 466 return -1; 335 467 } 336 468 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)) { 338 472 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)) { 343 479 d_printf("%s cli_get_fs_quota_info\n", 344 cli_errstr(cli));480 nt_errstr(status)); 345 481 return -1; 346 482 } … … 395 531 get_cmdline_auth_info_password(smbcquotas_auth_info), 396 532 flags, 397 get_cmdline_auth_info_signing_state(smbcquotas_auth_info), 398 NULL); 533 get_cmdline_auth_info_signing_state(smbcquotas_auth_info)); 399 534 if (!NT_STATUS_IS_OK(nt_status)) { 400 535 DEBUG(0,("cli_full_connection failed! (%s)\n", nt_errstr(nt_status))); … … 460 595 461 596 /* 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"); 466 599 467 600 setlinebuf(stdout); … … 608 741 break; 609 742 default: 610 611 743 result = EXIT_FAILED; 612 744 break;
Note:
See TracChangeset
for help on using the changeset viewer.