Changeset de3f641


Ignore:
Timestamp:
Sep 28, 2009, 3:19:50 PM (11 years ago)
Author:
Karl Ramm <kcr@1ts.org>
Branches:
master, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
39cff48
Parents:
bb79a52
git-author:
Karl Ramm <kcr@1ts.org> (09/26/09 12:25:28)
git-committer:
Karl Ramm <kcr@1ts.org> (09/28/09 15:19:50)
Message:
Perl callout for zsig computation + move default to perl

Barnowl::default_zephyr_signature works out what your zsig
should be.

New owl variable zsigfunc, which contains a perl expression
that is evaluated for the zsig.  Defaults to the above.

This is much more pleasant code in perl than in C.
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • perl/lib/BarnOwl.pm

    r7589f0a rde3f641  
    427427}
    428428
     429=head3 default_zephyr_signature
     430
     431Compute the default zephyr signature.
     432
     433=cut
     434
     435sub default_zephyr_signature
     436{
     437  if (my $zsig = getvar('zsig')) {
     438    return $zsig;
     439  }
     440  if (my $zsigproc = getvar('zsigproc')) {
     441    return `$zsigproc`;
     442  }
     443  my $zwrite_signature = get_zephyr_variable('zwrite-signature');
     444  if (defined($zwrite_signature)) {
     445    return $zwrite_signature;
     446  }
     447  my $name = ((getpwuid($<))[6]);
     448  $name =~ s/,.*//;
     449  return $name;
     450}
     451
    429452# Stub for owl::startup / BarnOwl::startup, so it isn't bound to the
    430453# startup command. This may be redefined in a user's configfile.
  • variable.c

    r8bce750 rde3f641  
    208208         "principal. Note that customizing the sender name will\n"
    209209         "cause your zephyrs to be sent unauthenticated."),
     210
     211  OWLVAR_STRING( "zsigfunc" /* %OwlVarStub */, "BarnOwl::default_zephyr_signature()",
     212                 "zsig perl function",
     213                 "Called every time you start a zephyrgram without an\n"
     214                 "explicit zsig.  The default setting implements the policy\n"
     215                 "descripted in the documentation for the 'zsig' variable.\n"),
    210216
    211217  OWLVAR_STRING( "zsig" /* %OwlVarStub */, "",
  • zwrite.c

    r24ccc01 rde3f641  
    154154void owl_zwrite_populate_zsig(owl_zwrite *z)
    155155{
    156   const char *zsigproc, *zsigowlvar, *zsigzvar;
    157   char *ptr;
    158   struct passwd *pw;
    159 
    160156  /* get a zsig, if not given */
    161   if (z->zsig==NULL) {
    162     zsigproc = owl_global_get_zsigproc(&g);
    163     zsigowlvar = owl_global_get_zsig(&g);
    164     zsigzvar = owl_zephyr_get_variable("zwrite-signature");
    165 
    166     if (zsigowlvar && *zsigowlvar) {
    167       z->zsig=owl_validate_utf8(zsigowlvar);
    168     } else if (zsigproc && *zsigproc) {
    169       FILE *file;
    170       char buff[LINE], *openline;
    171      
    172       /* simple hack for now to nuke stderr */
    173 #if OWL_STDERR_REDIR
    174       openline = owl_strdup(zsigproc);
    175 #else
    176       openline = owl_sprintf("%s 2> /dev/null", zsigproc);
    177 #endif
    178       file=popen(openline, "r");
    179       owl_free(openline);
    180       if (!file) {
    181         if (zsigzvar && *zsigzvar) {
    182           z->zsig=owl_validate_utf8(zsigzvar);
    183         }
    184       } else {
    185         z->zsig=owl_malloc(LINE*5);
    186         strcpy(z->zsig, "");
    187         while (fgets(buff, LINE, file)) { /* wrong sizing */
    188           strcat(z->zsig, buff);
    189         }
    190         pclose(file);
    191         if (z->zsig[0] != '\0' && z->zsig[strlen(z->zsig) - 1] == '\n') {
    192           z->zsig[strlen(z->zsig)-1]='\0';
    193         }
    194       }
    195     } else if (zsigzvar) {
    196       z->zsig=owl_validate_utf8(zsigzvar);
    197     } else if (((pw=getpwuid(getuid()))!=NULL) && (pw->pw_gecos)) {
    198       z->zsig=owl_validate_utf8(pw->pw_gecos);
    199       ptr=strchr(z->zsig, ',');
    200       if (ptr) {
    201         ptr[0]='\0';
    202       }
    203     }
    204   }
     157  if (z->zsig != NULL)
     158    return;
     159
     160  z->zsig = owl_perlconfig_execute(owl_global_get_zsigfunc(&g));
    205161}
    206162
Note: See TracChangeset for help on using the changeset viewer.