@@ -928,6 +928,7 @@ static int chmod_list(
928
928
const mfu_perms * head ,
929
929
const char * usrname ,
930
930
const char * grname ,
931
+ const mfu_proc_t * proc ,
931
932
mfu_chmod_opts_t * opts )
932
933
{
933
934
/* assume we'll succeed, set this to FAILURE on any error */
@@ -990,7 +991,7 @@ static int chmod_list(
990
991
/* only attempt to change group if effective user id of
991
992
* the process is the owner of the item or process has
992
993
* CAP_CHWON capability */
993
- if (grname != NULL && opts -> geteuid != olduid && !opts -> capchown ) {
994
+ if (grname != NULL && proc -> geteuid != olduid && !proc -> cap_chown ) {
994
995
/* want to change group, but effective uid is not the
995
996
* owner, linux prevents normal users from doing this */
996
997
change = 0 ;
@@ -1069,7 +1070,7 @@ static int chmod_list(
1069
1070
/* don't bother changing permissions on files we don't own,
1070
1071
* unless process has CAP_FOWNER capability */
1071
1072
uid_t owner = (uid_t ) mfu_flist_file_get_uid (list , idx );
1072
- if (opts -> geteuid != owner && !opts -> capfowner ) {
1073
+ if (proc -> geteuid != owner && !proc -> cap_fowner ) {
1073
1074
/* don't attempt to change files we don't own */
1074
1075
change = 0 ;
1075
1076
}
@@ -1174,6 +1175,17 @@ void mfu_flist_chmod(
1174
1175
}
1175
1176
}
1176
1177
1178
+ /* Determine whether process is running with CAP_CHOWN,
1179
+ * allowing changes to uid/gid of file even when effective
1180
+ * user id of the process does not match owner of the file. */
1181
+
1182
+ /* Determine whether process is running with CAP_FOWNER,
1183
+ * allowing changes to permissions of file even when effective
1184
+ * user id of the process does not match owner of the file */
1185
+
1186
+ mfu_proc_t proc ;
1187
+ mfu_proc_set (& proc );
1188
+
1177
1189
/* wait for all tasks and start timer */
1178
1190
MPI_Barrier (MPI_COMM_WORLD );
1179
1191
double start_dchmod = MPI_Wtime ();
@@ -1199,7 +1211,7 @@ void mfu_flist_chmod(
1199
1211
1200
1212
/* do a dchmod on each element in the list for this level & pass it the size */
1201
1213
uint64_t stats [7 ] = {0 };
1202
- chmod_list (list , stats , head , usrname , grname , opts );
1214
+ chmod_list (list , stats , head , usrname , grname , & proc , opts );
1203
1215
1204
1216
/* tally up stats for above operation into running totals */
1205
1217
total_stats [ITEM_COUNT ] += stats [ITEM_COUNT ];
@@ -1252,13 +1264,6 @@ mfu_chmod_opts_t* mfu_chmod_opts_new(void)
1252
1264
{
1253
1265
mfu_chmod_opts_t * opts = (mfu_chmod_opts_t * ) MFU_MALLOC (sizeof (mfu_chmod_opts_t ));
1254
1266
1255
- /* cache current real user id */
1256
- opts -> getuid = getuid ();
1257
-
1258
- /* cache current effective user id,
1259
- * determines uid when considering owner ID of files */
1260
- opts -> geteuid = geteuid ();
1261
-
1262
1267
/* chown with uid==-1 preserves the same owner,
1263
1268
* default to keeping the owner the same */
1264
1269
opts -> uid = -1 ;
@@ -1271,30 +1276,6 @@ mfu_chmod_opts_t* mfu_chmod_opts_new(void)
1271
1276
* implied all in symbolic mode, like "+rX" */
1272
1277
opts -> umask = 0 ;
1273
1278
1274
- /* whether process is running with CAP_CHOWN, allowing
1275
- * changes to uid/gid of file even when effective id
1276
- * of the process does not match the file */
1277
- opts -> capchown = false;
1278
- #ifdef HAVE_LIBCAP
1279
- int cap_rc = cap_get_bound (CAP_CHOWN );
1280
- if (cap_rc > 0 ) {
1281
- /* process is running with CAP_CHOWN capability */
1282
- opts -> capchown = true;
1283
- }
1284
- #endif
1285
-
1286
- /* whether process is running with CAP_FOWNER, allowing
1287
- * changes to permissions of file even when effective user id
1288
- * of the process does not match the owner of the file */
1289
- opts -> capfowner = false;
1290
- #ifdef HAVE_LIBCAP
1291
- cap_rc = cap_get_bound (CAP_FOWNER );
1292
- if (cap_rc > 0 ) {
1293
- /* process is running with CAP_FOWNER capability */
1294
- opts -> capfowner = true;
1295
- }
1296
- #endif
1297
-
1298
1279
/* avoid calling chmod/chown on all items,
1299
1280
* if this is set to true, call on every item */
1300
1281
opts -> force = false;
0 commit comments