@@ -3297,8 +3297,6 @@ static krb5_error_code get_tgt_times(krb5_context ctx, const char *ccname,
3297
3297
}
3298
3298
3299
3299
static krb5_error_code get_fast_ccache_with_anonymous_pkinit (krb5_context ctx ,
3300
- uid_t fast_uid ,
3301
- gid_t fast_gid ,
3302
3300
bool posix_domain ,
3303
3301
struct cli_opts * cli_opts ,
3304
3302
krb5_keytab keytab ,
@@ -3308,7 +3306,6 @@ static krb5_error_code get_fast_ccache_with_anonymous_pkinit(krb5_context ctx,
3308
3306
{
3309
3307
krb5_error_code kerr ;
3310
3308
krb5_get_init_creds_opt * options ;
3311
- struct sss_creds * saved_creds = NULL ;
3312
3309
krb5_preauthtype pkinit = KRB5_PADATA_PK_AS_REQ ;
3313
3310
krb5_creds creds = { 0 };
3314
3311
@@ -3343,38 +3340,19 @@ static krb5_error_code get_fast_ccache_with_anonymous_pkinit(krb5_context ctx,
3343
3340
goto done ;
3344
3341
}
3345
3342
3346
- kerr = switch_creds (NULL , fast_uid , fast_gid , 0 , NULL , & saved_creds );
3347
- if (kerr != 0 ) {
3348
- DEBUG (SSSDBG_OP_FAILURE ,
3349
- "Failed to switch credentials to store FAST ccache with "
3350
- "expected permissions.\n" );
3351
- goto done ;
3352
- }
3353
-
3354
3343
kerr = create_ccache (ccname , & creds );
3355
3344
if (kerr != 0 ) {
3356
3345
DEBUG (SSSDBG_OP_FAILURE , "Failed to store FAST ccache.\n" );
3357
3346
goto done ;
3358
3347
}
3359
3348
3360
- kerr = restore_creds (saved_creds );
3361
- if (kerr != 0 ) {
3362
- DEBUG (SSSDBG_OP_FAILURE ,
3363
- "Failed to restore credentials, krb5_child might run with wrong "
3364
- "permissions, aborting.\n" );
3365
- goto done ;
3366
- }
3367
-
3368
3349
done :
3369
3350
sss_krb5_get_init_creds_opt_free (ctx , options );
3370
- talloc_free (saved_creds );
3371
3351
3372
3352
return kerr ;
3373
3353
}
3374
3354
3375
3355
static krb5_error_code get_fast_ccache_with_keytab (krb5_context ctx ,
3376
- uid_t fast_uid ,
3377
- gid_t fast_gid ,
3378
3356
bool posix_domain ,
3379
3357
struct cli_opts * cli_opts ,
3380
3358
krb5_keytab keytab ,
@@ -3399,11 +3377,7 @@ static krb5_error_code get_fast_ccache_with_keytab(krb5_context ctx,
3399
3377
/* Try to carry on */
3400
3378
}
3401
3379
3402
- kerr = k5c_become_user (fast_uid , fast_gid , posix_domain );
3403
- if (kerr != 0 ) {
3404
- DEBUG (SSSDBG_CRIT_FAILURE , "become_user failed: %d\n" , kerr );
3405
- exit (1 );
3406
- }
3380
+ sss_drop_all_caps ();
3407
3381
DEBUG (SSSDBG_TRACE_INTERNAL ,
3408
3382
"Running as [%" SPRIuid "][%" SPRIgid "].\n" , geteuid (), getegid ());
3409
3383
@@ -3557,8 +3531,7 @@ static krb5_error_code check_fast_ccache(TALLOC_CTX *mem_ctx,
3557
3531
3558
3532
/* Need to recreate the FAST ccache */
3559
3533
if (cli_opts -> fast_use_anonymous_pkinit ) {
3560
- kerr = get_fast_ccache_with_anonymous_pkinit (ctx , fast_uid , fast_gid ,
3561
- posix_domain , cli_opts ,
3534
+ kerr = get_fast_ccache_with_anonymous_pkinit (ctx , posix_domain , cli_opts ,
3562
3535
keytab , client_princ ,
3563
3536
ccname , realm );
3564
3537
if (kerr != 0 ) {
@@ -3567,8 +3540,8 @@ static krb5_error_code check_fast_ccache(TALLOC_CTX *mem_ctx,
3567
3540
"likely fail!\n" );
3568
3541
}
3569
3542
} else {
3570
- kerr = get_fast_ccache_with_keytab (ctx , fast_uid , fast_gid , posix_domain ,
3571
- cli_opts , keytab , client_princ , ccname );
3543
+ kerr = get_fast_ccache_with_keytab (ctx , posix_domain , cli_opts ,
3544
+ keytab , client_princ , ccname );
3572
3545
if (kerr != 0 ) {
3573
3546
DEBUG (SSSDBG_MINOR_FAILURE , "Creating FAST ccache with keytab failed, "
3574
3547
"krb5_child will likely fail!\n" );
@@ -4289,24 +4262,20 @@ int main(int argc, const char *argv[])
4289
4262
/* For PKINIT we might need access to the pcscd socket which by default
4290
4263
* is only allowed for authenticated users. Since PKINIT is part of
4291
4264
* the authentication and the user is not authenticated yet, we have
4292
- * to use different privileges and can only drop it only after the TGT is
4293
- * received. The fast_uid and fast_gid are the IDs the backend is running
4294
- * with. This can be either root or the 'sssd' user. Root is allowed by
4295
- * default and the 'sssd' user is allowed with the help of the
4296
- * sssd-pcsc.rules policy-kit rule. So those IDs are a suitable choice. We
4297
- * can only call switch_creds() because after the TGT is returned we have
4298
- * to switch to the IDs of the user to store the TGT.
4265
+ * to use different privileges and can only drop it after the TGT is
4266
+ * received. IDs the backend (and thus 'krb5_child) is running with are
4267
+ * either root or the 'sssd' user. Root is allowed by default and
4268
+ * the 'sssd' user is allowed with the help of the sssd-pcsc.rules
4269
+ * policy-kit rule. So those IDs are a suitable choice and needs to
4270
+ * be kept until TGT is obtained.
4299
4271
* If we are offline we have to switch to the user's credentials directly
4300
4272
* to make sure the empty ccache is created with the expected
4301
4273
* ownership. */
4302
- if (IS_SC_AUTHTOK (kr -> pd -> authtok ) && !offline ) {
4303
- kerr = switch_creds (kr , kr -> fast_uid , kr -> fast_gid , 0 , NULL ,
4304
- & kr -> pcsc_saved_creds );
4305
- } else {
4274
+ if (!IS_SC_AUTHTOK (kr -> pd -> authtok ) || offline ) {
4306
4275
kerr = k5c_become_user (kr -> uid , kr -> gid , kr -> posix_domain );
4307
4276
}
4308
4277
if (kerr != 0 ) {
4309
- DEBUG (SSSDBG_CRIT_FAILURE , "become_user failed.\n" );
4278
+ DEBUG (SSSDBG_CRIT_FAILURE , "k5c_become_user() failed.\n" );
4310
4279
ret = EFAULT ;
4311
4280
goto done ;
4312
4281
}
0 commit comments