(conn *net.UnixConn, serverUnixPath string)
| 50 | } |
| 51 | |
| 52 | func proxyConnection(conn *net.UnixConn, serverUnixPath string) { |
| 53 | defer func() { |
| 54 | _ = conn.Close() |
| 55 | |
| 56 | mu.Lock() |
| 57 | connections -= 1 |
| 58 | mu.Unlock() |
| 59 | }() |
| 60 | |
| 61 | // Increase counters. |
| 62 | mu.Lock() |
| 63 | transactions += 1 |
| 64 | connections += 1 |
| 65 | mu.Unlock() |
| 66 | |
| 67 | // Get credentials. |
| 68 | creds, err := linux.GetUcred(conn) |
| 69 | if err != nil { |
| 70 | log.Errorf("Unable to get user credentials: %s", err) |
| 71 | return |
| 72 | } |
| 73 | |
| 74 | // Setup logging context. |
| 75 | logger := log.WithFields(log.Fields{ |
| 76 | "uid": creds.Uid, |
| 77 | "gid": creds.Gid, |
| 78 | "pid": creds.Pid, |
| 79 | }) |
| 80 | |
| 81 | logger.Debug("Connected") |
| 82 | defer logger.Debug("Disconnected") |
| 83 | |
| 84 | // Check if the user was setup. |
| 85 | if !util.PathExists(internalUtil.VarPath("users", fmt.Sprintf("%d", creds.Uid))) || !slices.Contains(projectNames, fmt.Sprintf("user-%d", creds.Uid)) { |
| 86 | log.Infof("Setting up for uid %d", creds.Uid) |
| 87 | err := serverSetupUser(creds.Uid) |
| 88 | if err != nil { |
| 89 | log.Errorf("Failed to setup new user: %v", err) |
| 90 | return |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | // Connect to the daemon. |
| 95 | unixAddr, err := net.ResolveUnixAddr("unix", serverUnixPath) |
| 96 | if err != nil { |
| 97 | log.Errorf("Unable to resolve the target server: %v", err) |
| 98 | return |
| 99 | } |
| 100 | |
| 101 | client, err := net.DialUnix("unix", nil, unixAddr) |
| 102 | if err != nil { |
| 103 | log.Errorf("Unable to connect to target server: %v", err) |
| 104 | return |
| 105 | } |
| 106 | |
| 107 | defer incusLogger.WarnOnError(client.Close, "Failed to close connection") |
| 108 | |
| 109 | // Get the TLS configuration |
no test coverage detected
searching dependent graphs…