@@ -247,17 +247,10 @@ func (c *Client) initNSRequest(ctx context.Context, auth eosclient.Authorization
247
247
// cbox is a sudo'er, so we become the user specified in UID/GID, if it is set
248
248
rq .Authkey = c .opt .Authkey
249
249
250
- if auth .Role .UID != "" && auth .Role .GID != "" {
251
- uidInt , err := strconv .ParseUint (auth .Role .UID , 10 , 64 )
252
- if err != nil {
253
- return nil , err
254
- }
255
- gidInt , err := strconv .ParseUint (auth .Role .GID , 10 , 64 )
256
- if err != nil {
257
- return nil , err
258
- }
259
- rq .Role .Uid = uidInt
260
- rq .Role .Gid = gidInt
250
+ uid , gid , err := utils .ExtractUidGid (auth )
251
+ if err == nil {
252
+ rq .Role .Uid = uid
253
+ rq .Role .Gid = gid
261
254
}
262
255
}
263
256
@@ -288,17 +281,10 @@ func (c *Client) initMDRequest(ctx context.Context, auth eosclient.Authorization
288
281
// cbox is a sudo'er, so we become the user specified in UID/GID, if it is set
289
282
rq .Authkey = c .opt .Authkey
290
283
291
- if auth .Role .UID != "" && auth .Role .GID != "" {
292
- uidInt , err := strconv .ParseUint (auth .Role .UID , 10 , 64 )
293
- if err != nil {
294
- return nil , err
295
- }
296
- gidInt , err := strconv .ParseUint (auth .Role .GID , 10 , 64 )
297
- if err != nil {
298
- return nil , err
299
- }
300
- rq .Role .Uid = uidInt
301
- rq .Role .Gid = gidInt
284
+ uid , gid , err := utils .ExtractUidGid (auth )
285
+ if err == nil {
286
+ rq .Role .Uid = uid
287
+ rq .Role .Gid = gid
302
288
}
303
289
}
304
290
@@ -738,12 +724,13 @@ func (c *Client) GetFileInfoByPath(ctx context.Context, userAuth eosclient.Autho
738
724
log := appctx .GetLogger (ctx )
739
725
log .Debug ().Str ("func" , "GetFileInfoByPath" ).Str ("uid,gid" , userAuth .Role .UID + "," + userAuth .Role .GID ).Str ("path" , path ).Msg ("entering" )
740
726
741
- daemonAuth := utils .GetDaemonAuth ()
727
+ // UserAuth may not be sufficient, because the user may not have access to the file
728
+ // e.g. in the case of a guest account. So we check if a uid/gid is set, and if not,
729
+ // revert to the daemon account
730
+ auth := utils .GetEOSAuth (userAuth )
742
731
743
732
// Initialize the common fields of the MDReq
744
- // We do this as the daemon account, because the user may not have access to the file
745
- // e.g. in the case of a guest account
746
- mdrq , err := c .initMDRequest (ctx , daemonAuth )
733
+ mdrq , err := c .initMDRequest (ctx , auth )
747
734
if err != nil {
748
735
return nil , err
749
736
}
@@ -800,7 +787,7 @@ func (c *Client) GetFileInfoByPath(ctx context.Context, userAuth eosclient.Autho
800
787
}
801
788
802
789
log .Info ().Str ("func" , "GetFileInfoByPath" ).Str ("path" , path ).Uint64 ("info.Inode" , info .Inode ).Uint64 ("size" , info .Size ).Str ("etag" , info .ETag ).Msg ("result" )
803
- return c .fixupACLs (ctx , daemonAuth , info ), nil
790
+ return c .fixupACLs (ctx , auth , info ), nil
804
791
}
805
792
806
793
// GetFileInfoByFXID returns the FileInfo by the given file id in hexadecimal.
@@ -986,13 +973,11 @@ func (c *Client) Chown(ctx context.Context, auth, chownAuth eosclient.Authorizat
986
973
987
974
msg := new (erpc.NSRequest_ChownRequest )
988
975
msg .Owner = new (erpc.RoleId )
989
- msg .Owner .Uid , err = strconv .ParseUint (chownAuth .Role .UID , 10 , 64 )
990
- if err != nil {
991
- return err
992
- }
993
- msg .Owner .Gid , err = strconv .ParseUint (chownAuth .Role .GID , 10 , 64 )
994
- if err != nil {
995
- return err
976
+
977
+ uid , gid , err := utils .ExtractUidGid (chownAuth )
978
+ if err == nil {
979
+ msg .Owner .Uid = uid
980
+ msg .Owner .Gid = gid
996
981
}
997
982
998
983
msg .Id = new (erpc.MDId )
@@ -1225,9 +1210,8 @@ func (c *Client) Rename(ctx context.Context, auth eosclient.Authorization, oldPa
1225
1210
}
1226
1211
1227
1212
// List the contents of the directory given by path.
1228
- func (c * Client ) List (ctx context.Context , userAuth eosclient.Authorization , dpath string ) ([]* eosclient.FileInfo , error ) {
1213
+ func (c * Client ) List (ctx context.Context , auth eosclient.Authorization , dpath string ) ([]* eosclient.FileInfo , error ) {
1229
1214
log := appctx .GetLogger (ctx )
1230
- log .Info ().Str ("func" , "List" ).Str ("uid,gid" , userAuth .Role .UID + "," + userAuth .Role .GID ).Str ("dpath" , dpath ).Msg ("" )
1231
1215
1232
1216
// Stuff filename, uid, gid into the FindRequest type
1233
1217
fdrq := new (erpc.FindRequest )
@@ -1238,23 +1222,12 @@ func (c *Client) List(ctx context.Context, userAuth eosclient.Authorization, dpa
1238
1222
1239
1223
fdrq .Role = new (erpc.RoleId )
1240
1224
1241
- var auth eosclient.Authorization
1242
- if userAuth .Role .UID == "" || userAuth .Role .GID == "" {
1243
- auth = utils .GetDaemonAuth ()
1244
- } else {
1245
- auth = userAuth
1246
- }
1247
-
1248
- uidInt , err := strconv .ParseUint (auth .Role .UID , 10 , 64 )
1249
- if err != nil {
1250
- return nil , err
1251
- }
1252
- gidInt , err := strconv .ParseUint (auth .Role .GID , 10 , 64 )
1225
+ uid , gid , err := utils .ExtractUidGid (auth )
1253
1226
if err != nil {
1254
- return nil , err
1227
+ return nil , errors . Wrap ( err , "Failed to extract uid/gid from auth" )
1255
1228
}
1256
- fdrq .Role .Uid = uidInt
1257
- fdrq .Role .Gid = gidInt
1229
+ fdrq .Role .Uid = uid
1230
+ fdrq .Role .Gid = gid
1258
1231
1259
1232
fdrq .Authkey = c .opt .Authkey
1260
1233
0 commit comments