This file is indexed.

/usr/lib/nodejs/pg/connection-parameters.js is in node-pg 0.13.3-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var dns = require('dns');
var path = require('path');

var defaults = require(__dirname + '/defaults');

var val = function(key, config) {
  return config[key] ||
    process.env['PG' + key.toUpperCase()] ||
    defaults[key];
};

var url = require('url');
//parses a connection string
var parse = function(str) {
  //unix socket
  if(str.charAt(0) === '/') {
    return { host: str };
  }
  // url parse expects spaces encoded as %20
  str = encodeURI(str);
  var result = url.parse(str);
  var config = {};
  config.host = result.hostname;
  config.database = result.pathname ? result.pathname.slice(1) : null;
  var auth = (result.auth || ':').split(':');
  config.user = auth[0];
  config.password = auth[1];
  config.port = result.port;
  return config;
};

var ConnectionParameters = function(config) {
  config = typeof config == 'string' ? parse(config) : (config || {});
  this.user = val('user', config);
  this.database = val('database', config);
  this.port = parseInt(val('port', config), 10);
  this.host = val('host', config);
  this.password = val('password', config);
  this.binary = val('binary', config);
  this.ssl = config.ssl || defaults.ssl;
  //a domain socket begins with '/'
  this.isDomainSocket = (!(this.host||'').indexOf('/'));
};

var add = function(params, config, paramName) {
  var value = config[paramName];
  if(value) {
    params.push(paramName+"='"+value+"'");
  }
};

ConnectionParameters.prototype.getLibpqConnectionString = function(cb) {
  var params = [];
  add(params, this, 'user');
  add(params, this, 'password');
  add(params, this, 'port');
  if(this.database) {
    params.push("dbname='" + this.database + "'");
  }
  if(this.isDomainSocket) {
    params.push("host=" + this.host);
    return cb(null, params.join(' '));
  }
  params.push("options=--client_encoding='utf-8'");
  dns.lookup(this.host, function(err, address) {
    if(err) return cb(err, null);
    params.push("hostaddr=" + address);
    return cb(null, params.join(' '));
  });
};

module.exports = ConnectionParameters;