aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--passwd-help.pd56
-rw-r--r--passwd.c224
-rw-r--r--uid0x2d0x3eusername-help.pd26
-rw-r--r--uid0x2d0x3eusername.pd18
-rw-r--r--username0x2d0x3euid-help.pd33
-rw-r--r--username0x2d0x3euid.pd31
6 files changed, 388 insertions, 0 deletions
diff --git a/passwd-help.pd b/passwd-help.pd
new file mode 100644
index 0000000..b23a7f5
--- /dev/null
+++ b/passwd-help.pd
@@ -0,0 +1,56 @@
+#N canvas 47 122 698 474 10;
+#X obj 98 40 hsl 128 15 0 127 0 0 empty empty empty -2 -6 0 8 -262144
+-1 -1 0 1;
+#X floatatom 95 63 5 0 0 0 User_ID - -;
+#X obj 47 200 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
+-1;
+#X msg 194 148 10;
+#X msg 112 86 bang;
+#X text 209 168 <-- set by argument or cold inlet;
+#X text 148 85 output current;
+#X obj 94 167 passwd;
+#X text 37 20 fetch passwd data based on UID or username;
+#X msg 271 83 symbol hans;
+#X symbolatom 10 359 0 0 0 3 username - -;
+#X symbolatom 76 358 0 0 0 3 password - -;
+#X floatatom 142 358 0 0 0 3 uid - -;
+#X floatatom 173 358 0 0 0 3 gid - -;
+#X symbolatom 278 366 0 0 0 3 user_access_class - -;
+#X symbolatom 300 331 0 0 0 3 gecos - -;
+#X symbolatom 337 297 0 0 0 3 home_folder - -;
+#X symbolatom 376 264 0 0 0 3 shell - -;
+#X msg 269 105 symbol trash;
+#X text 361 105 ignore bad usernames;
+#X text 363 83 use a symbolic username;
+#X obj 76 224 unpack symbol symbol float float float float symbol symbol
+symbol symbol float float;
+#X floatatom 204 428 6 0 0 3 password_change_days - -;
+#X floatatom 226 395 6 0 0 3 password_change_seconds - -;
+#X floatatom 508 300 6 0 0 3 account_expire_days - -;
+#X floatatom 530 267 6 0 0 3 account_expire_seconds - -;
+#X msg 269 56 symbol daemon;
+#X text 188 195 bang on right inlet if no match;
+#X obj 138 195 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
+-1;
+#X connect 0 0 1 0;
+#X connect 1 0 7 0;
+#X connect 3 0 7 1;
+#X connect 4 0 7 0;
+#X connect 7 0 2 0;
+#X connect 7 0 21 0;
+#X connect 7 1 28 0;
+#X connect 9 0 7 0;
+#X connect 18 0 7 0;
+#X connect 21 0 10 0;
+#X connect 21 1 11 0;
+#X connect 21 2 12 0;
+#X connect 21 3 13 0;
+#X connect 21 4 22 0;
+#X connect 21 5 23 0;
+#X connect 21 6 14 0;
+#X connect 21 7 15 0;
+#X connect 21 8 16 0;
+#X connect 21 9 17 0;
+#X connect 21 10 24 0;
+#X connect 21 11 25 0;
+#X connect 26 0 7 0;
diff --git a/passwd.c b/passwd.c
new file mode 100644
index 0000000..bb0a020
--- /dev/null
+++ b/passwd.c
@@ -0,0 +1,224 @@
+/* --------------------------------------------------------------------------*/
+/* */
+/* converts a UID number to a user name symbol */
+/* Written by Hans-Christoph Steiner <hans@at.or.at> */
+/* */
+/* Copyright (c) 2006 Hans-Christoph Steiner */
+/* */
+/* This program is free software; you can redistribute it and/or */
+/* modify it under the terms of the GNU General Public License */
+/* as published by the Free Software Foundation; either version 2 */
+/* of the License, or (at your option) any later version. */
+/* */
+/* See file LICENSE for further informations on licensing terms. */
+/* */
+/* This program is distributed in the hope that it will be useful, */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
+/* GNU General Public License for more details. */
+/* */
+/* You should have received a copy of the GNU General Public License */
+/* along with this program; if not, write to the Free Software Foundation, */
+/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+/* */
+/* --------------------------------------------------------------------------*/
+
+#ifndef _WIN32 // this doesn't work on Windows (yet?)
+
+#include <m_pd.h>
+
+#ifdef _WIN32
+#define _WIN32_WINNT 0x0400
+#include <windows.h>
+#include <stdio.h>
+#include <lm.h>
+#else
+#include <stdlib.h>
+#include <pwd.h>
+#endif
+
+#include <string.h>
+/*
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/errno.h>
+*/
+
+static char *version = "$Revision: 1.1 $";
+
+t_int passwd_instance_count;
+
+#define DEBUG(x)
+//#define DEBUG(x) x
+
+/*------------------------------------------------------------------------------
+ * CLASS DEF
+ */
+static t_class *passwd_class;
+
+typedef struct _passwd {
+ t_object x_obj;
+ t_float x_uid;
+ t_outlet *x_data_outlet;
+ t_outlet *x_status_outlet;
+} t_passwd;
+
+/*------------------------------------------------------------------------------
+ * IMPLEMENTATION
+ */
+
+static void passwd_output(t_passwd *x)
+{
+ DEBUG(post("passwd_output"););
+ struct passwd *passwd_pointer;
+ t_atom output_data[11];
+
+#ifdef _WIN32
+ /* TODO: implement for Windows! */
+#else
+ if( x->x_uid < 0 )
+ {
+ post("[passwd]: ignoring UID less than zero or bad username");
+ outlet_bang(x->x_status_outlet);
+ }
+ else
+ {
+ passwd_pointer = getpwuid((uid_t)x->x_uid);
+ if( passwd_pointer != NULL )
+ {
+ SETSYMBOL(output_data, gensym(passwd_pointer->pw_passwd));
+ SETFLOAT(output_data + 1, passwd_pointer->pw_uid);
+ SETFLOAT(output_data + 2, passwd_pointer->pw_gid);
+ SETFLOAT(output_data + 3, passwd_pointer->pw_change / 86400);
+ SETFLOAT(output_data + 4, passwd_pointer->pw_change % 86400);
+ SETSYMBOL(output_data + 5, gensym(passwd_pointer->pw_class));
+ SETSYMBOL(output_data + 6, gensym(passwd_pointer->pw_gecos));
+ SETSYMBOL(output_data + 7, gensym(passwd_pointer->pw_dir));
+ SETSYMBOL(output_data + 8, gensym(passwd_pointer->pw_shell));
+ SETFLOAT(output_data + 9, (passwd_pointer->pw_expire / 86400));
+ SETFLOAT(output_data + 10, (passwd_pointer->pw_expire % 86400));
+ outlet_anything(x->x_data_outlet, gensym(passwd_pointer->pw_name),
+ 11, output_data);
+ }
+ else
+ {
+ outlet_bang(x->x_status_outlet);
+ }
+ }
+#endif /* _WIN32 */
+}
+
+
+static t_float get_uid_from_arguments(int argc, t_atom *argv)
+{
+ t_symbol *first_argument;
+ t_float uid = -1;
+ struct passwd *passwd_pointer;
+
+ if(argc == 0) return(0);
+
+ if(argc != 1)
+ post("[passwd]: too many arguments (%d), ignoring all but the first",
+ argc);
+
+ first_argument = atom_getsymbolarg(0,argc,argv);
+ if(first_argument == &s_)
+ { // single float arg means UID #
+ uid = atom_getfloatarg(0,argc,argv);
+ if( uid < 0 )
+ {
+ error("[passwd]: UID less than zero not allowed (%d)", uid);
+ return(-1);
+ }
+ }
+ else
+ { // single symbol arg means username
+ passwd_pointer = getpwnam(first_argument->s_name);
+ if( passwd_pointer != NULL )
+ return((t_float) passwd_pointer->pw_uid);
+ else
+ return(-1);
+ }
+ return(-1);
+}
+
+
+static void passwd_set(t_passwd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ /* get rid of the unused variable warning with the if() statement */
+ if( strcmp(s->s_name, "set") == 0 )
+ x->x_uid = get_uid_from_arguments(argc, argv);
+}
+
+
+static void passwd_float(t_passwd *x, t_float f)
+{
+ x->x_uid = f;
+ passwd_output(x);
+}
+
+static void passwd_symbol(t_passwd *x, t_symbol *s)
+{
+ t_atom argv[1];
+ SETSYMBOL(argv, s);
+ passwd_set(x, gensym("set"), 1, argv);
+ passwd_output(x);
+}
+
+
+static void *passwd_new(t_symbol *s, int argc, t_atom *argv)
+{
+ DEBUG(post("passwd_new"););
+
+ t_passwd *x = (t_passwd *)pd_new(passwd_class);
+
+ if(!passwd_instance_count)
+ {
+ post("[passwd] %s",version);
+ post("\twritten by Hans-Christoph Steiner <hans@at.or.at>");
+ post("\tcompiled on "__DATE__" at "__TIME__ " ");
+ }
+ passwd_instance_count++;
+
+ floatinlet_new(&x->x_obj, &x->x_uid);
+ x->x_data_outlet = outlet_new(&x->x_obj, 0);
+ x->x_status_outlet = outlet_new(&x->x_obj, 0);
+
+ passwd_set(x, gensym("set"), argc, argv);
+
+ return (x);
+}
+
+
+void passwd_free(void)
+{
+#ifdef _WIN32
+#else
+ endpwent();
+#endif /* _WIN32 */
+}
+
+
+void passwd_setup(void)
+{
+ DEBUG(post("passwd_setup"););
+ passwd_class = class_new(gensym("passwd"),
+ (t_newmethod)passwd_new,
+ 0,
+ sizeof(t_passwd),
+ 0,
+ A_GIMME,
+ 0);
+ /* add inlet datatype methods */
+ class_addbang(passwd_class, (t_method) passwd_output);
+ class_addfloat(passwd_class, (t_method) passwd_float);
+ class_addsymbol(passwd_class, (t_method) passwd_symbol);
+ /* add inlet message methods */
+ class_addmethod(passwd_class,
+ (t_method) passwd_set,
+ gensym("set"),
+ A_GIMME,
+ 0);
+}
+
+#endif /* NOT _WIN32 */
diff --git a/uid0x2d0x3eusername-help.pd b/uid0x2d0x3eusername-help.pd
new file mode 100644
index 0000000..578b8fc
--- /dev/null
+++ b/uid0x2d0x3eusername-help.pd
@@ -0,0 +1,26 @@
+#N canvas 185 212 477 316 10;
+#X msg 14 148 bang;
+#X obj 30 240 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
+-1;
+#X msg 271 159 bang;
+#X obj 142 240 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
+-1;
+#X text 145 262 ^-- bang if not found;
+#X text 12 14 convert a UID to a username;
+#X symbolatom 55 242 0 0 0 0 - - -;
+#X msg 143 162 1;
+#X symbolatom 272 242 0 0 0 0 - - -;
+#X obj 60 93 hsl 128 15 0 127 0 0 empty empty empty -2 -6 0 8 -262144
+-1 -1 300 1;
+#X floatatom 58 123 5 0 0 0 - - -;
+#X obj 56 190 uid->username;
+#X obj 272 201 uid->username 0;
+#X connect 0 0 11 0;
+#X connect 2 0 12 0;
+#X connect 7 0 11 1;
+#X connect 9 0 10 0;
+#X connect 10 0 11 0;
+#X connect 11 0 1 0;
+#X connect 11 0 6 0;
+#X connect 11 1 3 0;
+#X connect 12 0 8 0;
diff --git a/uid0x2d0x3eusername.pd b/uid0x2d0x3eusername.pd
new file mode 100644
index 0000000..ea7718c
--- /dev/null
+++ b/uid0x2d0x3eusername.pd
@@ -0,0 +1,18 @@
+#N canvas 217 216 510 229 10;
+#X obj 18 85 passwd;
+#X obj 18 12 inlet;
+#X obj 19 183 outlet;
+#X obj 66 12 inlet;
+#X obj 118 31 loadbang;
+#X obj 66 59 purepd/float_argument \$1;
+#X obj 82 183 outlet;
+#X obj 18 118 list;
+#X obj 18 147 list split 1;
+#X connect 0 0 7 0;
+#X connect 0 1 6 0;
+#X connect 1 0 0 0;
+#X connect 3 0 5 0;
+#X connect 4 0 5 0;
+#X connect 5 0 0 1;
+#X connect 7 0 8 0;
+#X connect 8 0 2 0;
diff --git a/username0x2d0x3euid-help.pd b/username0x2d0x3euid-help.pd
new file mode 100644
index 0000000..cd8b579
--- /dev/null
+++ b/username0x2d0x3euid-help.pd
@@ -0,0 +1,33 @@
+#N canvas 185 212 477 316 10;
+#X msg 57 49 symbol root;
+#X msg 76 81 symbol hans;
+#X obj 56 190 username->uid;
+#X floatatom 56 240 5 0 0 0 - - -;
+#X text 12 14 convert a username to a UID.;
+#X msg 14 148 bang;
+#X msg 143 162 symbol daemon;
+#X obj 30 240 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
+-1;
+#X msg 94 109 symbol lp;
+#X msg 100 135 symbol trash;
+#X floatatom 272 231 5 0 0 0 - - -;
+#X msg 271 159 bang;
+#X text 192 136 ignore bad usernames;
+#X obj 142 240 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
+-1;
+#X text 145 262 ^-- bang if not found;
+#X obj 409 228 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
+-1;
+#X obj 272 201 username->uid daemon;
+#X connect 0 0 2 0;
+#X connect 1 0 2 0;
+#X connect 2 0 3 0;
+#X connect 2 0 7 0;
+#X connect 2 1 13 0;
+#X connect 5 0 2 0;
+#X connect 6 0 2 1;
+#X connect 8 0 2 0;
+#X connect 9 0 2 0;
+#X connect 11 0 16 0;
+#X connect 16 0 10 0;
+#X connect 16 1 15 0;
diff --git a/username0x2d0x3euid.pd b/username0x2d0x3euid.pd
new file mode 100644
index 0000000..ecafa5c
--- /dev/null
+++ b/username0x2d0x3euid.pd
@@ -0,0 +1,31 @@
+#N canvas 496 159 353 422 10;
+#X obj 19 213 passwd;
+#X obj 18 12 inlet;
+#X obj 61 12 inlet;
+#X obj 18 322 outlet;
+#X obj 108 31 loadbang;
+#X obj 56 59 purepd/any_argument \$1;
+#X obj 57 93 route float;
+#X obj 129 114 passwd;
+#X obj 226 323 outlet;
+#X obj 129 135 list;
+#X obj 129 155 list split 3;
+#X obj 129 176 list split 2;
+#X obj 18 241 list;
+#X obj 18 261 list split 3;
+#X obj 18 282 list split 2;
+#X connect 0 0 12 0;
+#X connect 0 1 8 0;
+#X connect 1 0 0 0;
+#X connect 2 0 5 0;
+#X connect 4 0 5 0;
+#X connect 5 0 6 0;
+#X connect 6 0 0 1;
+#X connect 6 1 7 0;
+#X connect 7 0 9 0;
+#X connect 9 0 10 0;
+#X connect 10 0 11 0;
+#X connect 11 1 0 1;
+#X connect 12 0 13 0;
+#X connect 13 0 14 0;
+#X connect 14 1 3 0;