pax_global_header00006660000000000000000000000064124307642600014516gustar00rootroot0000000000000052 comment=aab48f5d6bda85794946b26d945d2ee452e0e9ab uid-number-0.0.6/000077500000000000000000000000001243076426000135705ustar00rootroot00000000000000uid-number-0.0.6/LICENSE000066400000000000000000000013541243076426000146000ustar00rootroot00000000000000The ISC License Copyright (c) Isaac Z. Schlueter Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. uid-number-0.0.6/README.md000066400000000000000000000005311243076426000150460ustar00rootroot00000000000000Use this module to convert a username/groupname to a uid/gid number. Usage: ``` npm install uid-number ``` Then, in your node program: ```javascript var uidNumber = require("uid-number") uidNumber("isaacs", function (er, uid, gid) { // gid is null because we didn't ask for a group name // uid === 24561 because that's my number. }) ``` uid-number-0.0.6/get-uid-gid.js000077500000000000000000000012041243076426000162250ustar00rootroot00000000000000if (module !== require.main) { throw new Error("This file should not be loaded with require()") } if (!process.getuid || !process.getgid) { throw new Error("this file should not be called without uid/gid support") } var argv = process.argv.slice(2) , user = argv[0] || process.getuid() , group = argv[1] || process.getgid() if (!isNaN(user)) user = +user if (!isNaN(group)) group = +group console.error([user, group]) try { process.setgid(group) process.setuid(user) console.log(JSON.stringify({uid:+process.getuid(), gid:+process.getgid()})) } catch (ex) { console.log(JSON.stringify({error:ex.message,errno:ex.errno})) } uid-number-0.0.6/package.json000066400000000000000000000006701243076426000160610ustar00rootroot00000000000000{ "author": "Isaac Z. Schlueter (http://blog.izs.me/)", "name": "uid-number", "description": "Convert a username/group name to a uid/gid number", "version": "0.0.6", "repository": { "type": "git", "url": "git://github.com/isaacs/uid-number.git" }, "main": "uid-number.js", "dependencies": {}, "devDependencies": {}, "optionalDependencies": {}, "engines": { "node": "*" }, "license": "ISC" } uid-number-0.0.6/uid-number.js000066400000000000000000000033311243076426000161750ustar00rootroot00000000000000module.exports = uidNumber // This module calls into get-uid-gid.js, which sets the // uid and gid to the supplied argument, in order to find out their // numeric value. This can't be done in the main node process, // because otherwise node would be running as that user from this // point on. var child_process = require("child_process") , path = require("path") , uidSupport = process.getuid && process.setuid , uidCache = {} , gidCache = {} function uidNumber (uid, gid, cb) { if (!uidSupport) return cb() if (typeof cb !== "function") cb = gid, gid = null if (typeof cb !== "function") cb = uid, uid = null if (gid == null) gid = process.getgid() if (uid == null) uid = process.getuid() if (!isNaN(gid)) gid = gidCache[gid] = +gid if (!isNaN(uid)) uid = uidCache[uid] = +uid if (uidCache.hasOwnProperty(uid)) uid = uidCache[uid] if (gidCache.hasOwnProperty(gid)) gid = gidCache[gid] if (typeof gid === "number" && typeof uid === "number") { return process.nextTick(cb.bind(null, null, uid, gid)) } var getter = require.resolve("./get-uid-gid.js") child_process.execFile( process.execPath , [getter, uid, gid] , function (code, out, stderr) { if (code) { var er = new Error("could not get uid/gid\n" + stderr) er.code = code return cb(er) } try { out = JSON.parse(out+"") } catch (ex) { return cb(ex) } if (out.error) { var er = new Error(out.error) er.errno = out.errno return cb(er) } if (isNaN(out.uid) || isNaN(out.gid)) return cb(new Error( "Could not get uid/gid: "+JSON.stringify(out))) cb(null, uidCache[uid] = +out.uid, gidCache[gid] = +out.gid) }) }