/[mailutils]/mailutils/pop3d/popauth.c
ViewVC logotype

Diff of /mailutils/pop3d/popauth.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by gray, Thu Oct 3 14:34:29 2002 UTC revision 1.7 by polak, Mon Dec 23 22:01:35 2002 UTC
# Line 1  Line 1 
1  /* GNU mailutils - a suite of utilities for electronic mail  /* GNU Mailutils -- a suite of utilities for electronic mail
2     Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.     Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3    
4     This program is free software; you can redistribute it and/or modify     GNU Mailutils is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2, or (at your option)     the Free Software Foundation; either version 2, or (at your option)
7     any later version.     any later version.
8    
9     This program is distributed in the hope that it will be useful,     GNU Mailutils is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.     GNU General Public License for more details.
13    
14     You should have received a copy of the GNU General Public License     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software     along with GNU Mailutils; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
17    
18  #include "pop3d.h"  #include "pop3d.h"
# Line 52  int (*ftab[]) __P((struct action_data *) Line 52  int (*ftab[]) __P((struct action_data *)
52  };  };
53    
54  const char *argp_program_version = "popauth (" PACKAGE_STRING ")";  const char *argp_program_version = "popauth (" PACKAGE_STRING ")";
55  static char doc[] = "GNU popauth -- manage pop3 authentcation database";  static char doc[] = N_("GNU popauth -- manage pop3 authentcation database");
56  static error_t popauth_parse_opt  __P((int key, char *arg,  static error_t popauth_parse_opt  __P((int key, char *arg,
57                                         struct argp_state *astate));                                         struct argp_state *astate));
58    
# Line 63  void (*argp_program_version_hook) __P((F Line 63  void (*argp_program_version_hook) __P((F
63    
64  static struct argp_option options[] =  static struct argp_option options[] =
65  {  {
66    { NULL, 0, NULL, 0, "Actions are:", 1 },    { NULL, 0, NULL, 0, N_("Actions are:"), 1 },
67    { "add", 'a', 0, 0, "Add user", 1 },    { "add", 'a', 0, 0, N_("Add user"), 1 },
68    { "modify", 'm', 0, 0, "Modify user's record (change password)", 1 },    { "modify", 'm', 0, 0, N_("Modify user's record (change password)"), 1 },
69    { "delete", 'd', 0, 0, "Delete user's record", 1 },    { "delete", 'd', 0, 0, N_("Delete user's record"), 1 },
70    { "list", 'l', 0, 0, "List the contents of DBM file", 1 },    { "list", 'l', 0, 0, N_("List the contents of DBM file"), 1 },
71    
72    { NULL, 0, NULL, 0,    { NULL, 0, NULL, 0,
73      "Default action is:\n"      N_("Default action is:\n"
74      "  For the file owner: --list\n"      "  For the file owner: --list\n"
75      "  For a user: --modify --username <username>\n", 2 },      "  For a user: --modify --username <username>\n"), 2 },
76        
77    { NULL, 0, NULL, 0, "Options are:", 3 },    { NULL, 0, NULL, 0, N_("Options are:"), 3 },
78    { "file", 'f', "FILE", 0, "Read input from FILE (default stdin)", 3 },    { "file", 'f', "FILE", 0, N_("Read input from FILE (default stdin)"), 3 },
79    { "output", 'o', "FILE", 0, "Direct output to file", 3 },    { "output", 'o', "FILE", 0, N_("Direct output to file"), 3 },
80    { "password", 'p', "STRING", 0, "Specify user's password", 3 },    { "password", 'p', "STRING", 0, N_("Specify user's password"), 3 },
81    { "user", 'u', "USERNAME", 0, "Specify user name", 3 },    { "user", 'u', "USERNAME", 0, N_("Specify user name"), 3 },
82    { NULL, }    { NULL, }
83  };  };
84    
# Line 164  int Line 164  int
164  main(int argc, char **argv)  main(int argc, char **argv)
165  {  {
166    struct action_data adata;    struct action_data adata;
167      
168      /* Native Language Support */
169      mu_init_nls ();
170    
171    mu_argp_parse (&argp, &argc, &argv, 0,    mu_argp_parse (&argp, &argc, &argv, 0,
172                   popauth_argp_capa, NULL, &adata);                   popauth_argp_capa, NULL, &adata);
173    
# Line 176  check_action (int action) Line 179  check_action (int action)
179  {  {
180    if (action != -1)    if (action != -1)
181      {      {
182        mu_error ("You may not specify more than one `-aldp' option");        mu_error (_("You may not specify more than one `-aldp' option"));
183        exit (1);        exit (1);
184      }      }
185  }  }
# Line 198  check_user_perm (int action, struct acti Line 201  check_user_perm (int action, struct acti
201            DBM_FILE db;            DBM_FILE db;
202            if (mu_dbm_open (ap->input_name, &db, MU_STREAM_CREAT, 0600))            if (mu_dbm_open (ap->input_name, &db, MU_STREAM_CREAT, 0600))
203              {              {
204                mu_error ("can't create %s: %s",                mu_error (_("can't create %s: %s"),
205                          ap->input_name, strerror (errno));                          ap->input_name, strerror (errno));
206                exit (1);                exit (1);
207              }              }
# Line 207  check_user_perm (int action, struct acti Line 210  check_user_perm (int action, struct acti
210          }          }
211        else        else
212          {          {
213            mu_error ("can't stat %s: %s", ap->input_name, strerror (errno));            mu_error (_("can't stat %s: %s"), ap->input_name, strerror (errno));
214            exit (1);            exit (1);
215          }          }
216      }      }
# Line 218  check_user_perm (int action, struct acti Line 221  check_user_perm (int action, struct acti
221    
222    if (ap->username)    if (ap->username)
223      {      {
224        mu_error ("Only the file owner can use --username");        mu_error (_("Only the file owner can use --username"));
225        exit (1);        exit (1);
226      }      }
227    
228    if (action != ACT_CHPASS)    if (action != ACT_CHPASS)
229      {      {
230        mu_error ("Operation not allowed");        mu_error (_("Operation not allowed"));
231        exit (1);        exit (1);
232      }      }
233    pw = getpwuid (uid);    pw = getpwuid (uid);
# Line 245  action_list (struct action_data *ap) Line 248  action_list (struct action_data *ap)
248    check_user_perm (ACT_LIST, ap);    check_user_perm (ACT_LIST, ap);
249    if (mu_dbm_open (ap->input_name, &db, MU_STREAM_READ, 0600))    if (mu_dbm_open (ap->input_name, &db, MU_STREAM_READ, 0600))
250      {      {
251        mu_error("can't open %s: %s", ap->input_name, strerror (errno));        mu_error (_("can't open %s: %s"), ap->input_name, strerror (errno));
252        return 1;        return 1;
253      }      }
254        
# Line 254  action_list (struct action_data *ap) Line 257  action_list (struct action_data *ap)
257        fp = fopen (ap->output_name, "w");        fp = fopen (ap->output_name, "w");
258        if (!fp)        if (!fp)
259          {          {
260            mu_error("can't create %s: %s", ap->output_name, strerror (errno));            mu_error (_("can't create %s: %s"), ap->output_name, strerror (errno));
261            return 1;            return 1;
262          }          }
263      }      }
# Line 269  action_list (struct action_data *ap) Line 272  action_list (struct action_data *ap)
272        MU_DATUM_SIZE (key) = strlen (ap->username);        MU_DATUM_SIZE (key) = strlen (ap->username);
273        if (mu_dbm_fetch (db, key, &contents))        if (mu_dbm_fetch (db, key, &contents))
274          {          {
275            mu_error ("no such user: %s", ap->username);            mu_error (_("no such user: %s"), ap->username);
276          }          }
277        else        else
278          fprintf (fp, "%.*s: %.*s\n",          fprintf (fp, "%.*s: %.*s\n",
# Line 316  action_create (struct action_data *ap) Line 319  action_create (struct action_data *ap)
319        fp = fopen (ap->input_name, "r");        fp = fopen (ap->input_name, "r");
320        if (!fp)        if (!fp)
321          {          {
322            mu_error("can't open %s: %s", ap->input_name, strerror (errno));            mu_error (_("can't open %s: %s"), ap->input_name, strerror (errno));
323            return 1;            return 1;
324          }          }
325      }      }
# Line 330  action_create (struct action_data *ap) Line 333  action_create (struct action_data *ap)
333      ap->output_name = APOP_PASSFILE;      ap->output_name = APOP_PASSFILE;
334    if (mu_dbm_open (ap->output_name, &db, MU_STREAM_CREAT, 0600))    if (mu_dbm_open (ap->output_name, &db, MU_STREAM_CREAT, 0600))
335      {      {
336        mu_error("can't create %s: %s", ap->output_name, strerror (errno));        mu_error (_("can't create %s: %s"), ap->output_name, strerror (errno));
337        return 1;        return 1;
338      }      }
339    
# Line 360  action_create (struct action_data *ap) Line 363  action_create (struct action_data *ap)
363                
364        if (argc != 3 || argv[1][0] != ':' || argv[1][1] != 0)        if (argc != 3 || argv[1][0] != ':' || argv[1][1] != 0)
365          {          {
366            mu_error ("%s:%d: malformed line", ap->input_name, line);            mu_error (_("%s:%d: malformed line"), ap->input_name, line);
367            argcv_free (argc, argv);            argcv_free (argc, argv);
368            continue;            continue;
369          }          }
# Line 373  action_create (struct action_data *ap) Line 376  action_create (struct action_data *ap)
376        MU_DATUM_SIZE (contents) = strlen (argv[2]);        MU_DATUM_SIZE (contents) = strlen (argv[2]);
377    
378        if (mu_dbm_insert (db, key, contents, 1))        if (mu_dbm_insert (db, key, contents, 1))
379          mu_error ("%s:%d: can't store datum", ap->input_name, line);          mu_error (_("%s:%d: can't store datum"), ap->input_name, line);
380    
381        argcv_free (argc, argv);        argcv_free (argc, argv);
382      }      }
# Line 390  open_io (int action, struct action_data Line 393  open_io (int action, struct action_data
393      *not_owner = rc;      *not_owner = rc;
394    if (mu_dbm_open (ap->input_name, db, MU_STREAM_RDWR, 0600))    if (mu_dbm_open (ap->input_name, db, MU_STREAM_RDWR, 0600))
395      {      {
396        mu_error("can't open %s: %s", ap->input_name, strerror (errno));        mu_error (_("can't open %s: %s"), ap->input_name, strerror (errno));
397        return 1;        return 1;
398      }      }
399    return 0;    return 0;
# Line 406  fill_pass (struct action_data *ap) Line 409  fill_pass (struct action_data *ap)
409        while (1) {        while (1) {
410          if (ap->passwd)          if (ap->passwd)
411            free (ap->passwd);            free (ap->passwd);
412          p = getpass ("Password:");          p = getpass (_("Password:"));
413          if (!p)          if (!p)
414            exit (1);            exit (1);
415          ap->passwd = strdup (p);          ap->passwd = strdup (p);
416          p = getpass ("Confirm :");          p = getpass (_("Confirm :"));
417          if (strcmp (ap->passwd, p) == 0)          if (strcmp (ap->passwd, p) == 0)
418            break;            break;
419          mu_error ("Passwords differ. Please retry.");          mu_error (_("Passwords differ. Please retry."));
420        }        }
421      }      }
422  }  }
# Line 428  action_add (struct action_data *ap) Line 431  action_add (struct action_data *ap)
431        
432    if (!ap->username)    if (!ap->username)
433      {      {
434        mu_error ("missing username to add");        mu_error (_("missing username to add"));
435        return 1;        return 1;
436      }      }
437    
# Line 446  action_add (struct action_data *ap) Line 449  action_add (struct action_data *ap)
449    
450    rc = mu_dbm_insert (db, key, contents, 1);    rc = mu_dbm_insert (db, key, contents, 1);
451    if (rc)    if (rc)
452      mu_error ("can't store datum");      mu_error (_("can't store datum"));
453    
454    mu_dbm_close (db);    mu_dbm_close (db);
455    return rc;    return rc;
# Line 461  action_delete (struct action_data *ap) Line 464  action_delete (struct action_data *ap)
464        
465    if (!ap->username)    if (!ap->username)
466      {      {
467        mu_error ("missing username to delete");        mu_error (_("missing username to delete"));
468        return 1;        return 1;
469      }      }
470    
# Line 473  action_delete (struct action_data *ap) Line 476  action_delete (struct action_data *ap)
476    
477    rc = mu_dbm_delete (db, key);    rc = mu_dbm_delete (db, key);
478    if (rc)    if (rc)
479      mu_error ("can't remove record for %s", ap->username);      mu_error (_("can't remove record for %s"), ap->username);
480    
481    mu_dbm_close (db);    mu_dbm_close (db);
482    return rc;    return rc;
# Line 493  action_chpass (struct action_data *ap) Line 496  action_chpass (struct action_data *ap)
496    
497    if (!ap->username)    if (!ap->username)
498      {      {
499        mu_error ("missing username");        mu_error (_("missing username"));
500        return 1;        return 1;
501      }      }
502    
# Line 504  action_chpass (struct action_data *ap) Line 507  action_chpass (struct action_data *ap)
507    MU_DATUM_SIZE (key) = strlen (ap->username);    MU_DATUM_SIZE (key) = strlen (ap->username);
508    if (mu_dbm_fetch (db, key, &contents))    if (mu_dbm_fetch (db, key, &contents))
509      {      {
510        mu_error ("no such user: %s", ap->username);        mu_error (_("no such user: %s"), ap->username);
511        return 1;        return 1;
512      }      }
513    
# Line 515  action_chpass (struct action_data *ap) Line 518  action_chpass (struct action_data *ap)
518        oldpass = xmalloc (MU_DATUM_SIZE (contents) + 1);        oldpass = xmalloc (MU_DATUM_SIZE (contents) + 1);
519        memcpy (oldpass, MU_DATUM_PTR (contents), MU_DATUM_SIZE (contents));        memcpy (oldpass, MU_DATUM_PTR (contents), MU_DATUM_SIZE (contents));
520        oldpass[MU_DATUM_SIZE (contents)] = 0;        oldpass[MU_DATUM_SIZE (contents)] = 0;
521        p = getpass ("Old Password:");        p = getpass (_("Old Password:"));
522        if (!p)        if (!p)
523          return 1;          return 1;
524        if (strcmp (oldpass, p))        if (strcmp (oldpass, p))
525          {          {
526            mu_error ("Sorry");            mu_error (_("Sorry"));
527            return 1;            return 1;
528          }          }
529      }      }
# Line 531  action_chpass (struct action_data *ap) Line 534  action_chpass (struct action_data *ap)
534    MU_DATUM_SIZE (contents) = strlen (ap->passwd);    MU_DATUM_SIZE (contents) = strlen (ap->passwd);
535    rc = mu_dbm_insert (db, key, contents, 1);    rc = mu_dbm_insert (db, key, contents, 1);
536    if (rc)    if (rc)
537      mu_error ("can't replace datum");      mu_error (_("can't replace datum"));
538    
539    mu_dbm_close (db);    mu_dbm_close (db);
540    return rc;    return rc;
# Line 550  popauth_version (FILE *stream, struct ar Line 553  popauth_version (FILE *stream, struct ar
553  # define FORMAT "Old DBM"    # define FORMAT "Old DBM"  
554  #endif  #endif
555    printf ("%s\n", argp_program_version);    printf ("%s\n", argp_program_version);
556    printf ("Database format: %s\n", FORMAT);    printf (_("Database format: %s\n"), FORMAT);
557    printf ("Database location: %s\n", APOP_PASSFILE);    printf (_("Database location: %s\n"), APOP_PASSFILE);
558    exit (EXIT_SUCCESS);    exit (EXIT_SUCCESS);
559  }  }

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26