EFI_STATUS efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab) { EFI_STATUS status; int argc, i; CHAR16 **ARGV; CHAR16 descr[64]; InitializeLib(image, systab); status = argsplit(image, &argc, &ARGV); if (status != EFI_SUCCESS) { StatusToString (descr, status); Print (L"error %s\n", descr); } Print (L"argc %d\n", argc); for (i = 0; i < argc; i++) Print (L"argv[%d]: %s\n", i, ARGV[i]); Print (L"\nPress any key to continue\n"); efi_pause(); return EFI_SUCCESS; }
static void DisplayMsgHeader (CT ct, char *form) { pid_t child_id; int i, vecp; char **vec; char *file; vec = argsplit(mhlproc, &file, &vecp); vec[vecp++] = getcpy("-form"); vec[vecp++] = getcpy(form); vec[vecp++] = getcpy("-nobody"); vec[vecp++] = getcpy(ct->c_file); /* * If we've specified -(no)moreproc, * then just pass that along. */ if (nomore) { vec[vecp++] = getcpy("-nomoreproc"); } else if (progsw) { vec[vecp++] = getcpy("-moreproc"); vec[vecp++] = getcpy(progsw); } vec[vecp] = NULL; fflush (stdout); for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) sleep (5); switch (child_id) { case NOTOK: adios ("fork", "unable to"); /* NOTREACHED */ case OK: execvp (file, vec); fprintf (stderr, "unable to exec "); perror (mhlproc); _exit (-1); /* NOTREACHED */ default: xpid = -child_id; break; } arglist_free(file, vec); }
static void add_canonical_option(char *option,strlist_t *list) { char *arg=argsplit(option); if(arg) { char *joined; joined=xmalloc(strlen(option)+1+strlen(arg)+1); /* Make a canonical name=value form with no spaces */ strcpy(joined,option); strcat(joined,"="); strcat(joined,arg); append_to_strlist(list,joined); xfree(joined); } else append_to_strlist(list,option); }
int main (int argc, char **argv) { int msgp = 0, distsw = 0, vecp; int isdf = 0, mime = 0; int msgnum, status; char *cp, *dfolder = NULL, *maildir = NULL; char buf[BUFSIZ], **ap, **argp, **arguments, *program; char *msgs[MAXARGS], **vec; struct msgs *mp; struct stat st; if (nmh_init(argv[0], 1)) { return 1; } arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; vec = argsplit(postproc, &program, &vecp); vec[vecp++] = "-library"; vec[vecp++] = getcpy (m_maildir ("")); if ((cp = context_find ("fileproc"))) { vec[vecp++] = "-fileproc"; vec[vecp++] = cp; } if ((cp = context_find ("mhlproc"))) { vec[vecp++] = "-mhlproc"; vec[vecp++] = cp; } if ((cp = context_find ("credentials"))) { /* post doesn't read context so need to pass credentials. */ vec[vecp++] = "-credentials"; vec[vecp++] = cp; } while ((cp = *argp++)) { if (*cp == '-') { switch (smatch (++cp, switches)) { case AMBIGSW: ambigsw (cp, switches); done (1); case UNKWNSW: adios (NULL, "-%s unknown\n", cp); case HELPSW: snprintf (buf, sizeof(buf), "%s [file] [switches]", invo_name); print_help (buf, switches, 1); done (0); case VERSIONSW: print_version(invo_name); done (0); case DRAFTSW: msgs[msgp++] = draft; continue; case DFOLDSW: if (dfolder) adios (NULL, "only one draft folder at a time!"); if (!(cp = *argp++) || *cp == '-') adios (NULL, "missing argument to %s", argp[-2]); dfolder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp, *cp != '@' ? TFOLDER : TSUBCWF); continue; case DMSGSW: if (!(cp = *argp++) || *cp == '-') adios (NULL, "missing argument to %s", argp[-2]); msgs[msgp++] = cp; continue; case NDFLDSW: dfolder = NULL; isdf = NOTOK; continue; case PUSHSW: pushsw++; continue; case NPUSHSW: pushsw = 0; continue; case SPLITSW: if (!(cp = *argp++) || sscanf (cp, "%d", &splitsw) != 1) adios (NULL, "missing argument to %s", argp[-2]); continue; case UNIQSW: unique++; continue; case NUNIQSW: unique = 0; continue; case FORWSW: forwsw++; continue; case NFORWSW: forwsw = 0; continue; case VERBSW: verbsw++; vec[vecp++] = --cp; continue; case NVERBSW: verbsw = 0; vec[vecp++] = --cp; continue; case MIMESW: mime++; vec[vecp++] = --cp; continue; case NMIMESW: mime = 0; vec[vecp++] = --cp; continue; case DEBUGSW: debugsw++; /* fall */ case NFILTSW: case FRMTSW: case NFRMTSW: case BITSTUFFSW: case NBITSTUFFSW: case MSGDSW: case NMSGDSW: case WATCSW: case NWATCSW: case SNOOPSW: case SASLSW: case NOSASLSW: case TLSSW: case INITTLSSW: case NTLSSW: vec[vecp++] = --cp; continue; case ALIASW: case FILTSW: case WIDTHSW: case CLIESW: case SERVSW: case SASLMECHSW: case SASLMXSSFSW: case USERSW: case PORTSW: case MTSSW: case MESSAGEIDSW: vec[vecp++] = --cp; if (!(cp = *argp++) || *cp == '-') adios (NULL, "missing argument to %s", argp[-2]); vec[vecp++] = cp; continue; case ATTACHSW: advise(NULL, "The -attach switch is deprecated"); continue; case NOATTACHSW: advise(NULL, "The -noattach switch is deprecated"); continue; case ATTACHFORMATSW: advise(NULL, "The -attachformat switch is deprecated"); continue; } } else { msgs[msgp++] = cp; } } /* * check for "Aliasfile:" profile entry */ if ((cp = context_find ("Aliasfile"))) { char *dp = NULL; for (ap = brkstring(dp = getcpy(cp), " ", "\n"); ap && *ap; ap++) { vec[vecp++] = "-alias"; vec[vecp++] = *ap; } } if (dfolder == NULL) { if (msgp == 0) { msgs[msgp++] = getcpy (m_draft (NULL, NULL, 1, &isdf)); if (stat (msgs[0], &st) == NOTOK) adios (msgs[0], "unable to stat draft file"); cp = concat ("Use \"", msgs[0], "\"? ", NULL); for (status = LISTDSW; status != YESW;) { if (!(argp = getans (cp, anyl))) done (1); switch (status = smatch (*argp, anyl)) { case NOSW: done (0); case YESW: break; case LISTDSW: showfile (++argp, msgs[0]); break; default: advise (NULL, "say what?"); break; } } } else { for (msgnum = 0; msgnum < msgp; msgnum++) msgs[msgnum] = getcpy (m_maildir (msgs[msgnum])); } } else { if (!context_find ("path")) free (path ("./", TFOLDER)); if (!msgp) msgs[msgp++] = "cur"; maildir = m_maildir (dfolder); if (chdir (maildir) == NOTOK) adios (maildir, "unable to change directory to"); /* read folder and create message structure */ if (!(mp = folder_read (dfolder, 1))) adios (NULL, "unable to read folder %s", dfolder); /* check for empty folder */ if (mp->nummsg == 0) adios (NULL, "no messages in %s", dfolder); /* parse all the message ranges/sequences and set SELECTED */ for (msgnum = 0; msgnum < msgp; msgnum++) if (!m_convert (mp, msgs[msgnum])) done (1); seq_setprev (mp); /* set the previous-sequence */ for (msgp = 0, msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { if (is_selected (mp, msgnum)) { msgs[msgp++] = getcpy (m_name (msgnum)); unset_exists (mp, msgnum); } } mp->msgflags |= SEQMOD; seq_save (mp); } #ifdef WHATNOW go_to_it: #endif /* WHATNOW */ if ((cp = getenv ("SIGNATURE")) == NULL || *cp == 0) if ((cp = context_find ("signature")) && *cp) m_putenv ("SIGNATURE", cp); for (msgnum = 0; msgnum < msgp; msgnum++) if (stat (msgs[msgnum], &st) == NOTOK) adios (msgs[msgnum], "unable to stat draft file"); if ((annotext = getenv ("mhannotate")) == NULL || *annotext == 0) annotext = NULL; if (annotext && ((cp = getenv ("mhinplace")) != NULL && *cp != 0)) inplace = atoi (cp); if ((altmsg = getenv ("mhaltmsg")) == NULL || *altmsg == 0) altmsg = NULL; /* used by dist interface - see below */ if ((cp = getenv ("mhdist")) && *cp && (distsw = atoi (cp)) && altmsg) { vec[vecp++] = "-dist"; if ((cp = m_mktemp2(altmsg, invo_name, NULL, NULL)) == NULL) { adios(NULL, "unable to create temporary file in %s", get_temp_dir()); } distfile = getcpy (cp); (void) m_unlink(distfile); if (link (altmsg, distfile) == NOTOK) { /* Cygwin with FAT32 filesystem produces EPERM. */ if (errno != EXDEV && errno != EPERM #ifdef EISREMOTE && errno != EISREMOTE #endif /* EISREMOTE */ ) adios (distfile, "unable to link %s to", altmsg); free (distfile); if ((cp = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) { adios(NULL, "unable to create temporary file in %s", get_temp_dir()); } distfile = getcpy (cp); { int in, out; struct stat st; if ((in = open (altmsg, O_RDONLY)) == NOTOK) adios (altmsg, "unable to open"); fstat(in, &st); if ((out = creat (distfile, (int) st.st_mode & 0777)) == NOTOK) adios (distfile, "unable to write"); cpydata (in, out, altmsg, distfile); close (in); close (out); } } } else { distfile = NULL; } if (altmsg == NULL || stat (altmsg, &st) == NOTOK) { st.st_mtime = 0; st.st_dev = 0; st.st_ino = 0; } if (pushsw) push (); status = 0; closefds (3); for (msgnum = 0; msgnum < msgp; msgnum++) { switch (sendsbr (vec, vecp, program, msgs[msgnum], &st, 1)) { case DONE: done (++status); case NOTOK: status++; /* fall */ case OK: break; } } context_save (); /* save the context file */ done (status); return 1; }
EFI_STATUS efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab) { EFI_STATUS status; int argc, i, esl_mode = 0, hash_mode = 0; CHAR16 **ARGV, *var, *name, *progname, *owner_guid; EFI_FILE *file; void *buf; UINTN size, options = 0; EFI_GUID *owner; CHAR16 *variables[] = { L"PK", L"KEK", L"db", L"dbx", L"MokList" }; EFI_GUID *owners[] = { &GV_GUID, &GV_GUID, &SIG_DB, &SIG_DB, &MOK_OWNER }; InitializeLib(image, systab); status = argsplit(image, &argc, &ARGV); if (status != EFI_SUCCESS) { Print(L"Failed to parse arguments: %d\n", status); return status; } progname = ARGV[0]; while (argc > 1 && ARGV[1][0] == L'-') { if (StrCmp(ARGV[1], L"-a") == 0) { options |= EFI_VARIABLE_APPEND_WRITE; ARGV += 1; argc -= 1; } else if (StrCmp(ARGV[1], L"-g") == 0) { owner_guid = ARGV[2]; ARGV += 2; argc -= 2; } else if (StrCmp(ARGV[1], L"-e") == 0) { esl_mode = 1; ARGV += 1; argc -= 1; } else if (StrCmp(ARGV[1], L"-b") == 0) { esl_mode = 1; hash_mode = 1; ARGV += 1; argc -= 1; } else { /* unrecognised option */ break; } } if (argc != 3 ) { Print(L"Usage: %s: [-g guid] [-a] [-e] [-b] var file\n", progname); return EFI_INVALID_PARAMETER; } var = ARGV[1]; name = ARGV[2]; for(i = 0; i < ARRAY_SIZE(variables); i++) { if (StrCmp(var, variables[i]) == 0) { owner = owners[i]; break; } } if (i == ARRAY_SIZE(variables)) { Print(L"Invalid Variable %s\nVariable must be one of: ", var); for (i = 0; i < ARRAY_SIZE(variables); i++) Print(L"%s ", variables[i]); Print(L"\n"); return EFI_INVALID_PARAMETER; } if (owner == &MOK_OWNER) { if (!esl_mode) { Print(L"MoK variables can only be updated in ESL mode\n"); return EFI_INVALID_PARAMETER; } /* hack: esl goes directly into MoK variables, so we now * pretend we have a direct .auth update */ esl_mode = 0; } else { /* non MoK variables have runtime access and time based * authentication, MoK ones don't */ options |= EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS; } status = simple_file_open(image, name, &file, EFI_FILE_MODE_READ); if (status != EFI_SUCCESS) { Print(L"Failed to open file %s\n", name); return status; } status = simple_file_read_all(file, &size, &buf); if (status != EFI_SUCCESS) { Print(L"Failed to read file %s\n", name); return status; } simple_file_close(file); if (hash_mode) { UINT8 hash[SHA256_DIGEST_SIZE]; status = sha256_get_pecoff_digest_mem(buf, size, hash); if (status != EFI_SUCCESS) { Print(L"Failed to get hash of %s\n", name); return status; } status = variable_enroll_hash(var, *owner, hash); } else if (esl_mode) { status = SetSecureVariable(var, buf, size, *owner, options, 0); } else { status = uefi_call_wrapper(RT->SetVariable, 5, var, owner, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | options, size, buf); } if (status != EFI_SUCCESS) { Print(L"Failed to update variable %s: %d\n", var, status); return status; } return EFI_SUCCESS; }