Menu

Yet another sample for linux

is_null
2008-05-25
2013-04-17
  • is_null

    is_null - 2008-05-25

    -- sql start ----------
    CREATE TABLE `users_groups` (
      `uid` int(7) NOT NULL,
      `gid` int(7) NOT NULL,
      `main` tinyint(1) default NULL
    );

    CREATE TABLE `users` (
      `id` int(7) NOT NULL auto_increment,
      `name` varchar(30) NOT NULL,
      `password` varchar(34) NOT NULL,
      `home` varchar(150) default NULL,
      `shell` varchar(50) default NULL,
    -- Optionnal, for gecos with CONCAT_WS()
      `first_name` varchar(50) default NULL,
      `last_name` varchar(50) default NULL,
      `phone` int(15) default NULL,
      `country` varchar(5) default NULL,
      `email` varchar(100) NOT NULL,
      PRIMARY KEY  (`id`),
      UNIQUE KEY `name` (`name`)
    ) AUTO_INCREMENT=6000;

    CREATE TABLE `groups` (
      `id` int(7) NOT NULL auto_increment,
      `name` varchar(30) NOT NULL,
      `password` varchar(34) default NULL,
      PRIMARY KEY  (`id`),
      UNIQUE KEY `name` (`name`)
    ) AUTO_INCREMENT=6000;
    -- sql end ------------

    -- libnss-mysql.cfg start ----------
    getpwnam    select u.name, 'x', u.id, ug.gid, '', u.home, u.shell \             from users as u left join users_groups as ug on u.id = ug.uid \             where u.name='%1$s' and ug.main=true \             limit 1
    getpwuid    select u.name, 'x', u.id, ug.gid, '', u.home, u.shell \             from users as u left join users_groups as ug on u.id = ug.uid \             where u.name='%1$u' and ug.main=true \             limit 1
    getpwent    select u.name, 'x', u.id, ug.gid, '', u.home, u.shell \             from users as u left join users_groups as ug on u.id = ug.uid \             where u.name='%1$s' and ug.main=true \             limit 1
    getspnam    select name, password, '1', '0', '99999', '0', '0', '-1', '0' \              from users \             where name='%1$s' \             limit 1
    getspent    select name, password, '1', '0', '99999', '0', '0', '-1', '0' \             from users \             where name='%1$s' \             limit 1
    getgrnam    select name, password, id \             from groups \             where name='%1$s' \             limit 1
    getgrgid    select name, password, id \             from groups \             where id=%1$u \             limit 1
    getgrent    select name, password, id \             from groups
    memsbygid   select u.name \             from users as u left join users_groups as ug on u.id=ug.uid \             where ug.gid=%1$u
    gidsbymem   select ug.gid \             from users as u left join users_groups as ug on u.id=ug.uid \             where u.name='%1$s'
    -- libnss-mysql.cfg end ------------

    You can also use CONCAT_WS() with the optionnal fields if you installed them for the GECOS column, the fifth of getpwnam, getpwuid, getpwent, getgrgid.

    Thanks Ben for this great piece of software.

    Cheers, James.

     
    • is_null

      is_null - 2008-05-25

      I forgot to paste the permissions for mysql users.
      Replace 'itbm' with the name of your database.

      -- grant.sql start --------
      grant usage on *.* to 'nss-root'@'localhost';
      grant usage on *.* to 'nss-user'@'localhost';

      grant select (name, id, home, shell, password)
                   on itbm.users
                   To 'nss-user'@'localhost', 'nss-root'@'localhost';
      grant select (name, password, id)
                   on itbm.groups
                   to 'nss-root'@'localhost', 'nss-user'@'localhost';
      grant select (uid, gid, main)
                   on itbm.users_groups
                   to 'nss-root'@'localhost', 'nss-user'@'localhost';
      -- grant.sql end ----------

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.