Commit ae7d569b authored by Kevin Lyda's avatar Kevin Lyda
Browse files

Permission review

Added some missing checks.  Closes #5.
parent 64eb8e81
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -25,6 +25,10 @@ func ActionUser(cmd *dclish.Command) error {
// ActionUserAdd handles the `USER ADD` command.  This is used to add a
// new user.  This is new to the Go version of BULLETIN.
func ActionUserAdd(cmd *dclish.Command) error {
	if this.User.Admin == 0 {
		fmt.Println("ERROR: You are not an admin.")
		return nil
	}
	ctx := storage.Context()
	login := strings.ToUpper(cmd.Args[0])
	u, err := users.ValidExistingLogin(this.Q, login)
+3 −0
Original line number Diff line number Diff line
@@ -28,6 +28,9 @@ func ParseNumberList(input string) ([]int64, error) {
			if err1 != nil || err2 != nil || start > end {
				return nil, fmt.Errorf("invalid range: %s", segment)
			}
			if end-start > 10000 {
				return nil, fmt.Errorf("range too large: %s", segment)
			}
			for i := start; i <= end; i++ {
				result = append(result, i)
			}
+13 −4
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ import (
	"git.lyda.ie/pp/bulletin/pager"
	"git.lyda.ie/pp/bulletin/storage"
	"git.lyda.ie/pp/bulletin/this"
	"git.lyda.ie/pp/bulletin/users"
)

// ActionIndex handles the `INDEX` command.  This lists all the folders.
@@ -205,7 +206,11 @@ func ActionModify(cmd *dclish.Command) error {
		if this.User.Admin == 0 {
			return errors.New("must be an admin to modify the folder owner")
		}
		owner = cmd.Flags["/OWNER"].Value
		u, err := users.ValidExistingLogin(this.Q, cmd.Flags["/OWNER"].Value)
		if err != nil || u.Login == "" {
			return errors.New("specified owner not found")
		}
		owner = u.Login
	}
	name := this.Folder.Name
	if cmd.Flags["/NAME"].Set {
@@ -229,13 +234,17 @@ func ActionModify(cmd *dclish.Command) error {
//
// This originally existed as the subroutine REMOVE_FOLDER in bulletin5.for.
func ActionRemove(cmd *dclish.Command) error {
	if this.User.Login != this.Folder.Owner && this.User.Admin == 0 {
	folder, err := folders.FindFolder(cmd.Args[0])
	if err != nil || folder.Name == "" {
		return errors.New("folder not found")
	}
	if this.User.Login != folder.Owner && this.User.Admin == 0 {
		return errors.New("you are not able to remove the folder")
	}
	if this.Folder.Name == "GENERAL" {
	if folder.Name == "GENERAL" {
		return errors.New("can't delete folder GENERAL")
	}
	err := folders.DeleteFolder(cmd.Args[0])
	err = folders.DeleteFolder(folder.Name)
	if err == nil {
		fmt.Println("Folder removed.")
	}
+10 −2
Original line number Diff line number Diff line
@@ -265,8 +265,12 @@ func ActionAdd(cmd *dclish.Command) error {
		if f.Name == "" {
			return fmt.Errorf("folder '%s' does not exist", optFolder[i])
		}
		if f.Visibility != 0 && this.User.Admin == 0 && this.User.Login != f.Owner {
			return fmt.Errorf("folder '%s' is not accessible", optFolder[i])
		writable, err := folders.IsFolderWriteable(f.Name, this.User.Login)
		if err != nil {
			return err
		}
		if !writable {
			return fmt.Errorf("no access to write into folder '%s'", optFolder[i])
		}
	}

@@ -793,6 +797,10 @@ func ActionRead(cmd *dclish.Command) error {
//
// This originally existed as the subroutine REPLY in bulletin.for.
func ActionReply(cmd *dclish.Command) error {
	if this.User.Suspended == 1 {
		fmt.Println("ERROR: Your account is suspended (read-only).")
		return nil
	}
	extract := true
	if cmd.Flags["/EXTRACT"].Value == "false" {
		extract = false
+8 −2
Original line number Diff line number Diff line
@@ -78,7 +78,7 @@ func ActionSetNoaccess(cmd *dclish.Command) error {
			return errors.New("folder not found")
		}
	}
	if this.User.Admin == 0 || folder.Owner != this.User.Login {
	if this.User.Admin == 0 && folder.Owner != this.User.Login {
		return errors.New("must be an admin or folder owner")
	}
	return this.Q.DeleteFolderAccess(ctx, login, folder.Name)
@@ -140,7 +140,7 @@ func ActionSetAccess(cmd *dclish.Command) error {
			return errors.New("folder not found")
		}
	}
	if this.User.Admin == 0 || folder.Owner != this.User.Login {
	if this.User.Admin == 0 && folder.Owner != this.User.Login {
		return errors.New("must be an admin or folder owner")
	}
	visibility := int64(2)
@@ -152,12 +152,18 @@ func ActionSetAccess(cmd *dclish.Command) error {

// ActionSetAlways handles the `SET ALWAYS` command.
func ActionSetAlways(_ *dclish.Command) error {
	if this.User.Admin == 0 && this.User.Login != this.Folder.Owner {
		return errors.New("no privileges to modify folder")
	}
	ctx := storage.Context()
	return this.Q.UpdateFolderAlways(ctx, 1, this.Folder.Name)
}

// ActionSetNoalways handles the `SET NOALWAYS` command.
func ActionSetNoalways(_ *dclish.Command) error {
	if this.User.Admin == 0 && this.User.Login != this.Folder.Owner {
		return errors.New("no privileges to modify folder")
	}
	ctx := storage.Context()
	return this.Q.UpdateFolderAlways(ctx, 0, this.Folder.Name)
}
Loading