Ejemplo n.º 1
0
Code_t
SendKerberosData(int fd,	/* file descriptor to write onto */
		 KTEXT ticket,	/* where to put ticket (return) */
		 char *service,	/* service name, foreign host */
		 char *host)

{
    int rem;
    char p[32];
    size_t written;
    size_t size_to_write;

    rem = krb_mk_req(ticket, service, host, (char *)ZGetRealm(), (u_long) 0);
    if (rem != KSUCCESS)
	return rem + krb_err_base;

    (void) sprintf(p,"%d ",ticket->length);
    size_to_write = strlen (p);
    if ((written = write(fd, p, size_to_write)) != size_to_write)
	return ((ssize_t)written < 0) ? errno : ZSRV_PKSHORT;
    if ((written = write(fd, ticket->dat, ticket->length))
	!= ticket->length)
	return ((ssize_t)written < 0) ? errno : ZSRV_PKSHORT;

    return 0;
}
Ejemplo n.º 2
0
const char *owl_zephyr_get_realm(void)
{
#ifdef HAVE_LIBZEPHYR
  if (owl_global_is_havezephyr(&g))
    return(ZGetRealm());
#endif
  return "";
}
Ejemplo n.º 3
0
char *owl_zephyr_get_realm()
{
#ifdef HAVE_LIBZEPHYR
  return(ZGetRealm());
#else
  return("");
#endif
}
Ejemplo n.º 4
0
int owl_zephyr_loadloginsubs(char *filename)
{
#ifdef HAVE_LIBZEPHYR
  FILE *file;
  ZSubscription_t *subs;
  int numSubs = 100;
  char subsfile[1024], buffer[1024];
  int count, ret;
  struct stat statbuff;

  subs = owl_malloc(numSubs * sizeof(ZSubscription_t));

  if (filename==NULL) {
    sprintf(subsfile, "%s/%s", owl_global_get_homedir(&g), ".anyone");
  } else {
    strcpy(subsfile, filename);
  }
  
  ret=stat(subsfile, &statbuff);
  if (ret) return(0);

  ret=0;

  ZResetAuthentication();
  count=0;
  file=fopen(subsfile, "r");
  if (file) {
    while ( fgets(buffer, 1024, file)!=NULL ) {
      if (buffer[0]=='#' || buffer[0]=='\n' || buffer[0]=='\n') continue;
      
      if (count == numSubs) {
        numSubs *= 2;
        subs = owl_realloc(subs, numSubs * sizeof(ZSubscription_t));
      }

      buffer[strlen(buffer)-1]='\0';
      subs[count].zsub_class=owl_strdup("login");
      subs[count].zsub_recipient=owl_strdup("*");
      if (strchr(buffer, '@')) {
        subs[count].zsub_classinst=owl_strdup(buffer);
      } else {
        subs[count].zsub_classinst=owl_sprintf("%s@%s", buffer, ZGetRealm());
      }

      count++;
    }
    fclose(file);
  } else {
    count=0;
    ret=-1;
  }

  ret = owl_zephyr_loadsubs_helper(subs, count);
  return(ret);
#else
  return(0);
#endif
}
Ejemplo n.º 5
0
char *
decode_notice(ZNotice_t *notice,
	      char *hostname)
{
    char *temp;
    string when, notyear, year, date_string, time_string;

    /*
     * Convert useful notice fields to ascii and store away in
     * description language variables for later use by the
     * the user's program:
     */
    var_set_variable("zephyr_version", notice->z_version);
    var_set_variable("class", notice->z_class);
    var_set_variable("instance", notice->z_class_inst);
    var_set_variable("opcode", notice->z_opcode);
    var_set_variable("default", notice->z_default_format);
    var_set_variable("notice_charset", (char *)ZCharsetToString(notice->z_charset)); /*XXX const*/
    var_set_variable("recipient",
		     (notice->z_recipient[0] ? notice->z_recipient : "*"));
    var_set_variable("fullsender", notice->z_sender);
    var_set_variable_to_number("port", (int)ntohs(notice->z_port));
    var_set_variable_then_free_value("kind", z_kind_to_ascii(notice->z_kind));
    var_set_variable_then_free_value("auth", z_auth_to_ascii(notice->z_auth));

#ifdef CMU_ZWGCPLUS
    if ((temp=getSelectedText()) != 0)
	var_set_variable("selection", temp);
    
    var_set_variable("delete_window", "none");
    var_set_variable("event_time", "none");
    var_set_variable("event_name", "event");
#endif
    /*
     * Set $sender to the name of the notice sender except first strip off the
     * realm name if it is the local realm:
     */
    if ( (temp=strchr(notice->z_sender,'@')) && string_Eq(temp+1, ZGetRealm()) )
      var_set_variable_then_free_value("sender",
				string_CreateFromData(notice->z_sender,
						      temp-notice->z_sender));
    else
      var_set_variable("sender", notice->z_sender);
#ifdef CMU_ZWGCPLUS
    if (get_full_names) {
      struct passwd *pwnam = getpwnam(var_get_variable("sender"));
      if (pwnam) {
        temp = string_Copy(pwnam->pw_gecos);
        var_set_variable_then_free_value("sendername", temp);
      } else {
        var_set_variable("sendername", "unknown");
      }
    }
#endif
    
    /*
     * Convert time & date notice was sent to ascii.  The $time
     * has the format "01:03:52" while $date has the format
     * "Sun Sep 16 1973".
     */
    {
      /* the fields of struct timeval might not be the right type to pass
	 to ctime, so use a temporary */
      time_t sec = notice->z_time.tv_sec;
      when = ctime(&sec);
    }
    time_string = string_CreateFromData(when+11,8);
    var_set_variable_then_free_value("time", time_string);
    date_string = string_Concat(notyear=string_CreateFromData(when,11),
				year=string_CreateFromData(when+20,4));
    var_set_variable_then_free_value("date", date_string);
    free(notyear);
    free(year);

    /*
     * Convert host notice sent from to ascii:
     */
    var_set_variable("fromhost", hostname ? hostname :
		     inet_ntoa(notice->z_sender_addr));

    /*
     * Set $message to the message field of the notice with nulls changed
     * to newlines:
     */
    var_set_variable_then_free_value("message",
		     convert_nulls_to_newlines(notice->z_message,
					       notice->z_message_len));

    /*
     * Decide if its a control notice.  If so, return the notice's
     * opcode.  Otherwise, return NULL:
     */
    if ((strcasecmp(notice->z_class, WG_CTL_CLASS)==0) && /* <<<>>> */
	(strcasecmp(notice->z_class_inst, WG_CTL_USER)==0))
      return(notice->z_opcode);
    return(0);
}
Ejemplo n.º 6
0
int
main(int argc, char *argv[])
{
	register char *cp;
	char *realm;
	ZSubscription_t subs[SUBSATONCE];
	ZLocations_t locations;
	FILE *fp = NULL;
	struct passwd *pwd;
	char anyonename[BUFSIZ],name[BUFSIZ],cleanname[BUFSIZ],*envptr;
	char *comment_ptr;
	int onoff = ON,quiet = 0,justlist = 0,useronly = 0, filenamed = 0;
	int retval,arg,ind,one,numlocs,i;
	int wgport = 0;

	if ((retval = ZInitialize()) != ZERR_NONE) {
		com_err(argv[0],retval,"initializing");
		exit (1);
	}

	for (arg=1;arg<argc;arg++) {
		if (!strcmp(argv[arg],"on")) {
			onoff = ON;
			continue;
		}
		if (!strcmp(argv[arg],"off")) {
			onoff = OFF;
			continue;
		} 
		if (argv[arg][0] == '-') {
			char opt = argv[arg][1];
			if (opt == 0 || argv[arg][2] != 0)
				goto usage;
			switch (argv[arg][1]) {
			case 'q':
				quiet = 1;
				break;
			case 'l':
				justlist = 1;
				break;
			case 'f':
				if (arg == argc-1) {
					fprintf(stderr,"No file name specified\n");
					goto usage;
				}
				(void) strcpy(anyonename,argv[++arg]);
				filenamed = 1;
				break;
			case 'u':
				if (arg == argc-1) {
					fprintf(stderr,"No username specified\n");
					goto usage;
				}
				(void) strcpy(cleanname,argv[++arg]);
				useronly = 1;
				break;
			default:
				goto usage;
			}
			continue;
		}
	    usage:
		fprintf(stderr,"Usage: %s [on|off] [-q | -l] [-f file | -u username]\n", argv[0]);
		exit (1);
	}

	if (quiet && justlist) {
		fprintf(stderr,"-q and -l cannot both be used\n");
		goto usage;
	} 
	if (useronly && filenamed) {
		fprintf(stderr,"-u and -f cannot both be used\n");
		goto usage;
	} 
	if (!justlist)
		if ((wgport = ZGetWGPort()) == -1) {
			com_err(argv[0],errno,"while getting WindowGram port");
			exit(1);
		}
	
	if (!useronly) {
		/* If no filename specified, get the default */
		if (!filenamed) {
			envptr = getenv("HOME");
			if (envptr)
			    (void) strcpy(anyonename,envptr);
			else {
				if (!(pwd = getpwuid((int) getuid()))) {
					fprintf(stderr,"You are not listed in the password file.\n");
					exit (1);
				}
				(void) strcpy(anyonename,pwd->pw_dir);
			}
			(void) strcat(anyonename,"/.anyone");
		}

		/* if the filename is "-", read stdin */
		if (strcmp(anyonename,"-") == 0) {
			fp = stdin;
		} else if (!(fp = fopen(anyonename,"r"))) {
			fprintf(stderr,"Can't open %s for input\n",anyonename);
			exit (1);
		}
	}

	ind = 0;
	
	for (;;) {
		if (!useronly) {
		    if (!fgets(cleanname,sizeof cleanname,fp))
			break;
		    if (cleanname[0] == '#' || cleanname[0] == '\0' ||
			cleanname[0] == '\n')
			continue;	/* ignore comment and empty lines */
		    comment_ptr = strchr(cleanname, '#');
		    if (comment_ptr)
			*comment_ptr = '\0'; /* Ignore from # onwards */
		    /* Get rid of old-style nol entries, just in case */
		    cp = cleanname + strlen(cleanname) - 1;
		    *cp = '\0';
		    while(*--cp == ' ')
			*cp = '\0';
		    if (*cleanname == '@' || !*cleanname)
			continue;
		} else if (ind)
		    break;		/* only do the one name */

		subs[ind].zsub_class = LOGIN_CLASS;
		(void) strcpy(name,cleanname);
		if (!strchr(name,'@')) {
			cp = name + strlen(name);
			*cp++ = '@';
			(void) strcpy(cp,ZGetRealm());
		}
		cp = strchr(name,'@');
		if (cp[0] && strcmp(cp+1,ZGetRealm())) {
		    realm = cp + 1;
		    *cp = '\0';
		    if ((subs[ind].zsub_classinst =
			 malloc((unsigned)(strlen(name) + strlen(realm) + 2)))
			== NULL)
		    {
			fprintf (stderr, "znol: out of memory");
			exit (1);
		    }
		    (void) sprintf(subs[ind].zsub_classinst, "%s@%s", name,
				   realm);
		    (void) strcpy(name, subs[ind].zsub_classinst);
		    if ((subs[ind].zsub_recipient =
			 malloc((unsigned)(strlen(realm)+2))) == NULL) {
			fprintf (stderr, "znol: out of memory");
			exit (1);
		    }
		    (void) sprintf(subs[ind++].zsub_recipient, "@%s", realm);
		} else {
		    if ((subs[ind].zsub_classinst =
			 malloc((unsigned)(strlen(name)+1))) == NULL)
		    {
			fprintf (stderr, "znol: out of memory");
			exit (1);
		    }
		    (void) strcpy(subs[ind].zsub_classinst, name);
		    subs[ind++].zsub_recipient = "";
		}

		if (!quiet && onoff == ON) {
			if ((retval = ZLocateUser(name,&numlocs,ZAUTH))
			    != ZERR_NONE) {
				com_err(argv[0],retval,"locating user");
				exit(1);
			}
			one = 1;
			if (numlocs) {
				for (i=0;i<numlocs;i++) {
					if ((retval =
					     ZGetLocations(&locations,&one))
					    != ZERR_NONE) {
						com_err(argv[0],retval,
							"getting location");
						continue;
					}
					if (one != 1) {
						printf("%s: internal failure while getting location\n",argv[0]);
						exit(1);
					}
					printf("%s: %s\t%s\t%s\n",cleanname,
					       locations.host,
					       locations.tty,
					       locations.time);
				}
			}
		}
		
		if (ind == SUBSATONCE) {
			if (!justlist)
				if ((retval = (onoff==ON)?
				     ZSubscribeToSansDefaults(subs,ind,
							      (u_short)wgport):
				     ZUnsubscribeTo(subs,ind,(u_short)wgport)) !=
				    ZERR_NONE) {
					com_err(argv[0],retval,(onoff==ON)?
						"subscribing":
						"unsubscribing");
					exit(1);
				} 
			for (ind=0;ind<SUBSATONCE;ind++)
			  {
			    if (subs[ind].zsub_recipient[0] != '\0')
			      free(subs[ind].zsub_recipient);
			    free(subs[ind].zsub_classinst);
			  }
			ind = 0;
		}
	}

	if (ind && !justlist)
		if ((retval = (onoff==ON)?
		     ZSubscribeToSansDefaults(subs,ind,(u_short)wgport):
		     ZUnsubscribeTo(subs,ind,(u_short)wgport)) !=
		    ZERR_NONE) {
			com_err(argv[0],retval,(onoff==ON)?
				"subscribing":
				"unsubscribing");
			exit(1);
		} 

	if (!useronly)
	    (void) fclose(fp);		/* file is open read-only,
					   ignore errs */
	exit(0);
}