unsigned int main(register unsigned int argc, char* argv[]) { unsigned int fail = 0; /* success and golf are scored in the same way */ register unsigned int pos = 0; register unsigned int alloc_size; char ch[7]; char* edit_buffer; char* temp_buffer; t_getstate(&original); n_state = t_initstate(&original); t_setstate(&n_state); alloc_size = read_file(&edit_buffer, &fail); if (!fail) { temp_buffer = malloc(alloc_size); } while(!fail) { t_read(ch, 7); /* commands */ if (ch[0] == 27 && ch[1] == 'j' && ch[2] == 0) { /* alt+j - move backwards */ if(pos > 0) { pos -= 1; } } else if (ch[0] == 27 && ch[1] == 'k' && ch[2] == 0) { /* alt+k - move forwards */ if (pos < strlen(edit_buffer)) { pos += 1; } } else if (ch[0] == 27 && ch[1] == 'd' && ch[2] == 0) { /* alt+d - save file */ fputs(edit_buffer, stdout); } else if (ch[0] == 27 && ch[1] == 'f' && ch[2] == 0) { /* alt+f - quit program. Note: Don't hit this by accident. */ break; } else if (ch[0] == 127 && ch[1] == 0 && ch[2] == 0) { /* backspace - delete previous character */ if (pos > 0) { alloc_size = remove_char(pos, &edit_buffer, &temp_buffer, alloc_size, &fail); pos--; } } else if(ch[0] != 0 && ch[1] == 0 && ch[2] == 0) { /* add any other character pressed */ alloc_size = add_char(ch[0], pos, &edit_buffer, &temp_buffer, alloc_size, &fail); pos++; } } if (alloc_size > 0 && !fail) { free(edit_buffer); free(temp_buffer); } t_setstate(&original); fflush(stdout); return fail; };
/* **************************************************************** * Encerra a conexão * **************************************************************** */ int tcp_close (int fd) { if (t_getstate (fd) == T_DATAXFER) { if (t_sndrel (fd) < 0) return (-1); if (t_rcvrel (fd) < 0) return (-1); } return (t_close (fd)); } /* end tcp_close */
/*ARGSUSED*/ int main(int argc, char *argv[]) { register SVCXPRT *transp; load_libzfs(); /* * If stdin looks like a TLI endpoint, we assume * that we were started by a port monitor. If * t_getstate fails with TBADF, this is not a * TLI endpoint. */ if (t_getstate(0) != -1 || t_errno != TBADF) { char *netid; struct netconfig *nconf = NULL; openlog("rquotad", LOG_PID, LOG_DAEMON); if ((netid = getenv("NLSPROVIDER")) == NULL) { struct t_info tinfo; if (t_sync(0) == -1) { syslog(LOG_ERR, "could not do t_sync"); zexit(1); } if (t_getinfo(0, &tinfo) == -1) { syslog(LOG_ERR, "t_getinfo failed"); zexit(1); } if (tinfo.servtype == T_CLTS) { if (tinfo.addr == INET_ADDRSTRLEN) netid = "udp"; else netid = "udp6"; } else { syslog(LOG_ERR, "wrong transport"); zexit(1); } } if ((nconf = getnetconfigent(netid)) == NULL) { syslog(LOG_ERR, "cannot get transport info"); } if ((transp = svc_tli_create(0, nconf, NULL, 0, 0)) == NULL) { syslog(LOG_ERR, "cannot create server handle"); zexit(1); } if (nconf) freenetconfigent(nconf); if (!svc_reg(transp, RQUOTAPROG, RQUOTAVERS, dispatch, 0)) { syslog(LOG_ERR, "unable to register (RQUOTAPROG, RQUOTAVERS)."); zexit(1); } (void) sigset(SIGALRM, (void(*)(int)) closedown); (void) alarm(RPCSVC_CLOSEDOWN); svc_run(); zexit(1); /* NOTREACHED */ } /* * Started from a shell - fork the daemon. */ switch (fork()) { case 0: /* child */ break; case -1: perror("rquotad: can't fork"); zexit(1); default: /* parent */ zexit(0); } /* * Close existing file descriptors, open "/dev/null" as * standard input, output, and error, and detach from * controlling terminal. */ closefrom(0); (void) open("/dev/null", O_RDONLY); (void) open("/dev/null", O_WRONLY); (void) dup(1); (void) setsid(); openlog("rquotad", LOG_PID, LOG_DAEMON); /* * Create datagram service */ if (svc_create(dispatch, RQUOTAPROG, RQUOTAVERS, "datagram_v") == 0) { syslog(LOG_ERR, "couldn't register datagram_v service"); zexit(1); } /* * Start serving */ svc_run(); syslog(LOG_ERR, "Error: svc_run shouldn't have returned"); return (1); }
/* * Bind a fd to a privileged IP port. * This is slightly different from the code in netdir_options * because it has a different interface - main thing is that it * needs to know its own address. We also wanted to set the qlen. * t_getname() can be used for those purposes and perhaps job can be done. */ int __rpc_bindresvport_ipv6(int fd, struct sockaddr *sin, int *portp, int qlen, char *fmly) { int res; static in_port_t port, *sinport; struct sockaddr_in6 myaddr; int i; struct t_bind tbindstr, *tres; struct t_info tinfo; extern mutex_t portnum_lock; /* VARIABLES PROTECTED BY portnum_lock: port */ #define STARTPORT 600 #define ENDPORT (IPPORT_RESERVED - 1) #define NPORTS (ENDPORT - STARTPORT + 1) if (sin == 0 && fmly == 0) { errno = EINVAL; return (-1); } if (geteuid()) { errno = EACCES; return (-1); } if ((i = t_getstate(fd)) != T_UNBND) { if (t_errno == TBADF) errno = EBADF; if (i != -1) errno = EISCONN; return (-1); } if (sin == 0) { sin = (struct sockaddr *)&myaddr; get_myaddress_ipv6(fmly, sin); } if (sin->sa_family == AF_INET) { /* LINTED pointer cast */ sinport = &((struct sockaddr_in *)sin)->sin_port; } else if (sin->sa_family == AF_INET6) { /* LINTED pointer cast */ sinport = &((struct sockaddr_in6 *)sin)->sin6_port; } else { errno = EPFNOSUPPORT; return (-1); } /* Transform sockaddr to netbuf */ if (t_getinfo(fd, &tinfo) == -1) { return (-1); } /* LINTED pointer cast */ tres = (struct t_bind *)t_alloc(fd, T_BIND, T_ADDR); if (tres == NULL) return (-1); tbindstr.qlen = qlen; tbindstr.addr.buf = (char *)sin; tbindstr.addr.len = tbindstr.addr.maxlen = __rpc_get_a_size(tinfo.addr); /* LINTED pointer cast */ sin = (struct sockaddr *)tbindstr.addr.buf; res = -1; (void) mutex_lock(&portnum_lock); if (port == 0) port = (getpid() % NPORTS) + STARTPORT; for (i = 0; i < NPORTS; i++) { *sinport = htons(port++); if (port > ENDPORT) port = STARTPORT; res = t_bind(fd, &tbindstr, tres); if (res == 0) { if ((tbindstr.addr.len == tres->addr.len) && (memcmp(tbindstr.addr.buf, tres->addr.buf, (int)tres->addr.len) == 0)) break; (void) t_unbind(fd); res = -1; } else if (t_errno != TSYSERR || errno != EADDRINUSE) break; } (void) mutex_unlock(&portnum_lock); if ((portp != NULL) && (res == 0)) *portp = *sinport; (void) t_free((char *)tres, T_BIND); return (res); }
int main(int argc, char *argv[]) { pid_t pid; int c; char *progname = argv[0]; int connmaxrec = RPC_MAXDATASIZE; while ((c = getopt(argc, argv, "d")) != -1) switch ((char)c) { case 'd': debug++; break; default: (void) fprintf(stderr, "usage: %s [-d]\n", progname); exit(EXIT_FAILURE); } /* * Set non-blocking mode and maximum record size for * connection oriented RPC transports. */ if (!rpc_control(RPC_SVC_CONNMAXREC_SET, &connmaxrec)) { msgout("unable to set maximum RPC record size"); } /* * If stdin looks like a TLI endpoint, we assume * that we were started by a port monitor. If * t_getstate fails with TBADF, this is not a * TLI endpoint. */ if (t_getstate(0) != -1 || t_errno != TBADF) { char *netid; struct netconfig *nconf = NULL; SVCXPRT *transp; int pmclose; if ((netid = getenv("NLSPROVIDER")) == NULL) { if (debug) msgout("cannot get transport name"); } else if ((nconf = getnetconfigent(netid)) == NULL) { if (debug) msgout("cannot get transport info"); } pmclose = (t_getstate(0) != T_DATAXFER); if ((transp = svc_tli_create(0, nconf, NULL, 0, 0)) == NULL) { msgout("cannot create server handle"); exit(EXIT_FAILURE); } if (nconf) freenetconfigent(nconf); if (!svc_reg(transp, BOOTPARAMPROG, BOOTPARAMVERS, bootparamprog_1, 0)) { msgout("unable to register (BOOTPARAMPROG, " "BOOTPARAMVERS)."); exit(EXIT_FAILURE); } if (pmclose) { (void) signal(SIGALRM, closedown); (void) alarm(_RPCSVC_CLOSEDOWN); } svc_run(); exit(EXIT_FAILURE); /* NOTREACHED */ } /* * run this process in the background only if it was started from * a shell and the debug flag was not given. */ if (!server_child && !debug) { pid = fork(); if (pid < 0) { perror("cannot fork"); exit(EXIT_FAILURE); } if (pid) exit(EXIT_SUCCESS); closefrom(0); (void) setsid(); } /* * messges go to syslog if the program was started by * another server, or if it was run from the command line without * the debug flag. */ if (server_child || !debug) openlog("bootparam_prot", LOG_PID, LOG_DAEMON); if (debug) { if (debug == 1) msgout("in debug mode."); else msgout("in debug mode (level %d).", debug); } if (!svc_create(bootparamprog_1, BOOTPARAMPROG, BOOTPARAMVERS, "netpath")) { msgout("unable to create (BOOTPARAMPROG, BOOTPARAMVERS) " "for netpath."); exit(EXIT_FAILURE); } svc_run(); msgout("svc_run returned"); return (EXIT_FAILURE); }
void i_setup(void){ t_getstate(&orig); nstate = t_initstate(&orig); t_setstate(&nstate); }
int main(int argc, char *argv[]) { pid_t pid; int i; int connmaxrec = RPC_MAXDATASIZE; /* * Set non-blocking mode and maximum record size for * connection oriented RPC transports. */ if (!rpc_control(RPC_SVC_CONNMAXREC_SET, &connmaxrec)) { msgout("unable to set maximum RPC record size"); } /* * If stdin looks like a TLI endpoint, we assume * that we were started by a port monitor. If * t_getstate fails with TBADF, this is not a * TLI endpoint. */ if (t_getstate(0) != -1 || t_errno != TBADF) { char *netid; struct netconfig *nconf = NULL; SVCXPRT *transp; int pmclose; extern char *getenv(); _rpcpmstart = 1; openlog("rusers", LOG_PID, LOG_DAEMON); if ((netid = getenv("NLSPROVIDER")) == NULL) { #ifdef DEBUG msgout("cannot get transport name"); #endif } else if ((nconf = getnetconfigent(netid)) == NULL) { #ifdef DEBUG msgout("cannot get transport info"); #endif } if ((transp = svc_tli_create(0, nconf, NULL, 0, 0)) == NULL) { msgout("cannot create server handle"); exit(1); } if (nconf) freenetconfigent(nconf); if (!svc_reg(transp, RUSERSPROG, RUSERSVERS_3, rusers_service, 0)) { msgout("unable to register (RUSERSPROG, RUSERSVERS_3)."); exit(1); } if (!svc_reg(transp, RUSERSPROG, RUSERSVERS_IDLE, rusers_service, 0)) { msgout("unable to register (RUSERSPROG, RUSERSVERS_IDLE)."); exit(1); } (void) signal(SIGALRM, closedown); (void) alarm(_RPCSVC_CLOSEDOWN); svc_run(); msgout("svc_run returned"); exit(1); /* NOTREACHED */ } #ifndef RPC_SVC_FG pid = fork(); if (pid < 0) { perror("rpc.rusersd: cannot fork"); exit(1); } if (pid) exit(0); for (i = 0; i < 20; i++) (void) close(i); setsid(); openlog("rusers", LOG_PID, LOG_DAEMON); #endif if (!svc_create(rusers_service, RUSERSPROG, RUSERSVERS_3, "netpath")) { msgout("unable to create (RUSERSPROG, RUSERSVERS_3) for netpath"); exit(1); } if (!svc_create(rusers_service, RUSERSPROG, RUSERSVERS_IDLE, "netpath")) { msgout( "unable to create (RUSERSPROG, RUSERSVERS_IDLE) for netpath"); exit(1); } svc_run(); msgout("svc_run returned"); return (1); }