~ubuntu-branches/debian/sid/rlinetd/sid

« back to all changes in this revision

Viewing changes to src/data.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Luberda
  • Date: 2010-03-20 18:03:45 UTC
  • mfrom: (2.3.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100320180345-x1srfbe2tg00ezsf
Tags: 0.7-1
* New upstream version.
* Recommend rsyslog instead of sysklogd (closes: #526922).
* update-inetd:
  + add support for enabling, disabling and removing entries;
  + use ucf for managing generated files;
  + ignore ucf files in rlinetd.conf;
  + make appropriate changes in  postinst and postrm scripts.
* Set debhelper compat level to 7
* Standards-Version: 3.8.4 (no changes). 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdlib.h>
 
2
#include <string.h>
 
3
#include <sysexits.h>
 
4
 
 
5
#include <pwd.h>
 
6
 
 
7
#include <port/port.h>
 
8
 
 
9
#include "data.h"
 
10
#include "db.h"
 
11
#include "error.h"
 
12
 
 
13
void numlist_add(struct numlist **list, long num) {
 
14
        struct numlist *tmp = (struct numlist *)malloc(sizeof(*tmp));
 
15
 
 
16
        if(!tmp)
 
17
                rl_fatal(EX_SOFTWARE, _("ABORT - Can't allocate memory"));
 
18
        tmp->next = *list;
 
19
        tmp->num = num;
 
20
        *list = tmp;
 
21
}
 
22
 
 
23
void numlist_copy(struct numlist **to, struct numlist *from) {
 
24
        while(from) {
 
25
                numlist_add(to, from->num);
 
26
                from = from->next;
 
27
        }
 
28
}
 
29
 
 
30
void numlist_free(struct numlist *n) {
 
31
        struct numlist *p;
 
32
        
 
33
        while(n) {
 
34
                p = n->next;
 
35
                free(n);
 
36
                n = p;
 
37
        }
 
38
}
 
39
 
 
40
void stringlist_add(struct stringlist **list, char *str) {
 
41
        struct stringlist *tmp = (struct stringlist *)malloc(sizeof(*tmp));
 
42
 
 
43
        if(!tmp)
 
44
                rl_fatal(EX_SOFTWARE, _("ABORT - Can't allocate memory"));
 
45
        tmp->next = *list;
 
46
        tmp->str = str;
 
47
        *list = tmp;
 
48
}
 
49
 
 
50
void stringlist_copy(struct stringlist **to, struct stringlist *from) {
 
51
        while(from) {
 
52
                stringlist_add(to, strdup(from->str));
 
53
                from = from->next;
 
54
        }
 
55
}
 
56
 
 
57
void stringlist_free(struct stringlist *n) {
 
58
        struct stringlist *p;
 
59
 
 
60
        while(n) {
 
61
                p = n->next;
 
62
                if(n->str)
 
63
                        free(n->str);
 
64
                free(n);
 
65
                n = p;
 
66
        }
 
67
}
 
68
 
 
69
void builduserdata(struct userdata **dest, char *name) {
 
70
        struct passwd pw;
 
71
        struct passwd *pp;
 
72
 
 
73
        pp = &pw;
 
74
        pp = getpwnam(name);
 
75
        endpwent();
 
76
        if(!pp)
 
77
                return;
 
78
        clearuserdata(dest);
 
79
        (*dest)->name = name;
 
80
        (*dest)->uid = pp->pw_uid;
 
81
        (*dest)->gid = pp->pw_gid;
 
82
}       
 
83
 
 
84
void clearuserdata(struct userdata **dest) {
 
85
        if(!*dest)
 
86
                return;
 
87
        if((*dest)->name)
 
88
                free((*dest)->name);
 
89
        memset(*dest, 0, sizeof(**dest));
 
90
        (*dest)->uid = -1;
 
91
        (*dest)->gid = -1;
 
92
}
 
93
 
 
94
void newuserdata(struct userdata **dest) {
 
95
        if(!*dest)
 
96
                *dest = (struct userdata *)malloc(sizeof(**dest));
 
97
        if(!*dest)
 
98
                rl_fatal(EX_SOFTWARE, _("ABORT - Can't allocate memory"));
 
99
        memset(*dest, 0, sizeof(**dest));
 
100
        (*dest)->uid = -1;
 
101
        (*dest)->gid = -1;
 
102
}
 
103
 
 
104
void userdata_copy(struct userdata **to, struct userdata *from) {
 
105
        if(!from)
 
106
                return;
 
107
        newuserdata(to);
 
108
        memcpy(*to, from, sizeof(**to));
 
109
        (*to)->name = from->name ? strdup(from->name) : NULL;
 
110
}
 
111
 
 
112
 
 
113
/* vim: set ts=2: */