Project

General

Profile

« Previous | Next » 

Revision acd7e560

Added by Jim Pingle almost 6 years ago

User & Group Manager: Improve Deny Config Write Handling. Fixes #9259

  • Denies all changes if a user has the Deny Config Write privilege.
    Previously it only denied the config write but some OS operations were
    performed.
  • Sets an input error so the user is notified that their attempt failed.
  • Hides the add and delete buttons so read only users don't see the
    option to perform those actions (but are still denied if they submit the
    form through other means)

View differences:

src/usr/local/www/system_usermanager.php
83 83
	$pconfig['disabled'] = isset($a_user[$id]['disabled']);
84 84
}
85 85

  
86
if ($_POST['act'] == "deluser") {
86
/*
87
 * Check user privileges to test if the user is allowed to make changes.
88
 * Otherwise users can end up in an inconsistent state where some changes are
89
 * performed and others denied. See https://redmine.pfsense.org/issues/9259
90
 */
91
phpsession_begin();
92
$guiuser = getUserEntry($_SESSION['Username']);
93
$read_only = (is_array($guiuser) && userHasPrivilege($guiuser, "user-config-readonly"));
94
phpsession_end();
95

  
96
if (!empty($_POST) && $read_only) {
97
	$input_errors = array(gettext("Insufficient privileges to make the requested change (read only)."));
98
}
99

  
100
if (($_POST['act'] == "deluser") && !$read_only) {
87 101

  
88 102
	if (!isset($_POST['username']) || !isset($a_user[$id]) || ($_POST['username'] != $a_user[$id]['name'])) {
89 103
		pfSenseHeader("system_usermanager.php");
......
125 139

  
126 140
}
127 141

  
128
if (isset($_POST['dellall'])) {
142
if (isset($_POST['dellall']) && !$read_only) {
129 143

  
130 144
	$del_users = $_POST['delete_check'];
131 145
	$deleted_users = array();
......
155 169
	}
156 170
}
157 171

  
158
if ($_POST['act'] == "delcert") {
172
if (($_POST['act'] == "delcert") && !$read_only) {
159 173

  
160 174
	if (!$a_user[$id]) {
161 175
		pfSenseHeader("system_usermanager.php");
......
171 185
	$_POST['act'] = "edit";
172 186
}
173 187

  
174
if ($_POST['act'] == "delprivid") {
188
if (($_POST['act'] == "delprivid") && !$read_only) {
175 189
	$privdeleted = $priv_list[$a_user[$id]['priv'][$_POST['privid']]]['name'];
176 190
	unset($a_user[$id]['priv'][$_POST['privid']]);
177 191
	local_user_set($a_user[$id]);
......
181 195
	$_POST['act'] = "edit";
182 196
}
183 197

  
184
if ($_POST['save']) {
198
if ($_POST['save'] && !$read_only) {
185 199
	unset($input_errors);
186 200
	$pconfig = $_POST;
187 201

  
......
475 489
}
476 490

  
477 491
function build_priv_table() {
478
	global $a_user, $id;
492
	global $a_user, $id, $read_only;
479 493

  
480 494
	$privhtml = '<div class="table-responsive">';
481 495
	$privhtml .=	'<table class="table table-striped table-hover table-condensed">';
......
508 522
		}
509 523
		$privhtml .=			'</td>';
510 524
		$privhtml .=			'<td>';
511
		if (!$group) {
525
		if (!$group && !$read_only) {
512 526
			$privhtml .=			'<a class="fa fa-trash no-confirm icon-pointer" title="' . gettext('Delete Privilege') . '" id="delprivid' . $i . '"></a>';
513 527
		}
514 528

  
......
536 550
	$privhtml .= '</div>';
537 551

  
538 552
	$privhtml .= '<nav class="action-buttons">';
539
	$privhtml .=	'<a href="system_usermanager_addprivs.php?userid=' . $id . '" class="btn btn-success"><i class="fa fa-plus icon-embed-btn"></i>' . gettext("Add") . '</a>';
553
	if (!$read_only) {
554
		$privhtml .=	'<a href="system_usermanager_addprivs.php?userid=' . $id . '" class="btn btn-success"><i class="fa fa-plus icon-embed-btn"></i>' . gettext("Add") . '</a>';
555
	}
540 556
	$privhtml .= '</nav>';
541 557

  
542 558
	return($privhtml);
543 559
}
544 560

  
545 561
function build_cert_table() {
546
	global $a_user, $id;
562
	global $a_user, $id, $read_only;
547 563

  
548 564
	$certhtml = '<div class="table-responsive">';
549 565
	$certhtml .=	'<table class="table table-striped table-hover table-condensed">';
......
568 584
			$certhtml .=		'<td>' . htmlspecialchars($cert['descr']) . $revokedstr . '</td>';
569 585
			$certhtml .=		'<td>' . htmlspecialchars($ca['descr']) . '</td>';
570 586
			$certhtml .=		'<td>';
571
			$certhtml .=			'<a id="delcert' . $i .'" class="fa fa-trash no-confirm icon-pointer" title="';
572
			$certhtml .=			gettext('Remove this certificate association? (Certificate will not be deleted)') . '"></a>';
587
			if (!$read_only) {
588
				$certhtml .=			'<a id="delcert' . $i .'" class="fa fa-trash no-confirm icon-pointer" title="';
589
				$certhtml .=			gettext('Remove this certificate association? (Certificate will not be deleted)') . '"></a>';
590
			}
573 591
			$certhtml .=		'</td>';
574 592
			$certhtml .=	'</tr>';
575 593
			$i++;
......
582 600
	$certhtml .= '</div>';
583 601

  
584 602
	$certhtml .= '<nav class="action-buttons">';
585
	$certhtml .=	'<a href="system_certmanager.php?act=new&amp;userid=' . $id . '" class="btn btn-success"><i class="fa fa-plus icon-embed-btn"></i>' . gettext("Add") . '</a>';
603
	if (!$read_only) {
604
		$certhtml .=	'<a href="system_certmanager.php?act=new&amp;userid=' . $id . '" class="btn btn-success"><i class="fa fa-plus icon-embed-btn"></i>' . gettext("Add") . '</a>';
605
	}
586 606
	$certhtml .= '</nav>';
587 607

  
588 608
	return($certhtml);
......
659 679
						<td><?=implode(",", local_user_get_groups($userent))?></td>
660 680
						<td>
661 681
							<a class="fa fa-pencil" title="<?=gettext("Edit user"); ?>" href="?act=edit&amp;userid=<?=$i?>"></a>
662
<?php if (($userent['scope'] != "system") && ($userent['name'] != $_SESSION['Username'])): ?>
682
<?php if (($userent['scope'] != "system") && ($userent['name'] != $_SESSION['Username']) && !$read_only): ?>
663 683
							<a class="fa fa-trash"	title="<?=gettext("Delete user")?>" href="?act=deluser&amp;userid=<?=$i?>&amp;username=<?=$userent['name']?>" usepost></a>
664 684
<?php endif; ?>
665 685
						</td>
......
671 691
	</div>
672 692
</div>
673 693
<nav class="action-buttons">
694
	<?php if (!$read_only): ?>
695

  
674 696
	<a href="?act=new" class="btn btn-sm btn-success">
675 697
		<i class="fa fa-plus icon-embed-btn"></i>
676 698
		<?=gettext("Add")?>
......
680 702
		<i class="fa fa-trash icon-embed-btn"></i>
681 703
		<?=gettext("Delete")?>
682 704
	</button>
705
	<?php endif; ?>
683 706

  
684 707
</nav>
685 708
</form>

Also available in: Unified diff