/* * Print out privileges for the specified user. * We only get here if the user is allowed to run something on this host. */ void display_privs(struct sudo_nss_list *snl, struct passwd *pw) { struct sudo_nss *nss; struct lbuf defs, privs; int count, olen; /* Reset group vector so group matching works correctly. */ reset_groups(pw); lbuf_init(&defs, output, 4, NULL, sudo_user.cols); lbuf_init(&privs, output, 4, NULL, sudo_user.cols); /* Display defaults from all sources. */ lbuf_append(&defs, "Matching Defaults entries for ", pw->pw_name, " on this host:\n", NULL); count = 0; tq_foreach_fwd(snl, nss) { count += nss->display_defaults(nss, pw, &defs); }
/* * Print out privileges for the specified user. * We only get here if the user is allowed to run something. */ void display_privs(struct sudo_nss_list *snl, struct passwd *pw) { struct sudo_nss *nss; struct lbuf defs, privs; struct stat sb; int cols, count, olen; debug_decl(display_privs, SUDO_DEBUG_NSS) cols = sudo_user.cols; if (fstat(STDOUT_FILENO, &sb) == 0 && S_ISFIFO(sb.st_mode)) cols = 0; lbuf_init(&defs, output, 4, NULL, cols); lbuf_init(&privs, output, 8, NULL, cols); /* Display defaults from all sources. */ lbuf_append(&defs, _("Matching Defaults entries for %s on %s:\n"), pw->pw_name, user_srunhost); count = 0; TAILQ_FOREACH(nss, snl, entries) { count += nss->display_defaults(nss, pw, &defs); }
/* * Receive command input from @fd into @inbuf. * Return 1 on receipt of input, zero on EOF, -1 on error. */ static int recv_input(int fd, struct ring *inbuf) { static struct lbuf cmdbuf; int n, i, ch; char *line; int res = 1; n = ring_from_file(inbuf, fd); if (n < 0) return -1; if (n == 0) { /* EOF on input */ if (lbuf_len(&cmdbuf)) { /* incomplete line */ ring_putc(inbuf, '\n'); n++; } /* * Can't put EOF cookie into INBUF here, it may not fit. * Leave it to caller. */ res = 0; } /* copy input to AUXFP etc. */ for (i = -n; i < 0; i++) { ch = ring_peek(inbuf, i); assert(ch != EOF); if (ch != '\r' && lbuf_putc(&cmdbuf, ch) > 0) { line = lbuf_line(&cmdbuf); save_input(line); lbuf_init(&cmdbuf); } if (auxfp) putc(ch, auxfp); } return res; }
/* * Give usage message and exit. * The actual usage strings are in sudo_usage.h for configure substitution. */ void usage(int fatal) { struct lbuf lbuf; char *uvec[6]; int i, ulen; /* * Use usage vectors appropriate to the progname. */ if (strcmp(getprogname(), "sudoedit") == 0) { uvec[0] = SUDO_USAGE5 + 3; uvec[1] = NULL; } else { uvec[0] = SUDO_USAGE1; uvec[1] = SUDO_USAGE2; uvec[2] = SUDO_USAGE3; uvec[3] = SUDO_USAGE4; uvec[4] = SUDO_USAGE5; uvec[5] = NULL; } /* * Print usage and wrap lines as needed, depending on the * tty width. */ ulen = (int)strlen(getprogname()) + 8; lbuf_init(&lbuf, fatal ? usage_err : usage_out, ulen, NULL, user_details.ts_cols); for (i = 0; uvec[i] != NULL; i++) { lbuf_append(&lbuf, "usage: %s%s", getprogname(), uvec[i]); lbuf_print(&lbuf); } lbuf_destroy(&lbuf); if (fatal) exit(1); }
/* * Receive and process server output from @sock. * Return number of characters received on success, -1 on error. */ static int recv_output(int sock) { /* * Read a chunk of server output and feed its characters into a * simple state machine. * Initial state is SCANNING_ID. * In state SCANNING_ID, buffer the character. If it's a space, * decode the id that has been buffered, and enter state BUFFERING * or COPYING depending on its value. * In state BUFFERING, buffer the character. If it's newline, * pass id and buffered text to servercmd(), then enter state * SCANNING_ID. * In state COPYING, pass the character to outch(). If it's * newline, enter state SCANNING_ID. */ static enum { SCANNING_ID, BUFFERING, COPYING } state = SCANNING_ID; static int id; static struct lbuf lbuf; char buf[4096]; ssize_t n; int i, ch, len; char *line; n = read(sock, buf, sizeof(buf)); if (n < 0) return -1; for (i = 0; i < n; i++) { ch = buf[i]; switch (state) { case SCANNING_ID: if (ch == '\n') { /* FIXME gripe unexpected! */ lbuf_init(&lbuf); break; } lbuf_putc(&lbuf, ch); if (ch != ' ') break; line = lbuf_line(&lbuf); id = parseid(line); lbuf_init(&lbuf); switch (id) { case C_PROMPT: case C_FLUSH: case C_EXECUTE: case C_EXIT: case C_FLASH: case C_INFORM: case C_PIPE: case C_REDIR: state = BUFFERING; break; default: /* unknown or unexpected id, treat like C_DATA */ case C_DATA: state = COPYING; break; } break; case BUFFERING: len = lbuf_putc(&lbuf, ch); if (len) { line = lbuf_line(&lbuf); servercmd(id, line, len); lbuf_init(&lbuf); state = SCANNING_ID; } break; case COPYING: outch(ch); if (ch == '\n') state = SCANNING_ID; } } return n; }
int main() { int i; #ifdef FPGA pll_init(); #else bt16_pll_init(); #endif delay(500000); uart_init((96000000/ 460800)); // pa8 puts(pubDate); puts("...fpga bt16 setup ok.......\n"); #ifdef FPGA spi_int(); #endif puts("-----1\n"); system_init(); puts("-----2\n"); timer0_start(); puts("-----3\n"); RF_init(); //----------debug HWI_Install(1, exception_isr, 3) ; //timer0_isr ENABLE_INT(); puts("-----4\n"); thread_init(os_create_thread, os_delete_thread); puts("-----5\n"); sys_timer_init(); puts("-----6\n"); ble_main(); btstack_main(); /* device_manager_init(); */ /*INTALL_HWI(BT_BLE_INT, le_hw_isr, 0); INTALL_HWI(18, le_test_uart_isr, 0);*/ lbuf_init(malloc_buf, sizeof(malloc_buf)*4); /* btstack_v21_main(); */ puts("------------4.0 start run loop-----------\n"); while(1) { int c; //asm("idle"); /*delay(100000);*/ for (i=0; i<PRIORITY_NUM; i++) { if (thread_fun[i]){ thread_fun[i](i); } } c = getchar(); switch(c) { case 'A': puts("user cmd : ADV\n"); ble_set_adv(); break; case 'S': puts("user cmd : SCAN\n"); ble_set_scan(); break; default: break; } /*run_loop_execute();*/ /*printf("k");*/ } return 0; }
static void help(void) { struct lbuf lbuf; int indent = 16; const char *pname = getprogname(); lbuf_init(&lbuf, usage_out, indent, NULL, user_details.ts_cols); if (strcmp(pname, "sudoedit") == 0) lbuf_append(&lbuf, _("%s - edit files as another user\n\n"), pname); else lbuf_append(&lbuf, _("%s - execute a command as another user\n\n"), pname); lbuf_print(&lbuf); usage(0); lbuf_append(&lbuf, _("\nOptions:\n")); #ifdef HAVE_BSD_AUTH_H lbuf_append(&lbuf, " -A %s", _("use helper program for password prompting\n")); #endif lbuf_append(&lbuf, " -a type %s", _("use specified BSD authentication type\n")); lbuf_append(&lbuf, " -b %s", _("run command in the background\n")); lbuf_append(&lbuf, " -C fd %s", _("close all file descriptors >= fd\n")); #ifdef HAVE_LOGIN_CAP_H lbuf_append(&lbuf, " -c class %s", _("run command with specified login class\n")); #endif lbuf_append(&lbuf, " -E %s", _("preserve user environment when executing command\n")); lbuf_append(&lbuf, " -e %s", _("edit files instead of running a command\n")); lbuf_append(&lbuf, " -g group %s", _("execute command as the specified group\n")); lbuf_append(&lbuf, " -H %s", _("set HOME variable to target user's home dir.\n")); lbuf_append(&lbuf, " -h %s", _("display help message and exit\n")); lbuf_append(&lbuf, " -i [command] %s", _("run a login shell as target user\n")); lbuf_append(&lbuf, " -K %s", _("remove timestamp file completely\n")); lbuf_append(&lbuf, " -k %s", _("invalidate timestamp file\n")); lbuf_append(&lbuf, " -l[l] command %s", _("list user's available commands\n")); lbuf_append(&lbuf, " -n %s", _("non-interactive mode, will not prompt user\n")); lbuf_append(&lbuf, " -P %s", _("preserve group vector instead of setting to target's\n")); lbuf_append(&lbuf, " -p prompt %s", _("use specified password prompt\n")); #ifdef HAVE_SELINUX lbuf_append(&lbuf, " -r role %s", _("create SELinux security context with specified role\n")); #endif lbuf_append(&lbuf, " -S %s", _("read password from standard input\n")); lbuf_append(&lbuf, " -s [command] %s", _("run a shell as target user\n")); #ifdef HAVE_SELINUX lbuf_append(&lbuf, " -t type %s", _("create SELinux security context with specified role\n")); #endif lbuf_append(&lbuf, " -U user %s", _("when listing, list specified user's privileges\n")); lbuf_append(&lbuf, " -u user %s", _("run command (or edit file) as specified user\n")); lbuf_append(&lbuf, " -V %s", _("display version information and exit\n")); lbuf_append(&lbuf, " -v %s", _("update user's timestamp without running a command\n")); lbuf_append(&lbuf, " -- %s", _("stop processing command line arguments\n")); lbuf_print(&lbuf); lbuf_destroy(&lbuf); exit(0); }