aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans-Christoph Steiner <eighthave@users.sourceforge.net>2006-06-12 20:41:54 +0000
committerHans-Christoph Steiner <eighthave@users.sourceforge.net>2006-06-12 20:41:54 +0000
commit1b8c2838a308ac7536362a219f710c244fe529b9 (patch)
tree62435bd3147fc08974507d3f72f542050e6a4df2
parentdda26b130c1aa944bc042095677b2245c722e7ba (diff)
turned passwd.c into group.c; fixed error message wording; added group/gid abstractions
svn path=/trunk/externals/hcs/; revision=5202
-rw-r--r--gid0x2d0x3egroup_name-help.pd47
-rw-r--r--gid0x2d0x3egroup_name.c158
-rw-r--r--gid0x2d0x3egroup_name.pd18
-rw-r--r--group-help.pd43
-rw-r--r--group.c263
-rw-r--r--group_name0x2d0x3egid-help.pd34
-rw-r--r--group_name0x2d0x3egid.pd31
-rw-r--r--passwd.c9
8 files changed, 419 insertions, 184 deletions
diff --git a/gid0x2d0x3egroup_name-help.pd b/gid0x2d0x3egroup_name-help.pd
index ba9cdfa..b184606 100644
--- a/gid0x2d0x3egroup_name-help.pd
+++ b/gid0x2d0x3egroup_name-help.pd
@@ -1,20 +1,29 @@
-#N canvas 378 215 466 316 10;
-#X obj 94 157 gid->group_name;
-#X obj 98 60 hsl 128 15 0 127 0 0 empty empty empty -2 -6 0 8 -262144
--1 -1 500 1;
-#X floatatom 95 83 5 0 0 0 Group_ID - -;
-#X symbolatom 94 207 0 0 0 0 Group_Name - -;
-#X text 52 40 convert group GID number to group name symbol;
-#X obj 106 188 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
+#N canvas 185 212 485 324 10;
+#X msg 43 118 bang;
+#X obj 59 210 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
-1;
-#X text 68 255 outputs a blank symbol if no match;
-#X msg 194 138 10;
-#X msg 112 106 bang;
-#X text 209 158 <-- set by argument or cold inlet;
-#X text 148 105 output current;
-#X connect 0 0 3 0;
-#X connect 0 0 5 0;
-#X connect 1 0 2 0;
-#X connect 2 0 0 0;
-#X connect 7 0 0 1;
-#X connect 8 0 0 0;
+#X msg 300 129 bang;
+#X obj 184 216 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
+-1;
+#X text 187 238 ^-- bang if not found;
+#X text 12 14 convert a UID to a username;
+#X symbolatom 84 212 0 0 0 0 - - -;
+#X msg 172 132 1;
+#X symbolatom 301 212 0 0 0 0 - - -;
+#X obj 89 63 hsl 128 15 0 127 0 0 empty empty empty -2 -6 0 8 -262144
+-1 -1 0 1;
+#X floatatom 87 93 5 0 0 0 - - -;
+#X obj 85 160 gid->group_name;
+#X obj 417 193 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
+-1;
+#X obj 301 171 gid->group_name 0;
+#X connect 0 0 11 0;
+#X connect 2 0 13 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 13 0 8 0;
+#X connect 13 1 12 0;
diff --git a/gid0x2d0x3egroup_name.c b/gid0x2d0x3egroup_name.c
deleted file mode 100644
index 12ceae5..0000000
--- a/gid0x2d0x3egroup_name.c
+++ /dev/null
@@ -1,158 +0,0 @@
-/* --------------------------------------------------------------------------*/
-/* */
-/* converts a GID number to a group 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. */
-/* */
-/* --------------------------------------------------------------------------*/
-
-#include <m_pd.h>
-
-#ifdef _WIN32
-#define _WIN32_WINNT 0x0400
-#include <windows.h>
-#include <stdio.h>
-#include <lm.h>
-#else
-#include <stdlib.h>
-#include <grp.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 gid0x2d0x3egroup_name_instance_count;
-
-#define DEBUG(x)
-//#define DEBUG(x) x
-
-/*------------------------------------------------------------------------------
- * CLASS DEF
- */
-static t_class *gid0x2d0x3egroup_name_class;
-
-typedef struct _gid0x2d0x3egroup_name {
- t_object x_obj;
- t_float x_gid;
- t_outlet *x_data_outlet;
-// t_outlet *x_status_outlet;
-} t_gid0x2d0x3egroup_name;
-
-/*------------------------------------------------------------------------------
- * IMPLEMENTATION
- */
-
-
-static void gid0x2d0x3egroup_name_output(t_gid0x2d0x3egroup_name* x)
-{
- DEBUG(post("gid0x2d0x3egroup_name_output"););
- struct group *group_pointer;
-
-#ifdef _WIN32
- /* TODO: implement for Windows! */
-#else
- {
- group_pointer = getgrgid((gid_t)x->x_gid);
- if( group_pointer != NULL )
- outlet_symbol(x->x_data_outlet, gensym(group_pointer->gr_name));
- else /* output blank symbol if no match */
- outlet_symbol(x->x_data_outlet, &s_);
- }
-#endif /* _WIN32 */
-}
-
-
-static void gid0x2d0x3egroup_name_set(t_gid0x2d0x3egroup_name* x, t_float f)
-{
- DEBUG(post("gid0x2d0x3egroup_name_set"););
-
- x->x_gid = f;
-}
-
-
-static void gid0x2d0x3egroup_name_float(t_gid0x2d0x3egroup_name *x, t_float f)
-{
- gid0x2d0x3egroup_name_set(x,f);
- gid0x2d0x3egroup_name_output(x);
-}
-
-
-static void *gid0x2d0x3egroup_name_new(t_float f)
-{
- DEBUG(post("gid0x2d0x3egroup_name_new"););
-
- t_gid0x2d0x3egroup_name *x = (t_gid0x2d0x3egroup_name *)pd_new(gid0x2d0x3egroup_name_class);
-
- if(!gid0x2d0x3egroup_name_instance_count)
- {
- post("[gid->group_name] %s",version);
- post("\twritten by Hans-Christoph Steiner <hans@at.or.at>");
- post("\tcompiled on "__DATE__" at "__TIME__ " ");
- }
- gid0x2d0x3egroup_name_instance_count++;
-
-
- floatinlet_new(&x->x_obj, &x->x_gid);
- x->x_data_outlet = outlet_new(&x->x_obj, 0);
-// x->x_status_outlet = outlet_new(&x->x_obj, 0);
-
- gid0x2d0x3egroup_name_set(x,f);
-
- return (x);
-}
-
-
-void gid0x2d0x3egroup_name_free(void)
-{
-#ifdef _WIN32
-#else
- endgrent();
-#endif /* _WIN32 */
-}
-
-
-void gid0x2d0x3egroup_name_setup(void)
-{
- DEBUG(post("gid0x2d0x3egroup_name_setup"););
- gid0x2d0x3egroup_name_class = class_new(gensym("gid->group_name"),
- (t_newmethod)gid0x2d0x3egroup_name_new,
- 0,
- sizeof(t_gid0x2d0x3egroup_name),
- 0,
- A_DEFFLOAT,
- 0);
- /* add inlet datatype methods */
- class_addbang(gid0x2d0x3egroup_name_class,
- (t_method) gid0x2d0x3egroup_name_output);
- class_addfloat(gid0x2d0x3egroup_name_class,
- (t_method) gid0x2d0x3egroup_name_float);
-
- /* add inlet message methods */
- class_addmethod(gid0x2d0x3egroup_name_class,
- (t_method) gid0x2d0x3egroup_name_set,gensym("set"),
- A_DEFSYM, 0);
-}
-
diff --git a/gid0x2d0x3egroup_name.pd b/gid0x2d0x3egroup_name.pd
new file mode 100644
index 0000000..017f257
--- /dev/null
+++ b/gid0x2d0x3egroup_name.pd
@@ -0,0 +1,18 @@
+#N canvas 217 216 514 233 10;
+#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 obj 18 85 group;
+#X connect 0 0 8 0;
+#X connect 2 0 4 0;
+#X connect 3 0 4 0;
+#X connect 4 0 8 1;
+#X connect 6 0 7 0;
+#X connect 7 0 1 0;
+#X connect 8 0 6 0;
+#X connect 8 1 5 0;
diff --git a/group-help.pd b/group-help.pd
new file mode 100644
index 0000000..961486a
--- /dev/null
+++ b/group-help.pd
@@ -0,0 +1,43 @@
+#N canvas 296 212 557 427 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 112 86 bang;
+#X text 209 168 <-- set by argument or cold inlet;
+#X text 148 85 output current;
+#X symbolatom 14 365 0 0 0 3 group_name - -;
+#X symbolatom 43 331 0 0 0 3 password - -;
+#X floatatom 191 323 0 0 0 3 gid - -;
+#X msg 269 105 symbol trash;
+#X text 365 76 use a symbolic group name;
+#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 obj 94 167 group;
+#X obj 94 200 list;
+#X obj 14 299 unpack symbol symbol float;
+#X obj 94 220 list split 3;
+#X msg 271 83 symbol wheel;
+#X msg 194 148 20;
+#X obj 133 245 print group_members;
+#X text 37 20 fetch passwd data based on UID or group name;
+#X text 361 105 ignore bad group names;
+#X connect 0 0 1 0;
+#X connect 1 0 14 0;
+#X connect 3 0 14 0;
+#X connect 9 0 14 0;
+#X connect 11 0 14 0;
+#X connect 14 0 2 0;
+#X connect 14 0 15 0;
+#X connect 14 1 13 0;
+#X connect 15 0 17 0;
+#X connect 16 0 6 0;
+#X connect 16 1 7 0;
+#X connect 16 2 8 0;
+#X connect 17 0 16 0;
+#X connect 17 1 20 0;
+#X connect 18 0 14 0;
+#X connect 19 0 14 1;
diff --git a/group.c b/group.c
new file mode 100644
index 0000000..3d9bf17
--- /dev/null
+++ b/group.c
@@ -0,0 +1,263 @@
+/* --------------------------------------------------------------------------*/
+/* */
+/* converts a GID 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 <grp.h>
+#endif
+
+#include <string.h>
+
+static char *version = "$Revision: 1.1 $";
+
+t_int group_instance_count;
+
+#define DEBUG(x)
+//#define DEBUG(x) x
+
+/*------------------------------------------------------------------------------
+ * CLASS DEF
+ */
+static t_class *group_class;
+
+typedef struct _group {
+ t_object x_obj;
+ t_float x_gid;
+/* output */
+ t_atom *output; // holder for a list of atoms to be outputted
+ t_int output_count; // number of atoms in in x->output
+ t_outlet *x_data_outlet;
+ t_outlet *x_status_outlet;
+} t_group;
+
+/*------------------------------------------------------------------------------
+ * SUPPORT FUNCTIONS
+ */
+
+/* add one new atom to the list to be outputted */
+static void add_atom_to_output(t_group *x, t_atom *new_atom)
+{
+ t_atom *new_atom_list;
+
+ new_atom_list = (t_atom *)getbytes((x->output_count + 1) * sizeof(t_atom));
+ memcpy(new_atom_list, x->output, x->output_count * sizeof(t_atom));
+ freebytes(x->output, x->output_count * sizeof(t_atom));
+ x->output = new_atom_list;
+ memcpy(x->output + x->output_count, new_atom, sizeof(t_atom));
+ ++(x->output_count);
+}
+
+static void add_symbol_to_output(t_group *x, t_symbol *s)
+{
+ t_atom *temp_atom = getbytes(sizeof(t_atom));
+ SETSYMBOL(temp_atom, s);
+ add_atom_to_output(x,temp_atom);
+ freebytes(temp_atom,sizeof(t_atom));
+}
+
+static void add_float_to_output(t_group *x, t_float f)
+{
+ t_atom *temp_atom = getbytes(sizeof(t_atom));
+ SETFLOAT(temp_atom, f);
+ add_atom_to_output(x,temp_atom);
+ freebytes(temp_atom,sizeof(t_atom));
+}
+
+static void reset_output(t_group *x)
+{
+ if(x->output)
+ {
+ freebytes(x->output, x->output_count * sizeof(t_atom));
+ x->output = NULL;
+ x->output_count = 0;
+ }
+}
+
+/*------------------------------------------------------------------------------
+ * IMPLEMENTATION
+ */
+
+static void group_output(t_group *x)
+{
+ DEBUG(post("group_output"););
+ struct group *group_pointer;
+ char **members;
+
+#ifdef _WIN32
+ /* TODO: implement for Windows! */
+#else
+ if( x->x_gid < 0 )
+ {
+ post("[group]: ignoring bad username or GID less than zero");
+ outlet_bang(x->x_status_outlet);
+ }
+ else
+ {
+ group_pointer = getgrgid((gid_t)x->x_gid);
+ if( group_pointer != NULL )
+ {
+ reset_output(x);
+ add_symbol_to_output(x, gensym(group_pointer->gr_passwd));
+ add_float_to_output(x, group_pointer->gr_gid);
+ members = group_pointer->gr_mem;
+ while(*members)
+ {
+ add_symbol_to_output(x, gensym( *(members) ));
+ members++;
+ }
+ outlet_anything(x->x_data_outlet, gensym(group_pointer->gr_name),
+ x->output_count, x->output);
+ }
+ else
+ {
+ outlet_bang(x->x_status_outlet);
+ }
+ }
+#endif /* _WIN32 */
+}
+
+
+static t_float get_gid_from_arguments(int argc, t_atom *argv)
+{
+ t_symbol *first_argument;
+ t_float gid = -1;
+ struct group *group_pointer;
+
+ if(argc == 0) return(0);
+
+ if(argc != 1)
+ post("[group]: 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 GID #
+ gid = atom_getfloatarg(0,argc,argv);
+ if( gid < 0 )
+ {
+ error("[group]: GID less than zero not allowed (%d)", gid);
+ return(-1);
+ }
+ }
+ else
+ { // single symbol arg means username
+ group_pointer = getgrnam(first_argument->s_name);
+ if( group_pointer != NULL )
+ return((t_float) group_pointer->gr_gid);
+ else
+ return(-1);
+ }
+ return(-1);
+}
+
+
+static void group_set(t_group *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_gid = get_gid_from_arguments(argc, argv);
+}
+
+
+static void group_float(t_group *x, t_float f)
+{
+ x->x_gid = f;
+ group_output(x);
+}
+
+static void group_symbol(t_group *x, t_symbol *s)
+{
+ t_atom argv[1];
+ SETSYMBOL(argv, s);
+ group_set(x, gensym("set"), 1, argv);
+ group_output(x);
+}
+
+
+static void *group_new(t_symbol *s, int argc, t_atom *argv)
+{
+ DEBUG(post("group_new"););
+
+ t_group *x = (t_group *)pd_new(group_class);
+
+ if(!group_instance_count)
+ {
+ post("[group] %s",version);
+ post("\twritten by Hans-Christoph Steiner <hans@at.or.at>");
+ post("\tcompiled on "__DATE__" at "__TIME__ " ");
+ }
+ group_instance_count++;
+
+ floatinlet_new(&x->x_obj, &x->x_gid);
+ x->x_data_outlet = outlet_new(&x->x_obj, 0);
+ x->x_status_outlet = outlet_new(&x->x_obj, 0);
+
+ group_set(x, gensym("set"), argc, argv);
+
+ return (x);
+}
+
+
+void group_free(void)
+{
+#ifdef _WIN32
+#else
+ endgrent();
+#endif /* _WIN32 */
+}
+
+
+void group_setup(void)
+{
+ DEBUG(post("group_setup"););
+ group_class = class_new(gensym("group"),
+ (t_newmethod)group_new,
+ 0,
+ sizeof(t_group),
+ 0,
+ A_GIMME,
+ 0);
+ /* add inlet datatype methods */
+ class_addbang(group_class, (t_method) group_output);
+ class_addfloat(group_class, (t_method) group_float);
+ class_addsymbol(group_class, (t_method) group_symbol);
+ /* add inlet message methods */
+ class_addmethod(group_class,
+ (t_method) group_set,
+ gensym("set"),
+ A_GIMME,
+ 0);
+}
+
+#endif /* NOT _WIN32 */
diff --git a/group_name0x2d0x3egid-help.pd b/group_name0x2d0x3egid-help.pd
new file mode 100644
index 0000000..72fdf7e
--- /dev/null
+++ b/group_name0x2d0x3egid-help.pd
@@ -0,0 +1,34 @@
+#N canvas 185 212 481 320 10;
+#X floatatom 56 240 5 0 0 0 - - -;
+#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 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 421 227 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
+-1;
+#X msg 57 49 symbol wheel;
+#X msg 76 81 symbol staff;
+#X text 12 14 convert a group name to a GID.;
+#X obj 272 201 group_name->gid staff;
+#X obj 56 190 group_name->gid;
+#X msg 361 166 symbol postfix;
+#X connect 1 0 15 0;
+#X connect 2 0 15 1;
+#X connect 4 0 15 0;
+#X connect 5 0 15 0;
+#X connect 7 0 14 0;
+#X connect 11 0 15 0;
+#X connect 12 0 15 0;
+#X connect 14 0 6 0;
+#X connect 14 1 10 0;
+#X connect 15 0 0 0;
+#X connect 15 0 3 0;
+#X connect 15 1 8 0;
+#X connect 16 0 14 1;
diff --git a/group_name0x2d0x3egid.pd b/group_name0x2d0x3egid.pd
new file mode 100644
index 0000000..25bc810
--- /dev/null
+++ b/group_name0x2d0x3egid.pd
@@ -0,0 +1,31 @@
+#N canvas 496 159 385 454 10;
+#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 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 19 213 group;
+#X obj 129 114 group;
+#X obj 18 282 list split 2;
+#X connect 0 0 12 0;
+#X connect 1 0 4 0;
+#X connect 3 0 4 0;
+#X connect 4 0 5 0;
+#X connect 5 0 12 1;
+#X connect 5 1 13 0;
+#X connect 7 0 8 0;
+#X connect 8 0 9 0;
+#X connect 9 1 12 1;
+#X connect 10 0 11 0;
+#X connect 11 0 14 0;
+#X connect 12 0 10 0;
+#X connect 12 1 6 0;
+#X connect 13 0 7 0;
+#X connect 14 1 2 0;
diff --git a/passwd.c b/passwd.c
index bb0a020..8289818 100644
--- a/passwd.c
+++ b/passwd.c
@@ -38,13 +38,8 @@
#endif
#include <string.h>
-/*
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/errno.h>
-*/
-static char *version = "$Revision: 1.1 $";
+static char *version = "$Revision: 1.2 $";
t_int passwd_instance_count;
@@ -78,7 +73,7 @@ static void passwd_output(t_passwd *x)
#else
if( x->x_uid < 0 )
{
- post("[passwd]: ignoring UID less than zero or bad username");
+ post("[passwd]: ignoring bad username or UID less than zero");
outlet_bang(x->x_status_outlet);
}
else