View | Details | Raw Unified | Return to bug 430 | Differences between
and this patch

Collapse All | Expand All

(-)../openssh-3.4p1/sftp-server.c (-1 / +40 lines)
Lines 52-57 Link Here
52
/* Version of client */
52
/* Version of client */
53
int version;
53
int version;
54
/* deny client write operations */
55
int readonly = 0;
56
54
/* portable attibutes, etc. */
57
/* portable attibutes, etc. */
55
typedef struct Stat Stat;
58
typedef struct Stat Stat;
Lines 390-395 Link Here
390
       pflags = get_int();             /* portable flags */
393
       pflags = get_int();             /* portable flags */
391
       a = get_attrib();
394
       a = get_attrib();
392
       flags = flags_from_portable(pflags);
395
       flags = flags_from_portable(pflags);
396
       if (((flags & O_ACCMODE) == O_RDWR) ||
397
               ((flags & O_ACCMODE) == O_WRONLY)) {
398
               status = SSH2_FX_PERMISSION_DENIED;
399
               send_status(id, status);
400
               return;
401
       }
393
       mode = (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ? a->perm : 0666;
402
       mode = (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ? a->perm : 0666;
394
       TRACE("open id %u name %s flags %d mode 0%o", id, name, pflags, mode);
403
       TRACE("open id %u name %s flags %d mode 0%o", id, name, pflags, mode);
395
       fd = open(name, flags, mode);
404
       fd = open(name, flags, mode);
Lines 587-592 Link Here
587
       id = get_int();
596
       id = get_int();
588
       name = get_string(NULL);
597
       name = get_string(NULL);
589
       a = get_attrib();
598
       a = get_attrib();
599
       if (readonly) {
600
               status = SSH2_FX_PERMISSION_DENIED;
601
               send_status(id, status);
602
               return;
603
       }
590
       TRACE("setstat id %u name %s", id, name);
604
       TRACE("setstat id %u name %s", id, name);
591
       if (a->flags & SSH2_FILEXFER_ATTR_SIZE) {
605
       if (a->flags & SSH2_FILEXFER_ATTR_SIZE) {
592
               ret = truncate(name, a->size);
606
               ret = truncate(name, a->size);
Lines 604-610 Link Here
604
                       status = errno_to_portable(errno);
618
                       status = errno_to_portable(errno);
605
       }
619
       }
606
       if (a->flags & SSH2_FILEXFER_ATTR_UIDGID) {
620
       if (a->flags & SSH2_FILEXFER_ATTR_UIDGID) {
607
               ret = chown(name, a->uid, a->gid);
621
               ret = lchown(name, a->uid, a->gid);
608
               if (ret == -1)
622
               if (ret == -1)
609
                       status = errno_to_portable(errno);
623
                       status = errno_to_portable(errno);
610
       }
624
       }
Lines 802-807 Link Here
802
       id = get_int();
816
       id = get_int();
803
       name = get_string(NULL);
817
       name = get_string(NULL);
818
       if (readonly) {
819
               status = SSH2_FX_PERMISSION_DENIED;
820
               send_status(id, status);
821
               return;
822
       }
804
       TRACE("remove id %u name %s", id, name);
823
       TRACE("remove id %u name %s", id, name);
805
       ret = unlink(name);
824
       ret = unlink(name);
806
       status = (ret == -1) ? errno_to_portable(errno) : SSH2_FX_OK;
825
       status = (ret == -1) ? errno_to_portable(errno) : SSH2_FX_OK;
Lines 820-825 Link Here
820
       id = get_int();
839
       id = get_int();
821
       name = get_string(NULL);
840
       name = get_string(NULL);
822
       a = get_attrib();
841
       a = get_attrib();
842
       if (readonly) {
843
               status = SSH2_FX_PERMISSION_DENIED;
844
               send_status(id, status);
845
               return;
846
       }
823
       mode = (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ?
847
       mode = (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ?
824
           a->perm & 0777 : 0777;
848
           a->perm & 0777 : 0777;
825
       TRACE("mkdir id %u name %s mode 0%o", id, name, mode);
849
       TRACE("mkdir id %u name %s mode 0%o", id, name, mode);
Lines 838-843 Link Here
838
       id = get_int();
862
       id = get_int();
839
       name = get_string(NULL);
863
       name = get_string(NULL);
864
       if (readonly) {
865
               status = SSH2_FX_PERMISSION_DENIED;
866
               send_status(id, status);
867
               return;
868
       }
840
       TRACE("rmdir id %u name %s", id, name);
869
       TRACE("rmdir id %u name %s", id, name);
841
       ret = rmdir(name);
870
       ret = rmdir(name);
842
       status = (ret == -1) ? errno_to_portable(errno) : SSH2_FX_OK;
871
       status = (ret == -1) ? errno_to_portable(errno) : SSH2_FX_OK;
Lines 881-886 Link Here
881
       id = get_int();
910
       id = get_int();
882
       oldpath = get_string(NULL);
911
       oldpath = get_string(NULL);
883
       newpath = get_string(NULL);
912
       newpath = get_string(NULL);
913
       if (readonly) {
914
               status = SSH2_FX_PERMISSION_DENIED;
915
               send_status(id, status);
916
               return;
917
       }
884
       TRACE("rename id %u old %s new %s", id, oldpath, newpath);
918
       TRACE("rename id %u old %s new %s", id, oldpath, newpath);
885
       /* fail if 'newpath' exists */
919
       /* fail if 'newpath' exists */
886
       if (stat(newpath, &st) == -1) {
920
       if (stat(newpath, &st) == -1) {
Lines 927-932 Link Here
927
       id = get_int();
970
       id = get_int();
928
       oldpath = get_string(NULL);
971
       oldpath = get_string(NULL);
929
       newpath = get_string(NULL);
972
       newpath = get_string(NULL);
973
       if (readonly) {
974
               status = SSH2_FX_PERMISSION_DENIED;
975
               send_status(id, status);
976
               return;
977
       }
930
       TRACE("symlink id %u old %s new %s", id, oldpath, newpath);
978
       TRACE("symlink id %u old %s new %s", id, oldpath, newpath);
931
       /* fail if 'newpath' exists */
979
       /* fail if 'newpath' exists */
932
       if (stat(newpath, &st) == -1) {
980
       if (stat(newpath, &st) == -1) {

Return to bug 430