]>
git.sthu.org Git - pgp-tools.git/blob - keyanalyze/process_keys.c
2 * Does preprocessing of keyrings for an intermediate file to be monged
5 * Copyright (c)2001 Thomas Roessler <roessler@does-not-exist.org>
7 * This program can be freely distributed under the GNU General Public
18 static int DontRequireSelfSig
= 0;
42 static void free_sig (struct sig
**sigpp
)
46 if (!sigpp
|| !*sigpp
)
49 for (sigp
= *sigpp
; sigp
; sigp
= q
)
58 static void free_uid (struct uid
**uidpp
)
62 if (!uidpp
|| !*uidpp
)
65 for (uidp
= *uidpp
; uidp
; uidp
= q
)
74 static void free_key (struct key
**keypp
)
78 if (!keypp
|| !(keyp
= *keypp
))
81 free_uid (&keyp
->uids
);
87 #define new_sig() calloc (sizeof (struct sig), 1)
88 #define new_uid() calloc (sizeof (struct uid), 1)
89 #define new_key() calloc (sizeof (struct key), 1)
91 /* Is a signature with this ID present? */
93 static int check_sig_id (struct sig
*signatures
, char *id
)
97 for (s
= signatures
; s
; s
= s
->next
)
98 if (!strcmp (s
->id
, id
))
104 /* Is this user ID self-signed? */
106 static int check_selfsig (struct uid
*uid
, struct key
*key
)
108 return (uid
->self
= check_sig_id (uid
->sigs
, key
->id
));
111 /* Append a list of signatures to a different list of signatures */
113 static void join_siglists (struct sig
**sig_d
, struct sig
**sig_s
)
116 sig_d
= &((*sig_d
)->next
);
122 /* Clean up a list of signatures - inefficient! */
124 static void cleanup_siglist (struct sig
**sig
, char *keyid
)
126 struct sig
**last
= sig
;
129 for (p
= *sig
; p
; p
= q
)
132 if (!strcmp (keyid
, p
->id
) || check_sig_id (p
->next
, p
->id
))
143 /* print the information gathered */
145 static void do_key (struct key
*k
)
147 struct sig
*interesting_signatures
= NULL
, *sigp
;
153 for (uidp
= k
->uids
; uidp
; uidp
= uidp
->next
)
154 if (DontRequireSelfSig
|| check_selfsig (uidp
, k
))
155 join_siglists (&interesting_signatures
, &uidp
->sigs
);
157 cleanup_siglist (&interesting_signatures
, k
->id
);
158 if (interesting_signatures
)
160 printf ("p%s\n", k
->id
);
161 for (sigp
= interesting_signatures
; sigp
; sigp
= sigp
->next
)
162 printf ("s%s\n", sigp
->id
);
165 free_sig (&interesting_signatures
);
169 /* the main routine */
171 int main (int argc
, char *argv
[])
176 struct sig
**lastsig
= NULL
;
177 struct uid
**lastuid
= NULL
;
178 struct key
*k
= new_key();
182 if (argc
== 2 && !strcmp (argv
[1], "-S"))
183 DontRequireSelfSig
= 1;
185 while (fgets (buff
, sizeof (buff
), stdin
))
187 if ((s
= strtok (buff
, ":")))
189 if (!strcmp (s
, "pub"))
195 lastuid
= &k
->uids
->next
;
196 lastsig
= &k
->uids
->sigs
;
202 sprintf (k
->id
, "%s", strtok (NULL
, ":"));
204 else if (!strcmp (s
, "rev"))
206 else if (!strcmp (s
, "uid"))
208 struct uid
*uid
= *lastuid
= new_uid();
209 lastuid
= &(*lastuid
)->next
;
210 lastsig
= &uid
->sigs
;
212 else if (!strcmp (s
, "sig"))
214 struct sig
*sig
= *lastsig
= new_sig();
215 lastsig
= &sig
->next
;
216 sprintf (sig
->id
, "%s", strtok (NULL
, ":"));