MCPcopy Create free account
hub / github.com/gogs/gogs / runServ

Function runServ

internal/cmd/serv.go:131–279  ·  view source on GitHub ↗
(c *cli.Context)

Source from the content-addressed store, hash-verified

129}
130
131func runServ(c *cli.Context) error {
132 ctx := context.Background()
133 setup(c, "serv.log", true)
134
135 if conf.SSH.Disabled {
136 println("Gogs: SSH has been disabled")
137 return nil
138 }
139
140 if len(c.Args()) < 1 {
141 fail("Not enough arguments", "Not enough arguments")
142 }
143
144 sshCmd := os.Getenv("SSH_ORIGINAL_COMMAND")
145 if sshCmd == "" {
146 println("Hi there, You've successfully authenticated, but Gogs does not provide shell access.")
147 println("If this is unexpected, please log in with password and setup Gogs under another user.")
148 return nil
149 }
150
151 verb, args := parseSSHCmd(sshCmd)
152 repoFullName := strings.ToLower(strings.Trim(args, "'"))
153 repoFields := strings.SplitN(repoFullName, "/", 2)
154 if len(repoFields) != 2 {
155 fail("Invalid repository path", "Invalid repository path: %v", args)
156 }
157 ownerName := strings.ToLower(repoFields[0])
158 repoName := strings.TrimSuffix(strings.ToLower(repoFields[1]), ".git")
159 repoName = strings.TrimSuffix(repoName, ".wiki")
160
161 owner, err := database.Handle.Users().GetByUsername(ctx, ownerName)
162 if err != nil {
163 if database.IsErrUserNotExist(err) {
164 fail("Repository owner does not exist", "Unregistered owner: %s", ownerName)
165 }
166 fail("Internal error", "Failed to get repository owner '%s': %v", ownerName, err)
167 }
168
169 repo, err := database.GetRepositoryByName(owner.ID, repoName)
170 if err != nil {
171 if database.IsErrRepoNotExist(err) {
172 fail(accessDeniedMessage, "Repository does not exist: %s/%s", owner.Name, repoName)
173 }
174 fail("Internal error", "Failed to get repository: %v", err)
175 }
176 repo.Owner = owner
177
178 requestMode, ok := allowedCommands[verb]
179 if !ok {
180 fail("Unknown git command", "Unknown git command '%s'", verb)
181 }
182
183 // Prohibit push to mirror repositories.
184 if requestMode > database.AccessModeRead && repo.IsMirror {
185 fail("Mirror repository is read-only", "")
186 }
187
188 // Allow anonymous (user is nil) clone for public repositories.

Callers

nothing calls this directly

Calls 15

IsErrUserNotExistFunction · 0.92
GetRepositoryByNameFunction · 0.92
IsErrRepoNotExistFunction · 0.92
GetPublicKeyByIDFunction · 0.92
UpdatePublicKeyFunction · 0.92
IsWindowsRuntimeFunction · 0.92
ComposeHookEnvsFunction · 0.92
setupFunction · 0.85
parseSSHCmdFunction · 0.85
appendFunction · 0.85
GetByUsernameMethod · 0.80
UsersMethod · 0.80

Tested by

no test coverage detected