Artifact abf0bdca85fd21fb548655212a1f49747f2ada9cb0309ca28b785db0f9804d72:
- File options.c — part of check-in [c14cf350df] at 2014-05-15 21:36:21 on branch manualheaven — Move src and doc files to top directory (user: base@atomicules.co.uk size: 5690) [more...]
- File
src/options.c
— part of check-in
[2ac75c5835]
at
2010-01-03 16:41:40
on branch origin/tweaks
— Avoid warnings about declaration of free in some files by ensuring stdlib.h is always imported
git-svn-id: https://pwman.svn.sourceforge.net/svnroot/pwman/trunk@101 db5f1c25-4851-472e-ac1e-5437d07aece1 (user: gagravarr@users.sourceforge.net size: 5690)
0000: 2f 2a 0a 20 2a 20 20 50 57 6d 61 6e 20 2d 20 70 /*. * PWman - p
0010: 61 73 73 77 6f 72 64 20 6d 61 6e 61 67 65 6d 65 assword manageme
0020: 6e 74 20 61 70 70 6c 69 63 61 74 69 6f 6e 0a 20 nt application.
0030: 2a 0a 20 2a 20 20 43 6f 70 79 72 69 67 68 74 20 *. * Copyright
0040: 28 43 29 20 32 30 30 32 20 20 49 76 61 6e 20 4b (C) 2002 Ivan K
0050: 65 6c 6c 79 20 3c 69 76 61 6e 40 69 76 61 6e 6b elly <ivan@ivank
0060: 65 6c 6c 79 2e 6e 65 74 3e 0a 20 2a 0a 20 2a 20 elly.net>. *. *
0070: 20 54 68 69 73 20 70 72 6f 67 72 61 6d 20 69 73 This program is
0080: 20 66 72 65 65 20 73 6f 66 74 77 61 72 65 3b 20 free software;
0090: 79 6f 75 20 63 61 6e 20 72 65 64 69 73 74 72 69 you can redistri
00a0: 62 75 74 65 20 69 74 20 61 6e 64 2f 6f 72 20 6d bute it and/or m
00b0: 6f 64 69 66 79 0a 20 2a 20 20 69 74 20 75 6e 64 odify. * it und
00c0: 65 72 20 74 68 65 20 74 65 72 6d 73 20 6f 66 20 er the terms of
00d0: 74 68 65 20 47 4e 55 20 47 65 6e 65 72 61 6c 20 the GNU General
00e0: 50 75 62 6c 69 63 20 4c 69 63 65 6e 73 65 20 61 Public License a
00f0: 73 20 70 75 62 6c 69 73 68 65 64 20 62 79 0a 20 s published by.
0100: 2a 20 20 74 68 65 20 46 72 65 65 20 53 6f 66 74 * the Free Soft
0110: 77 61 72 65 20 46 6f 75 6e 64 61 74 69 6f 6e 3b ware Foundation;
0120: 20 65 69 74 68 65 72 20 76 65 72 73 69 6f 6e 20 either version
0130: 32 20 6f 66 20 74 68 65 20 4c 69 63 65 6e 73 65 2 of the License
0140: 2c 20 6f 72 0a 20 2a 20 20 28 61 74 20 79 6f 75 , or. * (at you
0150: 72 20 6f 70 74 69 6f 6e 29 20 61 6e 79 20 6c 61 r option) any la
0160: 74 65 72 20 76 65 72 73 69 6f 6e 2e 0a 20 2a 0a ter version.. *.
0170: 20 2a 20 20 54 68 69 73 20 70 72 6f 67 72 61 6d * This program
0180: 20 69 73 20 64 69 73 74 72 69 62 75 74 65 64 20 is distributed
0190: 69 6e 20 74 68 65 20 68 6f 70 65 20 74 68 61 74 in the hope that
01a0: 20 69 74 20 77 69 6c 6c 20 62 65 20 75 73 65 66 it will be usef
01b0: 75 6c 2c 0a 20 2a 20 20 62 75 74 20 57 49 54 48 ul,. * but WITH
01c0: 4f 55 54 20 41 4e 59 20 57 41 52 52 41 4e 54 59 OUT ANY WARRANTY
01d0: 3b 20 77 69 74 68 6f 75 74 20 65 76 65 6e 20 74 ; without even t
01e0: 68 65 20 69 6d 70 6c 69 65 64 20 77 61 72 72 61 he implied warra
01f0: 6e 74 79 20 6f 66 0a 20 2a 20 20 4d 45 52 43 48 nty of. * MERCH
0200: 41 4e 54 41 42 49 4c 49 54 59 20 6f 72 20 46 49 ANTABILITY or FI
0210: 54 4e 45 53 53 20 46 4f 52 20 41 20 50 41 52 54 TNESS FOR A PART
0220: 49 43 55 4c 41 52 20 50 55 52 50 4f 53 45 2e 20 ICULAR PURPOSE.
0230: 20 53 65 65 20 74 68 65 0a 20 2a 20 20 47 4e 55 See the. * GNU
0240: 20 47 65 6e 65 72 61 6c 20 50 75 62 6c 69 63 20 General Public
0250: 4c 69 63 65 6e 73 65 20 66 6f 72 20 6d 6f 72 65 License for more
0260: 20 64 65 74 61 69 6c 73 2e 0a 20 2a 0a 20 2a 20 details.. *. *
0270: 20 59 6f 75 20 73 68 6f 75 6c 64 20 68 61 76 65 You should have
0280: 20 72 65 63 65 69 76 65 64 20 61 20 63 6f 70 79 received a copy
0290: 20 6f 66 20 74 68 65 20 47 4e 55 20 47 65 6e 65 of the GNU Gene
02a0: 72 61 6c 20 50 75 62 6c 69 63 20 4c 69 63 65 6e ral Public Licen
02b0: 73 65 0a 20 2a 20 20 61 6c 6f 6e 67 20 77 69 74 se. * along wit
02c0: 68 20 74 68 69 73 20 70 72 6f 67 72 61 6d 3b 20 h this program;
02d0: 69 66 20 6e 6f 74 2c 20 77 72 69 74 65 20 74 6f if not, write to
02e0: 20 74 68 65 20 46 72 65 65 20 53 6f 66 74 77 61 the Free Softwa
02f0: 72 65 0a 20 2a 20 20 46 6f 75 6e 64 61 74 69 6f re. * Foundatio
0300: 6e 2c 20 49 6e 63 2e 2c 20 35 39 20 54 65 6d 70 n, Inc., 59 Temp
0310: 6c 65 20 50 6c 61 63 65 2c 20 53 75 69 74 65 20 le Place, Suite
0320: 33 33 30 2c 20 42 6f 73 74 6f 6e 2c 20 4d 41 20 330, Boston, MA
0330: 20 30 32 31 31 31 2d 31 33 30 37 20 20 55 53 41 02111-1307 USA
0340: 0a 20 2a 2f 0a 0a 23 69 6e 63 6c 75 64 65 20 3c . */..#include <
0350: 70 77 6d 61 6e 2e 68 3e 0a 23 69 6e 63 6c 75 64 pwman.h>.#includ
0360: 65 20 3c 73 74 64 6c 69 62 2e 68 3e 0a 23 69 6e e <stdlib.h>.#in
0370: 63 6c 75 64 65 20 3c 6c 69 62 78 6d 6c 2f 74 72 clude <libxml/tr
0380: 65 65 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c ee.h>.#include <
0390: 6c 69 62 78 6d 6c 2f 70 61 72 73 65 72 2e 68 3e libxml/parser.h>
03a0: 0a 0a 4f 70 74 69 6f 6e 73 2a 0a 6f 70 74 69 6f ..Options*.optio
03b0: 6e 73 5f 6e 65 77 28 29 0a 7b 0a 09 4f 70 74 69 ns_new().{..Opti
03c0: 6f 6e 73 20 2a 6e 65 77 3b 0a 0a 09 6e 65 77 20 ons *new;...new
03d0: 3d 20 6d 61 6c 6c 6f 63 28 73 69 7a 65 6f 66 28 = malloc(sizeof(
03e0: 4f 70 74 69 6f 6e 73 29 29 3b 0a 09 6e 65 77 2d Options));..new-
03f0: 3e 67 70 67 5f 69 64 20 3d 20 6d 61 6c 6c 6f 63 >gpg_id = malloc
0400: 28 53 54 52 49 4e 47 5f 4c 4f 4e 47 29 3b 0a 09 (STRING_LONG);..
0410: 6e 65 77 2d 3e 67 70 67 5f 70 61 74 68 20 3d 20 new->gpg_path =
0420: 6d 61 6c 6c 6f 63 28 53 54 52 49 4e 47 5f 4c 4f malloc(STRING_LO
0430: 4e 47 29 3b 0a 09 6e 65 77 2d 3e 70 61 73 73 77 NG);..new->passw
0440: 6f 72 64 5f 66 69 6c 65 20 3d 20 6d 61 6c 6c 6f ord_file = mallo
0450: 63 28 53 54 52 49 4e 47 5f 4c 4f 4e 47 29 3b 0a c(STRING_LONG);.
0460: 09 6e 65 77 2d 3e 70 61 73 73 70 68 72 61 73 65 .new->passphrase
0470: 5f 74 69 6d 65 6f 75 74 20 3d 20 31 38 30 3b 0a _timeout = 180;.
0480: 09 6e 65 77 2d 3e 72 65 61 64 6f 6e 6c 79 20 3d .new->readonly =
0490: 20 46 41 4c 53 45 3b 0a 0a 09 6e 65 77 2d 3e 66 FALSE;...new->f
04a0: 69 6c 74 65 72 20 3d 20 66 69 6c 74 65 72 5f 6e ilter = filter_n
04b0: 65 77 28 29 3b 0a 09 6e 65 77 2d 3e 73 65 61 72 ew();..new->sear
04c0: 63 68 20 3d 20 73 65 61 72 63 68 5f 6e 65 77 28 ch = search_new(
04d0: 29 3b 0a 0a 09 72 65 74 75 72 6e 20 6e 65 77 3b );...return new;
04e0: 0a 7d 0a 0a 63 68 61 72 2a 0a 6f 70 74 69 6f 6e .}..char*.option
04f0: 73 5f 67 65 74 5f 66 69 6c 65 28 29 0a 7b 0a 09 s_get_file().{..
0500: 63 68 61 72 20 2a 63 6f 6e 66 5f 66 69 6c 65 3b char *conf_file;
0510: 0a 0a 09 63 6f 6e 66 5f 66 69 6c 65 20 3d 20 6d ...conf_file = m
0520: 61 6c 6c 6f 63 28 53 54 52 49 4e 47 5f 4c 4f 4e alloc(STRING_LON
0530: 47 29 3b 0a 09 0a 09 69 66 28 21 67 65 74 65 6e G);....if(!geten
0540: 76 28 22 48 4f 4d 45 22 29 29 7b 0a 09 09 72 65 v("HOME")){...re
0550: 74 75 72 6e 20 4e 55 4c 4c 3b 0a 09 7d 20 65 6c turn NULL;..} el
0560: 73 65 20 7b 0a 09 09 73 6e 70 72 69 6e 74 66 28 se {...snprintf(
0570: 63 6f 6e 66 5f 66 69 6c 65 2c 20 53 54 52 49 4e conf_file, STRIN
0580: 47 5f 4c 4f 4e 47 2c 20 22 25 73 2f 25 73 22 2c G_LONG, "%s/%s",
0590: 20 67 65 74 65 6e 76 28 22 48 4f 4d 45 22 29 2c getenv("HOME"),
05a0: 20 43 4f 4e 46 5f 46 49 4c 45 29 3b 0a 09 7d 0a CONF_FILE);..}.
05b0: 0a 09 72 65 74 75 72 6e 20 63 6f 6e 66 5f 66 69 ..return conf_fi
05c0: 6c 65 3b 0a 7d 0a 0a 69 6e 74 0a 6f 70 74 69 6f le;.}..int.optio
05d0: 6e 73 5f 72 65 61 64 28 29 0a 7b 0a 09 63 68 61 ns_read().{..cha
05e0: 72 20 2a 66 69 6c 65 2c 20 2a 74 65 78 74 3b 0a r *file, *text;.
05f0: 09 78 6d 6c 44 6f 63 50 74 72 20 64 6f 63 3b 0a .xmlDocPtr doc;.
0600: 09 78 6d 6c 4e 6f 64 65 50 74 72 20 6e 6f 64 65 .xmlNodePtr node
0610: 2c 20 72 6f 6f 74 3b 0a 09 0a 09 66 69 6c 65 20 , root;....file
0620: 3d 20 6f 70 74 69 6f 6e 73 5f 67 65 74 5f 66 69 = options_get_fi
0630: 6c 65 28 29 3b 0a 09 69 66 28 66 69 6c 65 20 3d le();..if(file =
0640: 3d 20 4e 55 4c 4c 29 7b 0a 09 09 72 65 74 75 72 = NULL){...retur
0650: 6e 20 2d 31 3b 0a 09 7d 0a 0a 09 64 6f 63 20 3d n -1;..}...doc =
0660: 20 78 6d 6c 50 61 72 73 65 46 69 6c 65 28 66 69 xmlParseFile(fi
0670: 6c 65 29 3b 0a 09 69 66 28 21 64 6f 63 29 7b 0a le);..if(!doc){.
0680: 09 09 72 65 74 75 72 6e 20 2d 31 3b 0a 09 7d 0a ..return -1;..}.
0690: 0a 09 72 6f 6f 74 20 3d 20 78 6d 6c 44 6f 63 47 ..root = xmlDocG
06a0: 65 74 52 6f 6f 74 45 6c 65 6d 65 6e 74 28 64 6f etRootElement(do
06b0: 63 29 3b 0a 0a 09 69 66 28 21 72 6f 6f 74 20 7c c);...if(!root |
06c0: 7c 20 21 72 6f 6f 74 2d 3e 6e 61 6d 65 20 7c 7c | !root->name ||
06d0: 20 28 73 74 72 63 6d 70 28 28 63 68 61 72 2a 29 (strcmp((char*)
06e0: 72 6f 6f 74 2d 3e 6e 61 6d 65 2c 20 22 70 77 6d root->name, "pwm
06f0: 5f 63 6f 6e 66 69 67 22 29 20 21 3d 20 30 29 20 _config") != 0)
0700: 29 7b 0a 09 09 66 70 72 69 6e 74 66 28 73 74 64 ){...fprintf(std
0710: 65 72 72 2c 22 50 57 4d 2d 57 61 72 6e 69 6e 67 err,"PWM-Warning
0720: 3a 20 42 61 64 6c 79 20 46 6f 72 6d 65 64 20 2e : Badly Formed .
0730: 70 77 6d 61 6e 72 63 5c 6e 22 29 3b 0a 09 09 72 pwmanrc\n");...r
0740: 65 74 75 72 6e 20 2d 31 3b 0a 09 7d 0a 0a 09 66 eturn -1;..}...f
0750: 6f 72 28 6e 6f 64 65 20 3d 20 72 6f 6f 74 2d 3e or(node = root->
0760: 63 68 69 6c 64 72 65 6e 3b 20 6e 6f 64 65 20 21 children; node !
0770: 3d 20 4e 55 4c 4c 3b 20 6e 6f 64 65 20 3d 20 6e = NULL; node = n
0780: 6f 64 65 2d 3e 6e 65 78 74 29 7b 0a 09 09 69 66 ode->next){...if
0790: 28 21 6e 6f 64 65 20 7c 7c 20 21 6e 6f 64 65 2d (!node || !node-
07a0: 3e 6e 61 6d 65 29 7b 0a 09 09 09 64 65 62 75 67 >name){....debug
07b0: 28 22 72 65 61 64 5f 63 6f 6e 66 69 67 3a 20 46 ("read_config: F
07c0: 75 63 6b 65 64 20 75 70 20 78 6d 6c 20 6e 6f 64 ucked up xml nod
07d0: 65 22 29 3b 0a 09 09 7d 20 65 6c 73 65 20 69 66 e");...} else if
07e0: 28 20 73 74 72 63 6d 70 28 28 63 68 61 72 2a 29 ( strcmp((char*)
07f0: 6e 6f 64 65 2d 3e 6e 61 6d 65 2c 20 22 67 70 67 node->name, "gpg
0800: 5f 69 64 22 29 20 3d 3d 20 30 29 7b 0a 09 09 09 _id") == 0){....
0810: 74 65 78 74 20 3d 20 28 63 68 61 72 2a 29 78 6d text = (char*)xm
0820: 6c 4e 6f 64 65 47 65 74 43 6f 6e 74 65 6e 74 28 lNodeGetContent(
0830: 6e 6f 64 65 29 3b 0a 09 09 09 69 66 28 74 65 78 node);....if(tex
0840: 74 29 20 73 74 72 6e 63 70 79 28 6f 70 74 69 6f t) strncpy(optio
0850: 6e 73 2d 3e 67 70 67 5f 69 64 2c 20 74 65 78 74 ns->gpg_id, text
0860: 2c 20 53 54 52 49 4e 47 5f 4c 4f 4e 47 29 3b 0a , STRING_LONG);.
0870: 09 09 7d 20 65 6c 73 65 20 69 66 28 20 73 74 72 ..} else if( str
0880: 63 6d 70 28 28 63 68 61 72 2a 29 6e 6f 64 65 2d cmp((char*)node-
0890: 3e 6e 61 6d 65 2c 20 22 67 70 67 5f 70 61 74 68 >name, "gpg_path
08a0: 22 29 20 3d 3d 20 30 29 7b 0a 09 09 09 74 65 78 ") == 0){....tex
08b0: 74 20 3d 20 28 63 68 61 72 2a 29 78 6d 6c 4e 6f t = (char*)xmlNo
08c0: 64 65 47 65 74 43 6f 6e 74 65 6e 74 28 6e 6f 64 deGetContent(nod
08d0: 65 29 3b 0a 09 09 09 69 66 28 74 65 78 74 29 20 e);....if(text)
08e0: 73 74 72 6e 63 70 79 28 6f 70 74 69 6f 6e 73 2d strncpy(options-
08f0: 3e 67 70 67 5f 70 61 74 68 2c 20 74 65 78 74 2c >gpg_path, text,
0900: 20 53 54 52 49 4e 47 5f 4c 4f 4e 47 29 3b 0a 09 STRING_LONG);..
0910: 09 7d 20 65 6c 73 65 20 69 66 28 20 73 74 72 63 .} else if( strc
0920: 6d 70 28 28 63 68 61 72 2a 29 6e 6f 64 65 2d 3e mp((char*)node->
0930: 6e 61 6d 65 2c 20 22 70 61 73 73 77 6f 72 64 5f name, "password_
0940: 66 69 6c 65 22 29 20 3d 3d 20 30 29 7b 0a 09 09 file") == 0){...
0950: 09 74 65 78 74 20 3d 20 28 63 68 61 72 2a 29 78 .text = (char*)x
0960: 6d 6c 4e 6f 64 65 47 65 74 43 6f 6e 74 65 6e 74 mlNodeGetContent
0970: 28 6e 6f 64 65 29 3b 0a 09 09 09 69 66 28 74 65 (node);....if(te
0980: 78 74 29 20 73 74 72 6e 63 70 79 28 6f 70 74 69 xt) strncpy(opti
0990: 6f 6e 73 2d 3e 70 61 73 73 77 6f 72 64 5f 66 69 ons->password_fi
09a0: 6c 65 2c 20 74 65 78 74 2c 20 53 54 52 49 4e 47 le, text, STRING
09b0: 5f 4c 4f 4e 47 29 3b 0a 09 09 7d 20 65 6c 73 65 _LONG);...} else
09c0: 20 69 66 28 20 73 74 72 63 6d 70 28 28 63 68 61 if( strcmp((cha
09d0: 72 2a 29 6e 6f 64 65 2d 3e 6e 61 6d 65 2c 20 22 r*)node->name, "
09e0: 70 61 73 73 70 68 72 61 73 65 5f 74 69 6d 65 6f passphrase_timeo
09f0: 75 74 22 29 20 3d 3d 20 30 29 7b 0a 09 09 09 74 ut") == 0){....t
0a00: 65 78 74 20 3d 20 28 63 68 61 72 2a 29 78 6d 6c ext = (char*)xml
0a10: 4e 6f 64 65 47 65 74 43 6f 6e 74 65 6e 74 28 6e NodeGetContent(n
0a20: 6f 64 65 29 3b 0a 09 09 09 69 66 28 74 65 78 74 ode);....if(text
0a30: 29 7b 20 6f 70 74 69 6f 6e 73 2d 3e 70 61 73 73 ){ options->pass
0a40: 70 68 72 61 73 65 5f 74 69 6d 65 6f 75 74 20 3d phrase_timeout =
0a50: 20 61 74 6f 69 28 74 65 78 74 29 3b 20 7d 0a 09 atoi(text); }..
0a60: 09 7d 20 65 6c 73 65 20 69 66 28 20 73 74 72 63 .} else if( strc
0a70: 6d 70 28 28 63 68 61 72 2a 29 6e 6f 64 65 2d 3e mp((char*)node->
0a80: 6e 61 6d 65 2c 20 22 66 69 6c 74 65 72 22 29 20 name, "filter")
0a90: 3d 3d 20 30 29 7b 0a 09 09 09 6f 70 74 69 6f 6e == 0){....option
0aa0: 73 2d 3e 66 69 6c 74 65 72 2d 3e 66 69 65 6c 64 s->filter->field
0ab0: 20 3d 20 61 74 6f 69 28 20 28 63 68 61 72 2a 29 = atoi( (char*)
0ac0: 78 6d 6c 47 65 74 50 72 6f 70 28 6e 6f 64 65 2c xmlGetProp(node,
0ad0: 20 22 66 69 65 6c 64 22 29 20 29 3b 0a 09 09 09 "field") );....
0ae0: 74 65 78 74 20 3d 20 28 63 68 61 72 2a 29 78 6d text = (char*)xm
0af0: 6c 4e 6f 64 65 47 65 74 43 6f 6e 74 65 6e 74 28 lNodeGetContent(
0b00: 6e 6f 64 65 29 3b 0a 09 09 09 69 66 28 74 65 78 node);....if(tex
0b10: 74 29 20 73 74 72 6e 63 70 79 28 6f 70 74 69 6f t) strncpy(optio
0b20: 6e 73 2d 3e 66 69 6c 74 65 72 2d 3e 66 69 6c 74 ns->filter->filt
0b30: 65 72 2c 20 74 65 78 74 2c 20 53 54 52 49 4e 47 er, text, STRING
0b40: 5f 4c 4f 4e 47 29 3b 0a 09 09 7d 20 65 6c 73 65 _LONG);...} else
0b50: 20 69 66 28 20 73 74 72 63 6d 70 28 28 63 68 61 if( strcmp((cha
0b60: 72 2a 29 6e 6f 64 65 2d 3e 6e 61 6d 65 2c 20 22 r*)node->name, "
0b70: 72 65 61 64 6f 6e 6c 79 22 29 20 3d 3d 20 30 29 readonly") == 0)
0b80: 7b 0a 09 09 09 6f 70 74 69 6f 6e 73 2d 3e 72 65 {....options->re
0b90: 61 64 6f 6e 6c 79 20 3d 20 54 52 55 45 3b 0a 09 adonly = TRUE;..
0ba0: 09 7d 20 65 6c 73 65 20 69 66 28 20 73 74 72 63 .} else if( strc
0bb0: 6d 70 28 28 63 68 61 72 2a 29 6e 6f 64 65 2d 3e mp((char*)node->
0bc0: 6e 61 6d 65 2c 20 22 74 65 78 74 22 29 20 3d 3d name, "text") ==
0bd0: 20 30 29 7b 0a 09 09 09 2f 2f 20 53 61 66 65 20 0){....// Safe
0be0: 74 6f 20 69 67 6e 6f 72 65 2e 20 54 68 69 73 20 to ignore. This
0bf0: 69 73 20 77 68 69 74 65 73 70 61 63 65 20 65 74 is whitespace et
0c00: 63 0a 09 09 7d 20 65 6c 73 65 20 7b 0a 09 09 09 c...} else {....
0c10: 64 65 62 75 67 28 22 72 65 61 64 5f 63 6f 6e 66 debug("read_conf
0c20: 69 67 3a 20 55 6e 72 65 63 6f 67 6e 69 73 65 64 ig: Unrecognised
0c30: 20 78 6d 6c 20 6e 6f 64 65 20 27 25 73 27 22 2c xml node '%s'",
0c40: 20 28 63 68 61 72 2a 29 6e 6f 64 65 2d 3e 6e 61 (char*)node->na
0c50: 6d 65 29 3b 0a 09 09 7d 0a 09 7d 0a 09 77 72 69 me);...}..}..wri
0c60: 74 65 5f 6f 70 74 69 6f 6e 73 20 3d 20 54 52 55 te_options = TRU
0c70: 45 3b 0a 09 78 6d 6c 46 72 65 65 44 6f 63 28 64 E;..xmlFreeDoc(d
0c80: 6f 63 29 3b 0a 09 72 65 74 75 72 6e 20 30 3b 0a oc);..return 0;.
0c90: 7d 0a 0a 69 6e 74 0a 6f 70 74 69 6f 6e 73 5f 77 }..int.options_w
0ca0: 72 69 74 65 28 29 0a 7b 0a 09 63 68 61 72 20 2a rite().{..char *
0cb0: 66 69 6c 65 3b 0a 09 63 68 61 72 20 74 65 78 74 file;..char text
0cc0: 5b 53 54 52 49 4e 47 5f 53 48 4f 52 54 5d 3b 0a [STRING_SHORT];.
0cd0: 09 78 6d 6c 44 6f 63 50 74 72 20 64 6f 63 3b 0a .xmlDocPtr doc;.
0ce0: 09 78 6d 6c 4e 6f 64 65 50 74 72 20 6e 6f 64 65 .xmlNodePtr node
0cf0: 2c 20 72 6f 6f 74 3b 0a 0a 09 69 66 28 21 77 72 , root;...if(!wr
0d00: 69 74 65 5f 6f 70 74 69 6f 6e 73 29 7b 0a 09 09 ite_options){...
0d10: 72 65 74 75 72 6e 20 30 3b 0a 09 7d 0a 09 66 69 return 0;..}..fi
0d20: 6c 65 20 3d 20 6f 70 74 69 6f 6e 73 5f 67 65 74 le = options_get
0d30: 5f 66 69 6c 65 28 29 3b 0a 09 69 66 28 66 69 6c _file();..if(fil
0d40: 65 20 3d 3d 20 4e 55 4c 4c 29 7b 0a 09 09 72 65 e == NULL){...re
0d50: 74 75 72 6e 20 2d 31 3b 0a 09 7d 0a 0a 09 69 66 turn -1;..}...if
0d60: 28 21 6f 70 74 69 6f 6e 73 29 7b 0a 09 09 72 65 (!options){...re
0d70: 74 75 72 6e 20 2d 31 3b 0a 09 7d 0a 09 64 6f 63 turn -1;..}..doc
0d80: 20 3d 20 78 6d 6c 4e 65 77 44 6f 63 28 28 78 6d = xmlNewDoc((xm
0d90: 6c 43 68 61 72 2a 29 20 22 31 2e 30 22 29 3b 0a lChar*) "1.0");.
0da0: 09 72 6f 6f 74 20 3d 20 78 6d 6c 4e 65 77 44 6f .root = xmlNewDo
0db0: 63 4e 6f 64 65 28 64 6f 63 2c 20 4e 55 4c 4c 2c cNode(doc, NULL,
0dc0: 20 28 78 6d 6c 43 68 61 72 2a 29 22 70 77 6d 5f (xmlChar*)"pwm_
0dd0: 63 6f 6e 66 69 67 22 2c 20 4e 55 4c 4c 29 3b 0a config", NULL);.
0de0: 09 78 6d 6c 4e 65 77 43 68 69 6c 64 28 72 6f 6f .xmlNewChild(roo
0df0: 74 2c 20 4e 55 4c 4c 2c 20 28 78 6d 6c 43 68 61 t, NULL, (xmlCha
0e00: 72 2a 29 22 67 70 67 5f 69 64 22 2c 20 28 78 6d r*)"gpg_id", (xm
0e10: 6c 43 68 61 72 2a 29 6f 70 74 69 6f 6e 73 2d 3e lChar*)options->
0e20: 67 70 67 5f 69 64 29 3b 0a 09 78 6d 6c 4e 65 77 gpg_id);..xmlNew
0e30: 43 68 69 6c 64 28 72 6f 6f 74 2c 20 4e 55 4c 4c Child(root, NULL
0e40: 2c 20 28 78 6d 6c 43 68 61 72 2a 29 22 67 70 67 , (xmlChar*)"gpg
0e50: 5f 70 61 74 68 22 2c 20 28 78 6d 6c 43 68 61 72 _path", (xmlChar
0e60: 2a 29 6f 70 74 69 6f 6e 73 2d 3e 67 70 67 5f 70 *)options->gpg_p
0e70: 61 74 68 29 3b 0a 09 78 6d 6c 4e 65 77 43 68 69 ath);..xmlNewChi
0e80: 6c 64 28 72 6f 6f 74 2c 20 4e 55 4c 4c 2c 20 28 ld(root, NULL, (
0e90: 78 6d 6c 43 68 61 72 2a 29 22 70 61 73 73 77 6f xmlChar*)"passwo
0ea0: 72 64 5f 66 69 6c 65 22 2c 20 28 78 6d 6c 43 68 rd_file", (xmlCh
0eb0: 61 72 2a 29 6f 70 74 69 6f 6e 73 2d 3e 70 61 73 ar*)options->pas
0ec0: 73 77 6f 72 64 5f 66 69 6c 65 29 3b 0a 0a 09 73 sword_file);...s
0ed0: 6e 70 72 69 6e 74 66 28 74 65 78 74 2c 20 53 54 nprintf(text, ST
0ee0: 52 49 4e 47 5f 53 48 4f 52 54 2c 20 22 25 64 22 RING_SHORT, "%d"
0ef0: 2c 20 6f 70 74 69 6f 6e 73 2d 3e 70 61 73 73 70 , options->passp
0f00: 68 72 61 73 65 5f 74 69 6d 65 6f 75 74 29 3b 0a hrase_timeout);.
0f10: 09 78 6d 6c 4e 65 77 43 68 69 6c 64 28 72 6f 6f .xmlNewChild(roo
0f20: 74 2c 20 4e 55 4c 4c 2c 20 28 78 6d 6c 43 68 61 t, NULL, (xmlCha
0f30: 72 2a 29 22 70 61 73 73 70 68 72 61 73 65 5f 74 r*)"passphrase_t
0f40: 69 6d 65 6f 75 74 22 2c 20 28 78 6d 6c 43 68 61 imeout", (xmlCha
0f50: 72 2a 29 74 65 78 74 29 3b 0a 0a 09 73 6e 70 72 r*)text);...snpr
0f60: 69 6e 74 66 28 74 65 78 74 2c 20 53 54 52 49 4e intf(text, STRIN
0f70: 47 5f 53 48 4f 52 54 2c 20 22 25 64 22 2c 20 6f G_SHORT, "%d", o
0f80: 70 74 69 6f 6e 73 2d 3e 66 69 6c 74 65 72 2d 3e ptions->filter->
0f90: 66 69 65 6c 64 29 3b 0a 09 6e 6f 64 65 20 3d 20 field);..node =
0fa0: 78 6d 6c 4e 65 77 43 68 69 6c 64 28 72 6f 6f 74 xmlNewChild(root
0fb0: 2c 20 4e 55 4c 4c 2c 20 28 78 6d 6c 43 68 61 72 , NULL, (xmlChar
0fc0: 2a 29 22 66 69 6c 74 65 72 22 2c 20 28 78 6d 6c *)"filter", (xml
0fd0: 43 68 61 72 2a 29 6f 70 74 69 6f 6e 73 2d 3e 66 Char*)options->f
0fe0: 69 6c 74 65 72 2d 3e 66 69 6c 74 65 72 29 3b 0a ilter->filter);.
0ff0: 09 78 6d 6c 53 65 74 50 72 6f 70 28 6e 6f 64 65 .xmlSetProp(node
1000: 2c 20 22 66 69 65 6c 64 22 2c 20 74 65 78 74 29 , "field", text)
1010: 3b 0a 0a 09 2f 2f 20 4e 6f 74 65 20 2d 20 73 65 ;...// Note - se
1020: 61 72 63 68 20 69 73 6e 27 74 20 73 65 72 69 61 arch isn't seria
1030: 6c 69 73 65 64 2c 20 62 75 74 20 66 69 6c 74 65 lised, but filte
1040: 72 20 69 73 0a 0a 09 78 6d 6c 44 6f 63 53 65 74 r is...xmlDocSet
1050: 52 6f 6f 74 45 6c 65 6d 65 6e 74 28 64 6f 63 2c RootElement(doc,
1060: 20 72 6f 6f 74 29 3b 0a 0a 09 69 66 28 20 78 6d root);...if( xm
1070: 6c 53 61 76 65 46 6f 72 6d 61 74 46 69 6c 65 28 lSaveFormatFile(
1080: 66 69 6c 65 2c 20 64 6f 63 2c 20 54 52 55 45 29 file, doc, TRUE)
1090: 20 21 3d 20 2d 31 20 29 7b 0a 09 09 78 6d 6c 46 != -1 ){...xmlF
10a0: 72 65 65 44 6f 63 28 64 6f 63 29 3b 0a 09 09 72 reeDoc(doc);...r
10b0: 65 74 75 72 6e 20 30 3b 0a 09 7d 20 65 6c 73 65 eturn 0;..} else
10c0: 20 7b 0a 09 09 64 65 62 75 67 28 22 77 72 69 74 {...debug("writ
10d0: 65 5f 6f 70 74 69 6f 6e 73 3a 20 63 6f 75 6c 64 e_options: could
10e0: 6e 27 74 20 77 72 69 74 65 20 63 6f 6e 66 69 67 n't write config
10f0: 20 66 69 6c 65 22 29 3b 0a 09 09 78 6d 6c 46 72 file");...xmlFr
1100: 65 65 44 6f 63 28 64 6f 63 29 3b 0a 09 09 72 65 eeDoc(doc);...re
1110: 74 75 72 6e 20 2d 31 3b 0a 09 7d 0a 7d 0a 0a 76 turn -1;..}.}..v
1120: 6f 69 64 0a 6f 70 74 69 6f 6e 73 5f 67 65 74 28 oid.options_get(
1130: 29 0a 7b 0a 09 63 68 61 72 20 70 77 5f 66 69 6c ).{..char pw_fil
1140: 65 5b 53 54 52 49 4e 47 5f 4c 4f 4e 47 5d 3b 0a e[STRING_LONG];.
1150: 09 63 68 61 72 20 74 65 78 74 5b 53 54 52 49 4e .char text[STRIN
1160: 47 5f 53 48 4f 52 54 5d 3b 0a 09 0a 09 70 75 74 G_SHORT];....put
1170: 73 28 22 48 6d 6d 2e 2e 2e 20 63 61 6e 27 74 20 s("Hmm... can't
1180: 6f 70 65 6e 20 7e 2f 2e 70 77 6d 61 6e 72 63 2c open ~/.pwmanrc,
1190: 20 77 65 27 6c 6c 20 63 72 65 61 74 65 20 6f 6e we'll create on
11a0: 65 20 6d 61 6e 75 61 6c 6c 79 20 6e 6f 77 2e 22 e manually now."
11b0: 29 3b 0a 09 0a 09 70 72 69 6e 74 66 28 22 47 6e );....printf("Gn
11c0: 75 50 47 20 49 44 20 5b 79 6f 75 40 79 6f 75 72 uPG ID [you@your
11d0: 64 6f 6d 61 69 6e 2e 63 6f 6d 5d 20 6f 72 20 5b domain.com] or [
11e0: 30 31 32 33 34 35 41 42 5d 3a 20 22 29 3b 0a 09 012345AB]: ");..
11f0: 66 67 65 74 73 28 6f 70 74 69 6f 6e 73 2d 3e 67 fgets(options->g
1200: 70 67 5f 69 64 2c 20 53 54 52 49 4e 47 5f 4c 4f pg_id, STRING_LO
1210: 4e 47 2c 20 73 74 64 69 6e 29 3b 0a 09 69 66 28 NG, stdin);..if(
1220: 20 73 74 72 63 6d 70 28 6f 70 74 69 6f 6e 73 2d strcmp(options-
1230: 3e 67 70 67 5f 69 64 2c 20 22 5c 6e 22 29 20 3d >gpg_id, "\n") =
1240: 3d 20 30 20 29 7b 0a 09 09 73 74 72 6e 63 70 79 = 0 ){...strncpy
1250: 28 6f 70 74 69 6f 6e 73 2d 3e 67 70 67 5f 69 64 (options->gpg_id
1260: 2c 20 22 79 6f 75 40 79 6f 75 72 64 6f 6d 61 69 , "you@yourdomai
1270: 6e 2e 63 6f 6d 22 2c 20 53 54 52 49 4e 47 5f 53 n.com", STRING_S
1280: 48 4f 52 54 29 3b 0a 09 7d 20 65 6c 73 65 20 7b HORT);..} else {
1290: 0a 09 09 6f 70 74 69 6f 6e 73 2d 3e 67 70 67 5f ...options->gpg_
12a0: 69 64 5b 20 73 74 72 6c 65 6e 28 6f 70 74 69 6f id[ strlen(optio
12b0: 6e 73 2d 3e 67 70 67 5f 69 64 29 20 2d 20 31 5d ns->gpg_id) - 1]
12c0: 20 3d 20 30 3b 0a 09 7d 0a 09 0a 09 70 72 69 6e = 0;..}....prin
12d0: 74 66 28 22 50 61 74 68 20 74 6f 20 47 6e 75 50 tf("Path to GnuP
12e0: 47 20 5b 2f 75 73 72 2f 62 69 6e 2f 67 70 67 5d G [/usr/bin/gpg]
12f0: 3a 20 22 29 3b 0a 09 66 67 65 74 73 28 6f 70 74 : ");..fgets(opt
1300: 69 6f 6e 73 2d 3e 67 70 67 5f 70 61 74 68 2c 20 ions->gpg_path,
1310: 53 54 52 49 4e 47 5f 4c 4f 4e 47 2c 20 73 74 64 STRING_LONG, std
1320: 69 6e 29 3b 0a 09 69 66 28 20 73 74 72 63 6d 70 in);..if( strcmp
1330: 28 6f 70 74 69 6f 6e 73 2d 3e 67 70 67 5f 70 61 (options->gpg_pa
1340: 74 68 2c 20 22 5c 6e 22 29 20 3d 3d 20 30 29 7b th, "\n") == 0){
1350: 0a 09 09 73 74 72 6e 63 70 79 28 6f 70 74 69 6f ...strncpy(optio
1360: 6e 73 2d 3e 67 70 67 5f 70 61 74 68 2c 20 22 2f ns->gpg_path, "/
1370: 75 73 72 2f 62 69 6e 2f 67 70 67 22 2c 20 53 54 usr/bin/gpg", ST
1380: 52 49 4e 47 5f 4c 4f 4e 47 29 3b 0a 09 7d 20 65 RING_LONG);..} e
1390: 6c 73 65 20 7b 0a 09 09 6f 70 74 69 6f 6e 73 2d lse {...options-
13a0: 3e 67 70 67 5f 70 61 74 68 5b 20 73 74 72 6c 65 >gpg_path[ strle
13b0: 6e 28 6f 70 74 69 6f 6e 73 2d 3e 67 70 67 5f 70 n(options->gpg_p
13c0: 61 74 68 29 20 2d 20 31 5d 20 3d 20 30 3b 0a 09 ath) - 1] = 0;..
13d0: 7d 0a 09 0a 09 73 6e 70 72 69 6e 74 66 28 70 77 }....snprintf(pw
13e0: 5f 66 69 6c 65 2c 20 53 54 52 49 4e 47 5f 4c 4f _file, STRING_LO
13f0: 4e 47 2c 20 22 25 73 2f 2e 70 77 6d 61 6e 2e 64 NG, "%s/.pwman.d
1400: 62 22 2c 20 67 65 74 65 6e 76 28 22 48 4f 4d 45 b", getenv("HOME
1410: 22 29 20 29 3b 0a 09 70 72 69 6e 74 66 28 22 50 ") );..printf("P
1420: 61 73 73 77 6f 72 64 20 44 61 74 61 62 61 73 65 assword Database
1430: 20 46 69 6c 65 20 5b 25 73 5d 3a 20 22 2c 20 70 File [%s]: ", p
1440: 77 5f 66 69 6c 65 20 29 3b 0a 09 66 67 65 74 73 w_file );..fgets
1450: 28 6f 70 74 69 6f 6e 73 2d 3e 70 61 73 73 77 6f (options->passwo
1460: 72 64 5f 66 69 6c 65 2c 20 53 54 52 49 4e 47 5f rd_file, STRING_
1470: 4c 4f 4e 47 2c 20 73 74 64 69 6e 29 3b 0a 09 69 LONG, stdin);..i
1480: 66 28 20 73 74 72 63 6d 70 28 6f 70 74 69 6f 6e f( strcmp(option
1490: 73 2d 3e 70 61 73 73 77 6f 72 64 5f 66 69 6c 65 s->password_file
14a0: 2c 20 22 5c 6e 22 29 20 3d 3d 20 30 29 7b 0a 09 , "\n") == 0){..
14b0: 09 73 74 72 6e 63 70 79 28 6f 70 74 69 6f 6e 73 .strncpy(options
14c0: 2d 3e 70 61 73 73 77 6f 72 64 5f 66 69 6c 65 2c ->password_file,
14d0: 20 70 77 5f 66 69 6c 65 2c 20 53 54 52 49 4e 47 pw_file, STRING
14e0: 5f 4c 4f 4e 47 29 3b 0a 09 7d 20 65 6c 73 65 20 _LONG);..} else
14f0: 7b 0a 09 09 6f 70 74 69 6f 6e 73 2d 3e 70 61 73 {...options->pas
1500: 73 77 6f 72 64 5f 66 69 6c 65 5b 20 73 74 72 6c sword_file[ strl
1510: 65 6e 28 6f 70 74 69 6f 6e 73 2d 3e 70 61 73 73 en(options->pass
1520: 77 6f 72 64 5f 66 69 6c 65 29 20 2d 20 31 5d 20 word_file) - 1]
1530: 3d 20 30 3b 0a 09 7d 0a 09 0a 09 70 72 69 6e 74 = 0;..}....print
1540: 66 28 22 50 61 73 73 70 68 72 61 73 65 20 54 69 f("Passphrase Ti
1550: 6d 65 6f 75 74 28 69 6e 20 6d 69 6e 75 74 65 73 meout(in minutes
1560: 29 20 5b 31 38 30 5d 3a 20 22 29 3b 0a 09 66 67 ) [180]: ");..fg
1570: 65 74 73 28 74 65 78 74 2c 20 53 54 52 49 4e 47 ets(text, STRING
1580: 5f 53 48 4f 52 54 2c 20 73 74 64 69 6e 29 3b 0a _SHORT, stdin);.
1590: 09 69 66 28 20 73 74 72 63 6d 70 28 74 65 78 74 .if( strcmp(text
15a0: 2c 20 22 5c 6e 22 29 20 3d 3d 20 30 29 7b 0a 09 , "\n") == 0){..
15b0: 09 6f 70 74 69 6f 6e 73 2d 3e 70 61 73 73 70 68 .options->passph
15c0: 72 61 73 65 5f 74 69 6d 65 6f 75 74 20 3d 20 31 rase_timeout = 1
15d0: 38 30 3b 0a 09 7d 20 65 6c 73 65 20 7b 0a 09 09 80;..} else {...
15e0: 6f 70 74 69 6f 6e 73 2d 3e 70 61 73 73 70 68 72 options->passphr
15f0: 61 73 65 5f 74 69 6d 65 6f 75 74 20 3d 20 61 74 ase_timeout = at
1600: 6f 69 28 74 65 78 74 29 3b 0a 09 7d 0a 0a 09 77 oi(text);..}...w
1610: 72 69 74 65 5f 6f 70 74 69 6f 6e 73 20 3d 20 54 rite_options = T
1620: 52 55 45 3b 0a 09 6f 70 74 69 6f 6e 73 5f 77 72 RUE;..options_wr
1630: 69 74 65 28 29 3b 0a 7d 0a 0a ite();.}..