Fossil SCM

Initial steps toward more prominently recording when a user's permissions are elevated. This currently only changes the admin log output but the eventual intent is to enable optional email notifications when a user account is elevated.

stephan 2025-03-08 11:31 trunk
Commit 22b648e9e5893ee22ab292de537996ac2ac7d2738502258aa0663e79cb37700e
1 file changed +35 -6
+35 -6
--- src/setupuser.c
+++ src/setupuser.c
@@ -302,10 +302,34 @@
302302
if( zPw==0 ) return 0;
303303
if( zPw[0]==0 ) return 1;
304304
while( zPw[0]=='*' ){ zPw++; }
305305
return zPw[0]!=0;
306306
}
307
+
308
+/*
309
+** Return 1 if user capability string zCaps contains the given
310
+** capability letter, else 0.
311
+*/
312
+static int userCapsContain(const char *zCaps, const char letter){
313
+ for( ; zCaps && *zCaps; ++zCaps ){
314
+ if( letter==*zCaps ) return 1;
315
+ }
316
+ return 0;
317
+}
318
+
319
+/*
320
+** Return 1 if user capability string zNew contains any capability
321
+** letter which is not in user capability string zOrig, else 0.
322
+*/
323
+static int userCapsAreElevated(const char *zOrig, const char *zNew){
324
+ for( ; zNew && *zNew; ++zNew ){
325
+ if( !userCapsContain(zOrig, *zNew) ){
326
+ return 1;
327
+ }
328
+ }
329
+ return 0;
330
+}
307331
308332
/*
309333
** WEBPAGE: setup_uedit
310334
**
311335
** Edit information about a user or create a new user.
@@ -314,10 +338,11 @@
314338
void user_edit(void){
315339
const char *zId, *zLogin, *zInfo, *zCap, *zPw;
316340
const char *zGroup;
317341
const char *zOldLogin;
318342
int uid, i;
343
+ char *zOldCaps = 0; /* Capabilities before edit */
319344
char *zDeleteVerify = 0; /* Delete user verification text */
320345
int higherUser = 0; /* True if user being edited is SETUP and the */
321346
/* user doing the editing is ADMIN. Disallow editing */
322347
const char *inherit[128];
323348
int a[128];
@@ -331,14 +356,15 @@
331356
/* Check to see if an ADMIN user is trying to edit a SETUP account.
332357
** Don't allow that.
333358
*/
334359
zId = PD("id", "0");
335360
uid = atoi(zId);
336
- if( zId && !g.perm.Setup && uid>0 ){
337
- char *zOldCaps;
361
+ if( uid>0 ){
338362
zOldCaps = db_text(0, "SELECT cap FROM user WHERE uid=%d",uid);
339
- higherUser = zOldCaps && strchr(zOldCaps,'s');
363
+ if( zId && !g.perm.Setup ){
364
+ higherUser = zOldCaps && strchr(zOldCaps,'s');
365
+ }
340366
}
341367
342368
if( P("can") ){
343369
/* User pressed the cancel button */
344370
cgi_redirect(cgi_referer("setup_ulist"));
@@ -460,12 +486,15 @@
460486
}
461487
admin_log( "Renamed user [%q] to [%q].", zOldLogin, zLogin );
462488
}
463489
db_protect_pop();
464490
setup_incr_cfgcnt();
465
- admin_log( "Updated user [%q] with capabilities [%q].",
466
- zLogin, &aCap[0] );
491
+ admin_log( "Updated user [%q] with%s capabilities [%q].",
492
+ zLogin,
493
+ userCapsAreElevated(zOldCaps, &aCap[0])
494
+ ? " elevated" : "",
495
+ &aCap[0] );
467496
if( atoi(PD("all","0"))>0 ){
468497
Blob sql;
469498
char *zErr = 0;
470499
blob_zero(&sql);
471500
if( zOldLogin==0 ){
@@ -526,11 +555,11 @@
526555
527556
/* Load the existing information about the user, if any
528557
*/
529558
zLogin = "";
530559
zInfo = "";
531
- zCap = "";
560
+ zCap = zOldCaps;
532561
zPw = "";
533562
for(i='a'; i<='z'; i++) oa[i] = "";
534563
for(i='0'; i<='9'; i++) oa[i] = "";
535564
for(i='A'; i<='Z'; i++) oa[i] = "";
536565
if( uid ){
537566
--- src/setupuser.c
+++ src/setupuser.c
@@ -302,10 +302,34 @@
302 if( zPw==0 ) return 0;
303 if( zPw[0]==0 ) return 1;
304 while( zPw[0]=='*' ){ zPw++; }
305 return zPw[0]!=0;
306 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
307
308 /*
309 ** WEBPAGE: setup_uedit
310 **
311 ** Edit information about a user or create a new user.
@@ -314,10 +338,11 @@
314 void user_edit(void){
315 const char *zId, *zLogin, *zInfo, *zCap, *zPw;
316 const char *zGroup;
317 const char *zOldLogin;
318 int uid, i;
 
319 char *zDeleteVerify = 0; /* Delete user verification text */
320 int higherUser = 0; /* True if user being edited is SETUP and the */
321 /* user doing the editing is ADMIN. Disallow editing */
322 const char *inherit[128];
323 int a[128];
@@ -331,14 +356,15 @@
331 /* Check to see if an ADMIN user is trying to edit a SETUP account.
332 ** Don't allow that.
333 */
334 zId = PD("id", "0");
335 uid = atoi(zId);
336 if( zId && !g.perm.Setup && uid>0 ){
337 char *zOldCaps;
338 zOldCaps = db_text(0, "SELECT cap FROM user WHERE uid=%d",uid);
339 higherUser = zOldCaps && strchr(zOldCaps,'s');
 
 
340 }
341
342 if( P("can") ){
343 /* User pressed the cancel button */
344 cgi_redirect(cgi_referer("setup_ulist"));
@@ -460,12 +486,15 @@
460 }
461 admin_log( "Renamed user [%q] to [%q].", zOldLogin, zLogin );
462 }
463 db_protect_pop();
464 setup_incr_cfgcnt();
465 admin_log( "Updated user [%q] with capabilities [%q].",
466 zLogin, &aCap[0] );
 
 
 
467 if( atoi(PD("all","0"))>0 ){
468 Blob sql;
469 char *zErr = 0;
470 blob_zero(&sql);
471 if( zOldLogin==0 ){
@@ -526,11 +555,11 @@
526
527 /* Load the existing information about the user, if any
528 */
529 zLogin = "";
530 zInfo = "";
531 zCap = "";
532 zPw = "";
533 for(i='a'; i<='z'; i++) oa[i] = "";
534 for(i='0'; i<='9'; i++) oa[i] = "";
535 for(i='A'; i<='Z'; i++) oa[i] = "";
536 if( uid ){
537
--- src/setupuser.c
+++ src/setupuser.c
@@ -302,10 +302,34 @@
302 if( zPw==0 ) return 0;
303 if( zPw[0]==0 ) return 1;
304 while( zPw[0]=='*' ){ zPw++; }
305 return zPw[0]!=0;
306 }
307
308 /*
309 ** Return 1 if user capability string zCaps contains the given
310 ** capability letter, else 0.
311 */
312 static int userCapsContain(const char *zCaps, const char letter){
313 for( ; zCaps && *zCaps; ++zCaps ){
314 if( letter==*zCaps ) return 1;
315 }
316 return 0;
317 }
318
319 /*
320 ** Return 1 if user capability string zNew contains any capability
321 ** letter which is not in user capability string zOrig, else 0.
322 */
323 static int userCapsAreElevated(const char *zOrig, const char *zNew){
324 for( ; zNew && *zNew; ++zNew ){
325 if( !userCapsContain(zOrig, *zNew) ){
326 return 1;
327 }
328 }
329 return 0;
330 }
331
332 /*
333 ** WEBPAGE: setup_uedit
334 **
335 ** Edit information about a user or create a new user.
@@ -314,10 +338,11 @@
338 void user_edit(void){
339 const char *zId, *zLogin, *zInfo, *zCap, *zPw;
340 const char *zGroup;
341 const char *zOldLogin;
342 int uid, i;
343 char *zOldCaps = 0; /* Capabilities before edit */
344 char *zDeleteVerify = 0; /* Delete user verification text */
345 int higherUser = 0; /* True if user being edited is SETUP and the */
346 /* user doing the editing is ADMIN. Disallow editing */
347 const char *inherit[128];
348 int a[128];
@@ -331,14 +356,15 @@
356 /* Check to see if an ADMIN user is trying to edit a SETUP account.
357 ** Don't allow that.
358 */
359 zId = PD("id", "0");
360 uid = atoi(zId);
361 if( uid>0 ){
 
362 zOldCaps = db_text(0, "SELECT cap FROM user WHERE uid=%d",uid);
363 if( zId && !g.perm.Setup ){
364 higherUser = zOldCaps && strchr(zOldCaps,'s');
365 }
366 }
367
368 if( P("can") ){
369 /* User pressed the cancel button */
370 cgi_redirect(cgi_referer("setup_ulist"));
@@ -460,12 +486,15 @@
486 }
487 admin_log( "Renamed user [%q] to [%q].", zOldLogin, zLogin );
488 }
489 db_protect_pop();
490 setup_incr_cfgcnt();
491 admin_log( "Updated user [%q] with%s capabilities [%q].",
492 zLogin,
493 userCapsAreElevated(zOldCaps, &aCap[0])
494 ? " elevated" : "",
495 &aCap[0] );
496 if( atoi(PD("all","0"))>0 ){
497 Blob sql;
498 char *zErr = 0;
499 blob_zero(&sql);
500 if( zOldLogin==0 ){
@@ -526,11 +555,11 @@
555
556 /* Load the existing information about the user, if any
557 */
558 zLogin = "";
559 zInfo = "";
560 zCap = zOldCaps;
561 zPw = "";
562 for(i='a'; i<='z'; i++) oa[i] = "";
563 for(i='0'; i<='9'; i++) oa[i] = "";
564 for(i='A'; i<='Z'; i++) oa[i] = "";
565 if( uid ){
566

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button